Here’s the code:
All I am trying to do is map 2 network drives in 1 command shell but it only maps the first one. Anyone know how to do what i’m trying to do?
Here’s the code:
All I am trying to do is map 2 network drives in 1 command shell but it only maps the first one. Anyone know how to do what i’m trying to do?
Try this:
set ryan= WScript.createobject(“wscript.shell”)
ryan.run “net use s: \myserver1\c$”
ryan.run “net use t: \myserver2\c$”
Also not sure if you should dispose your object using
set ryan = Nothing
Understood. However, can it be done by only opening 1 shell instead of 2?
I’m not really familiar with the wscript.shell object but you could try putting a carriage return in the string between the two net use commands. Alternatively, you could put the net use commands in a batch file and give ryan.run a string with the name of the batch file. Also, magog is correct that you should set the object to nothing when you’re done with it, but you may already know that.
wscript shell can only handle one command item per invocation. You can, as davidm sez, make a batch file and invoke that via the wscript.shell.run method Or, you can use cmd.exe, which DOES support multiple commands in one invocation. Try something like this:
set ryan= WScript.createobject("wscript.shell")
ryan.run "cmd.exe /c net use s: \\myserver1\c$ & net use t: \\myserver2\c$"
set ryan = Nothing
Note the & character is inside the string, not used to concatenate two strings. If this doesn’t work the first time, try enclosing each net use command in (), like this:
set ryan= WScript.createobject("wscript.shell")
ryan.run "cmd.exe /c (net use s: \\myserver1\c$) & (net use t: \\myserver2\c$)"
set ryan = Nothing
Sometimes cmd’s parser gets lost and needs a little help.
This will create an extra cmd.exe window while its trunning, but that’s only visible for a moment.