i'm working on some sort of inventory program. It's very simple but i'm having some problems. It actually has 3 parts.
1.service that will be installed on all workstations that is set to run every few hours. This service starts an exe stored on the workstation.
2.This exe checks if there are updates for a third program. If there is an update he should copy the correct version to a location on the workstation and start it.
3.actual program that gathers general information about the workstation and stores it in a DB.
If i run the programs seperately everything works. If I run 2 then he copies the file and starts 3 without problem. But when I try the complete flow it fails. My feeling is that 2 cannot connect to the remote directory because its running in the background.
If I change my service so that he runs 3 instead of 2 then the inventory happens.
I hope this stil makes sense to you. Below you can find the code for step 2. The step that should check for an update and start the inventoryprogram. If someone could set me in the right direction that would be great. Have been googling for hours. The part Open_Remote_Connection is one I found online but it doesn't solve my problem. When i debug it it's states that the directory doesn't exists but it does.
1.service that will be installed on all workstations that is set to run every few hours. This service starts an exe stored on the workstation.
2.This exe checks if there are updates for a third program. If there is an update he should copy the correct version to a location on the workstation and start it.
3.actual program that gathers general information about the workstation and stores it in a DB.
If i run the programs seperately everything works. If I run 2 then he copies the file and starts 3 without problem. But when I try the complete flow it fails. My feeling is that 2 cannot connect to the remote directory because its running in the background.
If I change my service so that he runs 3 instead of 2 then the inventory happens.
I hope this stil makes sense to you. Below you can find the code for step 2. The step that should check for an update and start the inventoryprogram. If someone could set me in the right direction that would be great. Have been googling for hours. The part Open_Remote_Connection is one I found online but it doesn't solve my problem. When i debug it it's states that the directory doesn't exists but it does.
VB.NET:
Imports System.IO
Module Module1
Sub Main()
'deze applicatie zorgt voor het update van de OBDInventory /hij moet controleren of de versie van het bestand op het netwerk nieuwer is dan degene die in gebruik is
'indien ja dan moet hij de nieuwste versie kopieren, indien nee dan start ODBInventory/ eerst HELPDESK pingen om te kijken of hij bereikbaar is
System.Threading.Thread.Sleep(10000)
Open_Remote_Connection("HEPDESK", "username", "password")
If CheckFile("c:\temp\InventoryTool\ODBInventory.exe") = True Then
If GetFileVersionInfo("c:\temp\InventoryTool\ODBInventory.exe") < GetFileVersionInfo("\\HELPDESK\C$\temp\InventoryTool\Release\ODBInventory.exe") Then
NieuweVersieKopieren()
System.Diagnostics.Process.Start("C:\temp\InventoryTool\ODBInventory.exe")
Else
System.Diagnostics.Process.Start("C:\temp\InventoryTool\ODBInventory.exe")
End If
Else
NieuweVersieKopieren()
System.Diagnostics.Process.Start("C:\temp\InventoryTool\ODBInventory.exe")
End If
End Sub
Private Function GetFileVersionInfo(ByVal filename As String) As Version
Return Version.Parse(FileVersionInfo.GetVersionInfo(filename).FileVersion)
End Function
Private Sub NieuweVersieKopieren()
Dim sourcepath As String = "\\HELPDESK\C$\temp\InventoryTool\Release"
Dim DestPath As String = "C:\temp\InventoryTool\"
If Not Directory.Exists(DestPath) Then
Directory.CreateDirectory(DestPath)
End If
Dim file = New FileInfo("\\HELPDESK\C$\temp\InventoryTool\Release\ODBInventory.exe")
file.CopyTo(Path.Combine(DestPath, file.Name), True)
End Sub
Private Sub Open_Remote_Connection(ByVal strComputer As String, ByVal strUsername As String, ByVal strPassword As String)
'//====================================================================================
'//using NET USE to open a connection to the remote computer
'//with the specified credentials. if we dont do this first, File.Copy will fail
'//====================================================================================
Dim ProcessStartInfo As New System.Diagnostics.ProcessStartInfo
ProcessStartInfo.FileName = "net"
ProcessStartInfo.Arguments = "use \\" & strComputer & "\c$ /USER:" & strUsername & " " & strPassword
ProcessStartInfo.WindowStyle = ProcessWindowStyle.Hidden
System.Diagnostics.Process.Start(ProcessStartInfo)
'//============================================================================
'//wait 2 seconds to let the above command complete or the copy will still fail
'//============================================================================
System.Threading.Thread.Sleep(2000)
End Sub
Public Function CheckFile(ByVal strFileName As String) As Boolean
Dim objFSO As New System.IO.FileInfo(strFileName)
Try
If objFSO.Exists Then
CheckFile = True
Else
CheckFile = False
End If
Catch
CheckFile = False
End Try
objFSO = Nothing
Return CheckFile
End Function
End Module