Vbscript VBS使用RunAs参数创建桌面快捷方式

Vbscript VBS使用RunAs参数创建桌面快捷方式,vbscript,windows-7-x64,runas,Vbscript,Windows 7 X64,Runas,我的目标是:我尝试使用VBS在当前运行IE的用户下创建桌面快捷方式,使用带有参数的RunAs命令和用用户输入填充变量的变量(InputBox)提示符 操作系统:Win7 x64 工作BAT:(手动填写域\用户名) 非工作VBS: set WshShell = WScript.CreateObject("WScript.Shell") strDesktop = WshShell.SpecialFolders("Desktop") strUser = InputBox ("Please Enter

我的目标是:我尝试使用VBS在当前运行IE的用户下创建桌面快捷方式,使用带有参数的RunAs命令和用用户输入填充变量的变量(InputBox)提示符

操作系统:Win7 x64

工作BAT:(手动填写域\用户名)

非工作VBS:

set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
strUser = InputBox ("Please Enter your Domain Account")
set oUrlLink = WshShell.CreateShortcut(strDesktop & "\RunAs Internet Explorer (Domain Account).lnk")
oUrlLink.TargetPath = ("%windir%\system32\runas.exe" /u:DOMAIN\"" & strUser & "%ProgramFiles%\Internet Explorer\iexplore.exe")
oUrlLink.IconLocation = "%ProgramFiles%\Internet Explorer\iexplore.exe"
oUrlLink.Save

目前,
TargetPath
不是一个有效的字符串,在插入和退出字符串时,它们应该始终以一个双引号开始和结束。此外,字符串中的文字引号必须转义,以避免“破坏”字符串并导致语法错误。要在字符串中转义文字引号,请将其加倍

这里有一些例子应该会有所帮助

Dim TestString
TestString = "Simple string"
'Simple string
TestString = "Concatenated" & " string"
'Concatenated string
TestString = "Another " & TestString & " with a variable"
'Another Concatenated string with a variable
TestString = """Quoted string"""
'"Quoted string"
TestString = "This is a """ & TestString & """ in a variable"
'This is a "Quoted string" in a variable
考虑到这一点,这条线应该是

oUrlLink.TargetPath = "%windir%\system32\runas.exe /u:DOMAIN\" & strUser & " ""%ProgramFiles%\Internet Explorer\iexplore.exe"""
输出为:

%windir%\system32\runas.exe/u:DOMAIN\Username“%ProgramFiles%\Internet Explorer\iexplore.exe”

抱歉,重点放在了错误的问题上,而这是一个问题,主要问题是如何设置
TargetPath
。它应该只包含可执行文件的路径。任何需要用
arguments
属性指定的参数,请尝试一下

set WshShell=WScript.CreateObject(“WScript.Shell”)
strDesktop=WshShell.SpecialFolders(“桌面”)
strUser=InputBox(“请输入您的域帐户”)
设置oUrlLink=WshShell.CreateShortcut(strDesktop&“\RunAs Internet Explorer(域帐户).lnk”)
oUrlLink.TargetPath=“%windir%\system32\runas.exe”
'使用参数传递可执行文件的任何参数。
oUrlLink.Arguments=“/u:DOMAIN\”&strUser&”“%ProgramFiles%\Internet Explorer\iexplore.exe”“”
oUrlLink.IconLocation=“%ProgramFiles%\Internet Explorer\iexplore.exe”
奥林克,救命

目前,
TargetPath
不是一个有效的字符串,在插入和退出字符串时,它们应该始终以一个双引号开始和结束。此外,字符串中的文字引号必须转义,以避免“破坏”字符串并导致语法错误。要在字符串中转义文字引号,请将其加倍

这里有一些例子应该会有所帮助

Dim TestString
TestString = "Simple string"
'Simple string
TestString = "Concatenated" & " string"
'Concatenated string
TestString = "Another " & TestString & " with a variable"
'Another Concatenated string with a variable
TestString = """Quoted string"""
'"Quoted string"
TestString = "This is a """ & TestString & """ in a variable"
'This is a "Quoted string" in a variable
考虑到这一点,这条线应该是

oUrlLink.TargetPath = "%windir%\system32\runas.exe /u:DOMAIN\" & strUser & " ""%ProgramFiles%\Internet Explorer\iexplore.exe"""
输出为:

%windir%\system32\runas.exe/u:DOMAIN\Username“%ProgramFiles%\Internet Explorer\iexplore.exe”

抱歉,重点放在了错误的问题上,而这是一个问题,主要问题是如何设置
TargetPath
。它应该只包含可执行文件的路径。任何需要用
arguments
属性指定的参数,请尝试一下

set WshShell=WScript.CreateObject(“WScript.Shell”)
strDesktop=WshShell.SpecialFolders(“桌面”)
strUser=InputBox(“请输入您的域帐户”)
设置oUrlLink=WshShell.CreateShortcut(strDesktop&“\RunAs Internet Explorer(域帐户).lnk”)
oUrlLink.TargetPath=“%windir%\system32\runas.exe”
'使用参数传递可执行文件的任何参数。
oUrlLink.Arguments=“/u:DOMAIN\”&strUser&”“%ProgramFiles%\Internet Explorer\iexplore.exe”“”
oUrlLink.IconLocation=“%ProgramFiles%\Internet Explorer\iexplore.exe”
奥林克,救命

您需要更正
TargetPath
中的字符串转义,在字符串中使用引号时,将其加倍是规则,如
oUrlLink.TargetPath=“%windir%\system32\runas.exe/u:DOMAIN\”&strUser&“%ProgramFiles%\Internet Explorer\iexplore.exe”
。您需要更正
TargetPath
中的转义字符串,在字符串中使用引号时,将它们加倍是规则,如
oUrlLink.TargetPath=“%windir%\system32\runas.exe/u:DOMAIN\”&strUser&“%ProgramFiles%\Internet Explorer\iexplore.exe”“
。谢谢Lankymart!似乎还是有一个错误。。。错误:--------------------------------------------------------------创建桌面快捷方式(运行方式为Internet Explorer(Doamin帐户)。vbs(5,1)Microsoft VBScript运行时错误:无效的过程调用或参数--------------------------------------------------------------------它正在提示输入框字符串,但执行失败。我还尝试用相同的错误分隔最后一个空格和参数:(分开的字符串….oUrlLink.TargetPath=“%windir%\system32\runas.exe/u:DOMAIN\”&strUser&“&”%ProgramFiles%\internetexplorer\iexplore.exe“@GekkoLlama再次无法工作,因为
%ProgramFiles%
将扩展到
程序文件,这意味着您需要将其括在引号中。)(一个带引号的字符串,参见示例),因此按照答案中的建议,它应该是
oUrlLink.TargetPath=“%windir%\system32\runas.exe/u:DOMAIN\”&strUser&“%ProgramFiles%\Internet Explorer\iexplore.exe”“”
。它在注释中的格式不太好,只需复制我答案中的行即可—“记住这一点,这行应该是”。我确实复制并粘贴了您的“记住这一点,行应该是”回答,这就是错误的来源。我在多台机器上尝试过此操作,但都出现了相同的错误。脚本:set WshShell=WScript.CreateObject(“WScript.Shell”)strDesktop=WshShell.SpecialFolders(“桌面”)strUser=InputBox(“请输入您的域帐户”)设置oUrlLink=WshShell.CreateShortcut(strDesktop&“\RunAs Internet Explorer(strUser.lnk”)oUrlLink.TargetPath=“%windir%\system32\RunAs.exe/u:Domain\”&strUser&”“%ProgramFiles%\Internet Explorer\iexplore.exe”“”oUrlLink.IconLocation=“%ProgramFiles%\Internet Explorer\iexplore.exe”“oUrlLink.save谢谢Lankymart!似乎仍有错误…错误:---------------------------------------------------------------------------------------创建桌面快捷方式(运行方式为Internet Explorer(Doamin帐户)。vbs(5,1)Microsoft VBScript运行时错误:过程调用无效。”