2

批处理更改了 vbs 代码,使其无法被 vbs 使用。我该如何解决?

批号:

echo Const HIGH = 128 >> prio.vbs
echo strComputer = "." >> prio.vbs
echo Set objWMIService = GetObject("winmgmts:" _ >> prio.vbs
echo    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") >> prio.vbs
echo Set colProcesses = objWMIService.ExecQuery _ >> prio.vbs
echo    ("Select * from Win32_Process Where Name = 'file.exe'") >> prio.vbs
echo For Each objProcess in colProcesses >> prio.vbs
echo    objProcess.SetPriority(HIGH)  >> prio.vbs
echo Next >> prio.vbs

VBS 原版:

Const HIGH = 128
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery _
    ("Select * from Win32_Process Where Name = 'file.exe'")
For Each objProcess in colProcesses
    objProcess.SetPriority(HIGH) 
Next

VBS 之后:

Const HIGH = 128 
strComputer = "." 
Set objWMIService = GetObject("winmgmts:" _ 
Set colProcesses = objWMIService.ExecQuery _ 
   ("Select * from Win32_Process Where Name = 'file.exe'") 
For Each objProcess in colProcesses 
   objProcess.SetPriority(HIGH)  
Next

请帮忙

4

2 回答 2

3

&字符在 (command-chaining) 中具有特殊含义CMD,因此您必须对它们进行转义以获得文字 & 符号:

echo    ^& "{impersonationLevel=impersonate}!\\" ^& strComputer ^& "\root\cimv2") >> prio.vbs

右括号 ')' 和 '<', '>' 也是如此

于 2013-02-17T23:09:44.423 回答
0

如果您可以使用 bat 混合格式保存 vbs 代码,您不需要创建另一个文件,也不需要任何转义:

<!-- :
@echo off && mode 050,03 && title <nul && title .\%~nx0 
for /f ^tokens^=* %%i in ('%__APPDIR__%wScript.exe "%~dpnx0?.wsf" ^& cls')do exit /b 2>nul >nul
--> <job> <script language = "vbscript">Const HIGH = 128 : strComputer = ".": Set objWMIService = GetObject("winmgmts:" &_
"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2"): Set colProcesses = objWMIService.ExecQuery ("Select *"&_
"from Win32_Process Where Name = 'file.exe'"): For Each objProcess in colProcesses: objProcess.SetPriority(HIGH): Next </script></job>

所以,不需要任何转义,只需在命令行中执行或单击即可!

关于布局:


<!-- :
@echo off && mode 050,03 && title <nul && title .\%~nx0 
for /f ^tokens^=* %%i in ('%__APPDIR__%wScript.exe "%~dpnx0?.wsf" ^& cls')do exit /b 2>nul >nul
--> <job> <script language = "vbscript">

:: your vbs code here ::

</script></job>
于 2019-12-28T21:19:37.317 回答