shellexecute vbs

VBS中ShellExecute怎么使用

小亿
194
2023-09-11 11:34:34
栏目: 编程语言

在VBS(Visual Basic Script)中,可以使用ShellExecute方法打开外部程序或文件。ShellExecute方法的语法如下:

ShellExecute(Path[, Operation[, Parameters[, Directory[, ShowCmd]]]])

参数说明:

下面是一个使用ShellExecute方法打开记事本程序的示例:

Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "notepad.exe"

在上述示例中,使用Shell.Application对象创建了一个Shell对象,然后调用ShellExecute方法打开记事本程序。

你也可以在ShellExecute方法中指定其他参数,如下所示:

Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "C:\Path\to\File.txt", "open", "", "C:\Path\to", 1

在上述示例中,指定了要打开的文件路径为"C:\Path\to\File.txt",操作为"open",没有传递其他参数,工作目录为"C:\Path\to",窗口显示为vbNormalFocus(即正常大小并拥有焦点)。

注意:在使用ShellExecute方法时,需要保证指定的文件或程序存在于指定的路径中,否则可能会出现错误。

0
看了该问题的人还看了