0

I'm simply trying to find the right syntax to pass the following command to cmd.

net use P: "\\s0501svm1\home\John Smith"

If I type the below then it doesn't work, presumably because the double quotes aren't being passed.

Shell ("cmd.exe /k net use P: \\s0501svm1\home\John Smith")

Any ideas?

GSerg
  • 76,472
  • 17
  • 159
  • 346
Phil T
  • 67
  • 7
  • 1
    Just use proper double quotes? `Shell "cmd.exe /k net use P: " & Chr(34) & "\s0501svm1\home\John Smith" & Chr(34)` ? Also, it's better to first create the string for debugging and then to call `Shell` with that string. Also, don't use parentheses on things you don't call as functions. – Corion Jan 08 '19 at 10:00
  • 1
    `presumably because the double quotes aren't being passed` - they would have, but you did not provide any to begin with. – GSerg Jan 08 '19 at 10:31
  • Argh! Why didn't I think of that! Thanks for the help, that works perfectly. I agree completely about the string thing, I just didn't bother for the example. Why not use parentheses in this situation, if you could clarify? – Phil T Jan 08 '19 at 10:35
  • @PhilT https://stackoverflow.com/a/10262247/11683 – GSerg Jan 08 '19 at 10:48
  • Interesting. Now that I read that, it has got me before. Thanks again for your help. – Phil T Jan 10 '19 at 06:57

1 Answers1

0

i think below code can work:

Set oShell = CreateObject ("WScript.Shell") 
oShell.run "cmd.exe /C net use P: ""\s0501svm1\home\John Smith"""
MD5
  • 1,356
  • 15
  • 14
  • Thanks, but this didn't work for me - same problem, I think. The above suggestion from Corion worked great though. – Phil T Jan 08 '19 at 10:38