Create a folder on a remote computer (folder names consist of spaces)

This code INCORRECTLY creates a folder on the remote computer called "Program".
I actually want it to create a folder within Program Files called NEW FOLDER (C:\Program Files\NEW FOLDER).

msgbox "starting"
'strFolder = "c:\Program Files\NEW FOLDER"
'strFolder = "c:\Program Files\NEW" & chr(32) &  "FOLDER"
strFolder = "c:\Program" & chr(32) & "Files\NEW" & chr(32) &  "FOLDER"
msgbox strFolder
strComputer = "RemoteComputer"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2:Win32_Process")
errReturn = objWMIService.Create("cmd.exe /c md " & strFolder & chr(34) , Null, Null, intProcessID)
msgbox errReturn
msgbox "Done"
goldstarAsked:
Who is Participating?
 
Shift-3Connect With a Mentor Commented:
You just need another chr(34) in front of strFolder so that the entire path is enclosed in quotes.

msgbox "starting"
strFolder = "c:\Program Files\NEW FOLDER"
msgbox strFolder
strComputer = "RemoteComputer"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2:Win32_Process")
errReturn = objWMIService.Create("cmd.exe /cmd " & chr(34) & strFolder & chr(34) , Null, Null, intProcessID)
msgbox errReturn
msgbox "Done"
0
 
goldstarAuthor Commented:
Big DUH but that is what I was hoping for.

Thank you for your quick response!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.