使用WMI或其他东西在网络(域)计算机上启动.exe可能吗? [英] Start an .exe on a network (domain) computer using WMI or somthing else maybe?

查看:121
本文介绍了使用WMI或其他东西在网络(域)计算机上启动.exe可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Visual Studio 2017中编写一个应用程序(Windows VB.net表单),它从Active Directory收集域中存在的所有计算机,然后检查每台计算机(如果已打开)是否存在防病毒软件(检查特定文件)。如果未安装防病毒软件,则会将安装程序复制到PC本地根驱动器上的文件夹中。最后一部分是让远程计算机以后台进程启动安装程序(.exe从cmd运行时有-q标志选项)。我遇到了真正的问题。应用程序在服务器上运行的帐户是域管理员帐户。我知道也许PowerShell更适合这个,但是因为这个应用程序将在70多个站点中使用,并且每个站点都不一定以与之前相同的方式设置我不希望我们的IT人员必须调整脚本等等



我想也许WMI可能是一个更好的方法,任何建议都很受欢迎...



我尝试过:



Private Sub Button2_Click(发送者为对象,e为EventArgs)处理InstallButton.Click



Dim PCsource As String =C:\ Path\Install.txt'来自AD的PC列表

Dim Check As String'读取的行PCource

Dim安装为System.IO.StreamWriter'日志文件

Dim UName As String =someuser'尝试在此处添加凭据

Dim UPass As New SecureString()'但它没有帮助



UPass.AppendChar(S)

UPass.App endChar(o)

UPass.AppendChar(m)

UPass.AppendChar(e)

UPass.AppendChar( p)

UPass.AppendChar(a)

UPass.AppendChar(s)

UPass.AppendChar(s )

UPass.AppendChar(!)



如果System.IO.File.Exists(PCource)= True则

Dim Computer As New System.IO.StreamReader(PCsource)

Do While Computer.Peek()<> -1

Check = Computer.ReadLine()

尝试

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 =域

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安装程序已启动& ; 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()

结束尝试

循环

结束如果



MessageBox.Show(FINISHED !!!)< br $>




结束Sub

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

推荐答案

\ Path\AntiVirus.exe -q)

InstProcess.UseShellExecute = False

InstProcess.RedirectStandardError = True

InstProcess.RedirectStandardInput = True

InstProcess.RedirectStandardOutput = True

InstProcess.WorkingDirectory =C:\ Path

InstProcess.Domain =域

InstProcess.UserName = UName

InstProcess.Password = UPass

InstStart =系统。 Diagnostics.Process.Start(InstProcess)

Installed = My.Computer.FileSystem.OpenTextFileWriter(C:\Path\Installed.txt,True)

已安装.WriteLine(AntiVirus安装程序启动和& 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()

结束尝试

循环

结束如果



MessageBox.Show(FINISHED !!!)< br $>




End Sub
\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


是的,该代码没有在远程计算机上启动进程。它正在运行此代码的任何机器上启动该过程。 Process类IIRC不会在远程计算机上启动进程。



WMI更适合这种情况,您可以启动非交互式远程进程。 b / b


更好的做法是废弃它并使用专为在工作站上安装软件而设计和构建的商业软件,如MS的System Center Configuration Manager。
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.


这篇关于使用WMI或其他东西在网络(域)计算机上启动.exe可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆