我正在尝试使用VBScript在远程服务器上执行BAT文件。进一步要求:
不允许使用psexec
我需要脚本在其他用户(而不是我自己的工作站的用户)的权限下运行
我已经咨询了这篇文章:https://docs.microsoft.com/en-us/windows/desktop/WmiSdk/connecting-to-wmi-remotely-with-vbscript
我了解了如何创建连接,但是我不知道如何使用相同的连接创建流程。
我相信这个解决方案真的很接近,唯一的问题是我认为它冒充了当前正在运行的计算机的用户:
strCommand = "C:\temp\copyall.bat"
strPath = "C:\temp"
strcomputer="."
process = "winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2"
msgbox process
Set objWMIService = GetObject(process)
Set objProcess = objWMIService.Get("Win32_Process")
errReturn = objProcess.Create(strCommand, strPath, Null, intProcessID)
If errReturn = 0 Then
WScript.Echo "scan success: " & intProcessID
Else
WScript.Echo "scan fail: " & errReturn
End If
Microsoft网站上的此示例显示了如何正确创建连接,但是我不知道该如何使用该连接。
' Full Computer Name
' can be found by right-clicking My Computer,
' then click Properties, then click the Computer Name tab)
' or use the computer's IP address
strComputer = "FullComputerName"
strDomain = "DOMAIN"
Wscript.StdOut.Write "Please enter your user name:"
strUser = Wscript.StdIn.ReadLine
Set objPassword = CreateObject("ScriptPW.Password")
Wscript.StdOut.Write "Please enter your password:"
strPassword = objPassword.GetPassword()
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objSWbemServices = objSWbemLocator.ConnectServer(strComputer, _
"Root\CIMv2", _
strUser, _
strPassword, _
"MS_409", _
"ntlmdomain:" + strDomain)
Set colSwbemObjectSet = objSWbemServices.ExecQuery("Select * From Win32_Process")
For Each objProcess in colSWbemObjectSet
Wscript.Echo "Process Name: " & objProcess.Name
Next
答案可能是盯着我,但我现在看不到它。想法?
答案 0 :(得分:1)
连接到远程服务器后,只需像在本地一样获取Win32_Process
对象并调用Create()
方法即可。
Set objSWbemServices = objSWbemLocator.ConnectServer(...)
Set objProcess = objSWbemServices.Get("Win32_Process")
errReturn = objProcess.Create(strCommand, strPath, Null, intProcessID)
要运行的文件必须在远程服务器上本地存在,此功能才能起作用。
还请注意,这通常需要远程系统上的管理员权限。