如何在没有命令提示符窗口的情况下创建文件

时间:2021-09-26 09:47:37

I'm using WinRAR SFX module to create an installation, and use its presetup option to run some preliminary tests.

我正在使用WinRAR SFX模块来创建安装,并使用其预置选项来运行一些初步测试。

Since wscript can only accept vbs file, and not the script itself, I first run "cmd /c echo {...script code...} > setup.vbs", and then I run "wscript setup.vbs". The run of the first cmd command opens a brief command window, and I would really like to avoid this. I thought of using RunDll32 to write this data, but couldn't find any suitable API to use.

由于wscript只能接受vbs文件,而不是脚本本身,我首先运行“cmd / c echo {... script code ...}> setup.vbs”,然后运行“wscript setup.vbs”。第一个cmd命令的运行打开一个简短的命令窗口,我真的想避免这种情况。我想过使用RunDll32来编写这些数据,却找不到任何合适的API来使用。

Can anyone think of a way to bypass it and create a small file with a small VBScript text without opening a Command Prompt window?

任何人都可以想到绕过它并使用小VBScript文本创建一个小文件而无需打开命令提示符窗口的方法吗?

Thanks a lot,

非常感谢,

splintor

2 个解决方案

#1


2  

Is the script code already in a file? If so,

脚本代码是否已存在于文件中?如果是这样,

You can use the TYPE command to send the script to a file:

您可以使用TYPE命令将脚本发送到文件:

TYPE [script_file] > setup.vbs

or COPY the script file:

或者复制脚本文件:

COPY [script_file] setup.vbs

If the script code is in the body of your cmd, you can use the START command to run the cmd without a window (/b flag):

如果脚本代码位于cmd的主体中,则可以使用START命令运行不带窗口的cmd(/ b标志):

START /B cmd /c echo {...script code...} > setup.vbs

#2


1  

Rather than use cmd /c echo {...script code...} > setup.vbs as a presetup step, perhaps you could package a VBscript with your install that does your preliminary tests and creates setup.vbs, and then calls setup.vbs for you. You'd have to put this in the setup portion of the WinRAR script.

而不是使用cmd / c echo {...脚本代码...}> setup.vbs作为预设步骤,也许你可以用你的安装打包VBscript进行初步测试并创建setup.vbs,然后调用setup .vbs给你。你必须把它放在WinRAR脚本的设置部分。

You can call another VBScript from VBScript like this:

您可以像这样从VBScript调用另一个VBScript:

Set WSHShell = CreateObject("WScript.Shell") 
WSHShell.Run "wscript d:\setup.vbs, ,True

See this MSDN link for the syntax of the Run command.

有关“运行”命令的语法,请参阅此MSDN链接。

#1


2  

Is the script code already in a file? If so,

脚本代码是否已存在于文件中?如果是这样,

You can use the TYPE command to send the script to a file:

您可以使用TYPE命令将脚本发送到文件:

TYPE [script_file] > setup.vbs

or COPY the script file:

或者复制脚本文件:

COPY [script_file] setup.vbs

If the script code is in the body of your cmd, you can use the START command to run the cmd without a window (/b flag):

如果脚本代码位于cmd的主体中,则可以使用START命令运行不带窗口的cmd(/ b标志):

START /B cmd /c echo {...script code...} > setup.vbs

#2


1  

Rather than use cmd /c echo {...script code...} > setup.vbs as a presetup step, perhaps you could package a VBscript with your install that does your preliminary tests and creates setup.vbs, and then calls setup.vbs for you. You'd have to put this in the setup portion of the WinRAR script.

而不是使用cmd / c echo {...脚本代码...}> setup.vbs作为预设步骤,也许你可以用你的安装打包VBscript进行初步测试并创建setup.vbs,然后调用setup .vbs给你。你必须把它放在WinRAR脚本的设置部分。

You can call another VBScript from VBScript like this:

您可以像这样从VBScript调用另一个VBScript:

Set WSHShell = CreateObject("WScript.Shell") 
WSHShell.Run "wscript d:\setup.vbs, ,True

See this MSDN link for the syntax of the Run command.

有关“运行”命令的语法,请参阅此MSDN链接。