如何在不丢失这些行的情况下批量创建vbs文件?

编程入门 行业动态 更新时间:2024-10-22 17:23:59
本文介绍了如何在不丢失这些行的情况下批量创建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文件?

本文发布于:2023-11-02 14:43:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1552685.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:批量   情况下   文件   如何在   vbs

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!