批处理会更改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
请帮助
答案 0 :(得分:2)
&
个字符在CMD
(命令链接)中有特殊含义,所以你必须将它们转义才能获得文字&符号:
echo ^& "{impersonationLevel=impersonate}!\\" ^& strComputer ^& "\root\cimv2") >> prio.vbs
答案 1 :(得分: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 come came here ::
</script></job>