I am writing an application (Windows VB.net Form) in Visual Studio 2017 which gathers all the Computers present in a Domain from Active Directory, it then checks each machine (if it is switched on) for the presence of Antivirus software (checks for a specific file). If the Antivirus is not installed the installer is copied to a folder on the PCs local root drive. The final part of the puzzle is to get the remote computer to start the installer as a background process (the .exe has a -q flag option when run from cmd). I am having real problems getting this to work. The account the application is running under on the server is a Domain Admin account. I am aware that maybe PowerShell is better suited to this but as this application will be used in over 70 sites and each one is not necessarily set up the in same way as the previous I don't want our IT guys to have to tweak scripts etc.
I have thought maybe WMI might be a better method any suggestions greatly received...
What I have tried:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles InstallButton.Click
Dim PCsource As String = "C:\Path\Install.txt" 'List of PCs from AD
Dim Check As String 'Line read from PCsource
Dim Installed As System.IO.StreamWriter 'Log File
Dim UName As String = "someuser" 'Tried adding credentials here
Dim UPass As New SecureString() 'But it hasn't helped
UPass.AppendChar("S")
UPass.AppendChar("o")
UPass.AppendChar("m")
UPass.AppendChar("e")
UPass.AppendChar("p")
UPass.AppendChar("a")
UPass.AppendChar("s")
UPass.AppendChar("s")
UPass.AppendChar("!")
If System.IO.File.Exists(PCsource) = True Then
Dim Computer As New System.IO.StreamReader(PCsource)
Do While Computer.Peek() <> -1
Check = Computer.ReadLine()
Try
Dim InstStart As New System.Diagnostics.Process
Dim InstProcess As New System.Diagnostics.ProcessStartInfo("cmd.exe", arguments:="/c " & "\\" & Check & "\C$\Path\AntiVirus.exe -q")
InstProcess.UseShellExecute = False
InstProcess.RedirectStandardError = True
InstProcess.RedirectStandardInput = True
InstProcess.RedirectStandardOutput = True
InstProcess.WorkingDirectory = "C:\Path"
InstProcess.Domain = Domain
InstProcess.UserName = UName
InstProcess.Password = UPass
InstStart = System.Diagnostics.Process.Start(InstProcess)
Installed = My.Computer.FileSystem.OpenTextFileWriter("C:\Path\Installed.txt", True)
Installed.WriteLine("AntiVirus installer started on " & Check, True)
Installed.Close()
Catch Ex As Exception
Installed = My.Computer.FileSystem.OpenTextFileWriter("C:\Path\Installed.txt", True)
Installed.WriteLine(Ex.Message, True)
Installed.Close()
End Try
Loop
End If
MessageBox.Show("FINISHED!!!")
End Sub