2016-07-06 43 views
0

我试图用批处理文件来做到这一点,但是在那里有限制的选项。Visual basic以特定用户身份运行powershell .vbs

现在我正在尝试使用visual basic以特定用户身份启动powershell脚本。 这条线工作在CMD:

RUNAS /user:Domain\User "powershell Delete_App_Script.ps1" 

但是我怎么做到这一点的VBS文件?

set objShell = CreateObject("WScript.Shell") 
objShell.Run "RUNAS /user:Domain\User "powershell Delete_App_Script.ps1"" 
Set objShell = Nothing' 

我得到

预计年底声明在第2行

回答

1

你没有正确关闭字符串,当你在一个VBScript字符串中使用文字引号您转义加倍报价"",因为单引号定义了字符串的开始和结束。

Set objShell = CreateObject("WScript.Shell") 
objShell.Run "RUNAS /user:Domain\User ""powershell Delete_App_Script.ps1""" 
Set objShell = Nothing 

命令将运行为;

RUNAS /user:Domain\User "powershell Delete_App_Script.ps1" 
+0

如何设置它看起来Delete_App_Script.ps1是相同的文件夹?因为现在它只适用于全路径 –

+0

@VladimirLaktionov http://stackoverflow.com/q/16138831/692942 – Lankymart