Batch file 如何将批处理文件的变量转换成VB脚本文件
我已经创建了批处理文件,其中包括批处理文件的代码以及VBScript的代码。现在我尝试将变量值从批处理文件传递到VBScript,但它不起作用Batch file 如何将批处理文件的变量转换成VB脚本文件,batch-file,vbscript,Batch File,Vbscript,我已经创建了批处理文件,其中包括批处理文件的代码以及VBScript的代码。现在我尝试将变量值从批处理文件传递到VBScript,但它不起作用 echo This is batch set /p Name="Enter Your Name: " :x=msgbox("You have Entered '" & name & "'" ,0, "Your Title Here") findstr "^:" "%~sf0">temp.vbs & cscript //nol
echo This is batch
set /p Name="Enter Your Name: "
:x=msgbox("You have Entered '" & name & "'" ,0, "Your Title Here")
findstr "^:" "%~sf0">temp.vbs & cscript //nologo temp.vbs & del temp.vbs
echo This is batch again
我得到以下输出:
c:\Users\vshah\Desktop>echo This is batch
This is batch
c:\Users\vshah\Desktop>set /p Name="Enter Your Name: "
Enter Your Name: Vinkesh
c:\Users\vshah\Desktop>findstr "^:" "c:\Users\vshah\Desktop\Print.bat" 1>temp.vbs & cscript //nologo temp.vbs & del temp.vbs
c:\Users\vshah\Desktop>echo This is batch again
This is batch again
c:\Users\vshah\Desktop>
In Message Box I am getting message only -- You have Entered "
Not getting variable output
请帮助我将变量从批处理代码传递到VBScript代码并使用它们
非常感谢您……这将生成正确的msgbox:
@echo off
setlocal enabledelayedexpansion
echo This is batch
set /p Name="Enter Your Name: "
:x=msgbox("You have Entered '__name__'" ,0, "Your Title Here")
findstr "^:" "%~sf0"> %TEMP%\str
set /p vbl=<%TEMP%\str
del %TEMP%\str >NUL
set vbl=%vbl:__name__=!name!%
rem remove the first colon
echo %vbl:~1% 1>temp.vbs & cscript //nologo temp.vbs & del temp.vbs
@echo关闭
延迟扩展
这是一批
set/p Name=“输入您的姓名:”
:x=msgbox(“您已在此处输入了“\uuuuu name\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
findstr“^:“%sf0”>%TEMP%\str
设置/p vbl=NUL
设置vbl=%vbl:\名称\名称=!姓名!%
rem移除第一个结肠
回显%vbl:~1%1>temp.vbs&cscript//nologo temp.vbs&del temp.vbs
我使用了一个模板(\uuuu name\uuuu
)以及enabledelayedexpansion
来用变量中的变量替换值。
我还必须创建另一个临时文件,然后将其删除。只需更改以下内容:
:x=msgbox("You have Entered '" & name & "'" ,0, "Your Title Here")
findstr "^:" "%~sf0">temp.vbs & cscript //nologo temp.vbs & del temp.vbs
为此:
echo x=msgbox("You have Entered '%name%'" ,0, "Your Title Here")>temp.vbs
cscript //nologo temp.vbs & del temp.vbs
请注意,您并不是以这种方式真正传递变量,而是创建一个包含该变量的文本值的临时脚本。如果希望VBScript实际使用变量,则需要将代码更改为以下内容:
echo name=WScript.Arguments.Unnamed(0)>temp.vbs
echo x=msgbox("You have Entered '" ^& name ^& "'" ,0, "Your Title Here")>>temp.vbs
cscript //nologo temp.vbs "%name%"
del temp.vbs