本文介绍了如何在不丢失这些行的情况下批量创建vbs文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每次尝试批量创建vbs文件时,vbs文件中都缺少某些行
Everytime I tries to create a vbs file by batch , some lines are missing in the vbs file
@echo off echo Function RunAsAdmin() >> 2.vbs echo If WScript.Arguments.length = 0 Then >> 2.vbs echo CreateObject("Shell.Application").ShellExecute "wscript.exe", """" & _ >> 2.vbs echo WScript.ScriptFullName & """" & "RunAsAdministrator""",,"runas", 1 >> 2.vbs echo WScript.Quit >> 2.vbs echo End If >> test.vbs批量制作vbs文件时,我需要保留这两行吗?
What do i need to keep these 2 lines when making a vbs file by batch?
echo CreateObject("Shell.Application").ShellExecute "wscript.exe", """" & _ >> 2.vbs echo WScript.ScriptFullName & """" & "RunAsAdministrator""",,"runas", 1 >> 2.vbs`推荐答案
这里是一种避免逃逸的替代方法:
Here is an alternative method that avoids the necessity of escaping:
@echo off setlocal EnableExtensions DisableDelayedExpansion rem // Define constants here: set "_VBS_FILE=%~dp02.vbs" rem // Write to given output file: > "%_VBS_FILE%" ( rem // Read all lines from this batch script that begin with `::::`: for /F "delims=" %%V in ('findstr "^::::" "%~f0"') do ( rem // Store current line string: set "VBS_LINE=%%V" rem // Toggle delayed expansion to avoid loss of `!`: setlocal EnableDelayedExpansion rem // Return current line string with preceding `::::` removed: echo(!VBS_LINE:*::::=! endlocal ) ) endlocal exit /B ::This is the embedded VBS code section with each line preceded by `::::`: ::::Function RunAsAdmin() ::::If WScript.Arguments.length = 0 Then :::: CreateObject("Shell.Application").ShellExecute "wscript.exe", """" & _ :::: WScript.ScriptFullName & """" & "RunAsAdministrator""", , "runas", 1 :::: WScript.Quit ::::End If更多推荐
如何在不丢失这些行的情况下批量创建vbs文件?
发布评论