Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
436 views
in Technique[技术] by (71.8m points)

powershell - Access-Denied error upon using start-process

I first want to apologize for reposting a question. I attempted to start a bounty but am having this problem and there doesn't seem to be a fix for it.

Anyways

I am getting the following error when trying to execute a line of code

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

This is the code being executed

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

$powershellArguments = "D:pathps.script.ps1", "arg1", "arg2", "arg3", "arg4"
Start-Process "powershell.exe" -credential $cred -ArgumentList $powershellArguments -wait
  • This code works fine when executed locally, but not when called via vbs WMI
  • Both computers exist in the same domain and address range
  • The username and password supplied have admin privileges on both machines
  • I have tried both with and without -wait however neither works, and due to the user being privileged, I'd prefer to keep it

I am not proficient at VBS however I went through the script and pulled out what I believe to be all the lines that are used for executing a command on a remote computer. This script does work for thousands of other tasks without error.

m_strCommand =  MIGetTaskParam("RemoteProgName") & " " & MIGetTaskParam("Provider") & " " & FileTS
strScriptFolder = "C:productionlogsRemoteExec"
strComputer=MIGetTaskParam("RemoteServer")
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objRemote = objSWbemLocator.ConnectServer(strComputer, "moredata", 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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

For remote WMI in VBS, try setting ImpersonationLevel and AuthenticationLevel values:

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

Assuming your want to remotely execute a process, you could do something like the following where you're passing a computer IP to a WMIC command as opposed to using WMI in VBS:

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

Simply change the command you execute to whatever you want.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...