Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Posted
Updated 3-Nov-17 4:16am

1 solution

Yeah, that code is not starting the process on the remote machine. It's starting the process on whatever machine this code is running on. The Process class, IIRC, will not launch a process on a remote machine.

WMI would be better suited to this and you can launch NON-INTERACTIVE remote processes.

Even better would be to scrap this and use a commercial piece of software designed and built for installing software on workstations, like MS's System Center Configuration Manager.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900