Launch program from vbscript

2019-09-07 09:46发布

I am trying to launch a program called WebDrive from a vbscript but I cant get the syntax right to launch the program with a number of parameters; currently run from a batch file:

start /wait /D "c:\program files\webdrive" webdrive.exe /s:"syd-ftp.thruinc.net"

My base code is:

Set objShell = CreateObject("cscript.Shell")
objShell.Run start /wait /D c:\program files\webdrive webdrive.exe /s:"syd-ftp.thruinc.net"""
Set objShell = Nothing

I have read a number of posts on this site relating to this topic but I cant seem to get the quotes right, for example:

Set objShell = CreateObject("cscript.Shell")
objShell.Run "start /wait /D ""c:\program files\webdrive"" webdrive.exe /s:"""syd-ftp.thruinc.net"""
Set objShell = Nothing

Any advice would be great.

Regards

Martin

标签: vbscript
2条回答
狗以群分
2楼-- · 2019-09-07 10:19

Here is a generic way to launch using VBScript:

CONNECT:

Set objShell = CreateObject("WdScript.Shell") objShell.Run """C:\Program Files\WebDrive\webdrive.exe"" /s:""site""" Set objShell = Nothing

DISCONNECT:

Set objShell = CreateObject("WdScript.Shell") objShell.Run """C:\Program Files\WebDrive\webdrive.exe"" W: /d" Set objShell = Nothing

The site part of it is dependent on your particular site profile, and the W:
is dependent on the drive letter you selected to use. Whatever drive letter you chose should go where the W is.

Specifically for this instance, you could:

CONNECT:

Set objShell = CreateObject("WScript.Shell") objShell.Run """C:\Program Files\WebDrive\webdrive.exe"" /s:""syd-ftp.thruinc.net""" Set objShell = Nothing

DISCONNECT:

Set objShell = CreateObject("WScript.Shell") objShell.Run """C:\Program Files\WebDrive\webdrive.exe"" W: /d" Set objShell = Nothing

查看更多
甜甜的少女心
3楼-- · 2019-09-07 10:21
objShell.Run "start /wait /D ""c:\program files\webdrive"" webdrive.exe /s:"""syd-ftp.thruinc.net"""
                                                                           ^

Remove one of the double quote here!

You can echo out the command first to check whether it is in correct quote or not

Set objShell = CreateObject("WScript.Shell")
'WScript.Echo "start /wait /D ""c:\program files\webdrive"" webdrive.exe /s:""syd-ftp.thruinc.net"""
objShell.Run "start /wait /D ""c:\program files\webdrive"" webdrive.exe /s:""syd-ftp.thruinc.net"""
Set objShell = Nothing

I use WScript.Shell to create objShell instead of cscript.shell. It seems ok.

查看更多
登录 后发表回答