2017-10-12 28 views
0

我有一個批處理將與一個小腳本如下。現在我想用RUNAS修改它,這樣我就可以爲用戶提供它,而不需要給他管理員密碼。RUNAS引入時批處理文件不會運行

@ECHO OFF 
PowerShell.exe -NoProfile -Command "& {Start-Process PowerShell.exe -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""%~xyz0.ps1""' -Verb RunAs}" 
PAUSE 

我添加RUNAS用幾個參數,如以下所示,但它遇到一個錯誤:

ECHO OFF 
runas /profile /user:Administrator /savecred "PowerShell.exe -NoProfile -Command "& {Start-Process PowerShell.exe -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""%~xyz0.ps1""' -Verb RunAs}"" 
PAUSE 

ERROR:

PS:而不引入RUNAS,所述批處理文件運行得很好。

任何人都可以幫忙。

回答

0

嵌套報價必須加倍。一些試驗和錯誤可能是必要的,但它應該是這樣的:

runas /profile /user:Administrator /savecred "PowerShell.exe -NoProfile -Command ""& {Start-Process PowerShell.exe -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File """"%~xyz0.ps1""""' -Verb RunAs}""" 

或者,你可以得到runas運行包含了PowerShell命令另一個批處理文件。

+0

試過這個,但不幸的是沒有工作。批處理文件打開,閃爍一秒鐘然後消失。 – Vlan007