使用启动过程时出现访问 - 拒绝错误

时间:2012-08-24 15:06:03

标签: powershell vbscript wmi

我首先要为重新发布question而道歉。我试图开始赏金,但遇到this问题,似乎没有解决方法。

反正

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

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

1 个答案:

答案 0 :(得分: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

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