0

我首先要为重新发布问题道歉。我试图开始赏金,但遇到了这个问题,似乎没有解决办法。

无论如何

尝试执行一行代码时出现以下错误

Start-Process : This command cannot be executed due to the error: 
Access is denied.

这是正在执行的代码

$username = "domain\username"
$passwordPlainText = "password"     
$password = ConvertTo-SecureString "$passwordPlainText" -asplaintext -force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $username,$password

$powershellArguments = "D:\path\ps.script.ps1", "arg1", "arg2", "arg3", "arg4"
Start-Process "powershell.exe" -credential $cred -ArgumentList $powershellArguments -wait
  • 此代码在本地执行时工作正常,但在通过 vbs WMI 调用时不能正常工作
  • 两台计算机存在于相同的域和地址范围内
  • 提供的用户名和密码在两台机器上都具有管理员权限
  • 我已经尝试了有和没有-wait但都没有工作,并且由于用户具有特权,我更愿意保留它

我不精通 VBS,但是我浏览了脚本并提取了我认为用于在远程计算机上执行命令的所有行。该脚本确实适用于数千个其他任务而不会出错。

m_strCommand =  MIGetTaskParam("RemoteProgName") & " " & MIGetTaskParam("Provider") & " " & FileTS
strScriptFolder = "C:\production\logs\RemoteExec"
strComputer=MIGetTaskParam("RemoteServer")
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objRemote = objSWbemLocator.ConnectServer(strComputer, "more\data", strUser, strPassword,"data", "moredata" )
Set objProcess = objRemote.Get("Win32_Process")
intReturnCode = objProcess.Create(m_strCommand, null, null, intProcessID)
Do Until i = 999
   Set colProcesses = objRemote.ExecQuery ("SELECT * FROM Win32_Process " & "WHERE ProcessID=" & intProcessID )
   If colProcesses.Count = 0  Then
    Exit Do
   End If
Loop
4

1 回答 1

1

对于 VBS 中的远程 WMI,请尝试设置 ImpersonationLevel 和 AuthenticationLevel 值:

sComp = "."
Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate,authenticationLevel=pktPrivacy}!\\" & sComp & "\root\cimv2")

假设您想远程执行一个进程,您可以执行以下操作,将计算机 IP 传递给 WMIC 命令,而不是在 VBS 中使用 WMI:

On Error Resume Next
Set oWSH = CreateObject("WScript.Shell")  
For Each sComp In aComputers
  sCmd = "wmic /node:" & sComp & " path Win32_Process call create \"cmd /c tasklist | sort & pause\""  
  iRC = oWSH.Run(sCmd, 1, True)
  If Err.Number <> 0 Then 
    MsgBox "ERROR: (" & CStr(Err.Number) & ") " & Err.Source & vbCrLf & Err.Description, vbOkOnly, "WMI Remote Error"
    Err.Clear 
  End If   
Next

只需将您执行的命令更改为您想要的任何命令。

于 2012-08-31T23:51:48.353 回答