user505210
user505210

Reputation: 1402

running a script using WScript.Shell on a network location

I have a script which is on a network path and when I use the below code to run it I get an error the system cannot find the file specified.Do I need to do something for this to work in a network location.

CreateObject("WScript.Shell").Run "\\\host\aid\prog\Files.vbs" & Trim(arglist), 0, True

Thanks

Upvotes: 1

Views: 5536

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200553

You trim leading an trailing spaces from your argument list and then concatenate the result to the script path. Unless your argument list is an empty string this will create a non-existing filename. Example:

arglist = "/foo"
WScript.Echo "\\host\aid\prog\Files.vbs" & Trim(arglist)

produces the following output:

\\host\aid\prog\Files.vbs/foo

To make your code work you need to add a space between script path and arguments:

...
filename = "\\host\aid\prog\Files.vbs"
CreateObject("WScript.Shell").Run filename & " " & Trim(arglist), 0, True

Upvotes: 2

Related Questions