我首先要为重新发布问题道歉。我试图开始赏金,但遇到了这个问题,似乎没有解决办法。
无论如何
尝试执行一行代码时出现以下错误
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