使用启动进程时拒绝访问错误 [英] Access-Denied error upon using start-process

查看:35
本文介绍了使用启动进程时拒绝访问错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我首先要为转发一个问题而道歉.我试图开始赏金,但遇到了这个问题,但没有似乎不能解决它.

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.

无论如何

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

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.

这是正在执行的代码

$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 两种方法,但都不起作用,而且由于用户具有特权,我更愿意保留它
    • 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
    • 我不精通 VBS,但是我浏览了脚本并提取了我认为用于在远程计算机上执行命令的所有行.此脚本可以无误地用于数千个其他任务.

      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:\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
      

      推荐答案

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

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

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

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

      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.

      这篇关于使用启动进程时拒绝访问错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆