use*_*815 4 windows powershell credentials runas
我有一个脚本来启动另一个ps1脚本作为特定用户在目录上执行一个简单的目录,它运行时,当它运行一个单独的cmd窗口时出现与目录内容.
$encpwd = Get-Content C:\path\to\creds.txt
$passwd = ConvertTo-SecureString $encpwd
$cred = new-object System.Management.Automation.PSCredential 'theuser',$passwd
Start-Process c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -Credential $cred -ArgumentList '-noexit','-File', 'C:\path\to\script\test.ps1'
Run Code Online (Sandbox Code Playgroud)
我的目标是以特定用户身份启动应用程序.所以首先我想用notepad.exe进行测试所以我将最后一行更改为:
Start-Process c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -Credential $cred -ArgumentList '-noexit','-File', 'C:\windows\system32\notepad.exe'
Run Code Online (Sandbox Code Playgroud)
我得到的只是一个快速消失的命令窗口,无法判断是否有错误等.我也尝试调用一个调用记事本的ps1脚本并得到相同的结果,即使它本身就调用了新的脚本记事本精细.
有人可以解释我哪里出错了,谢谢
小智 10
如果您想要启动一个应用程序,您是不是只将其用作Start-Process的目标而不是打开另一个PowerShell窗口来执行此操作?
Start-Process 'C:\windows\system32\notepad.exe' -Credential $cred
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
35620 次 |
| 最近记录: |