First rule when using .Run or .Exec:
Build the command into a variable and .Echo it.
>> strNewFolderName = "NewFolderName"
>> sCmd = "cmd.exe /C NET SHARE strNewFolderName =""C:\test02\" & strNewFolderName & " "" /GRANT:" & strNewFol
derName & ",FULL"
>> WScript.Echo sCmd
>>
cmd.exe /C NET SHARE strNewFolderName ="C:\test02\NewFolderName " /GRANT:NewFolderName,FULL
Obviously, strNewFolderName
was not interpolated/replaced, because VBScript does not automagically put variable content into string literals/you forgot to concatenate the first instance of strNewFolderName
into the string.
Let's do the concatenation:
>> sCmd = "cmd.exe /C NET SHARE " & strNewFolderName & "=""C:\test02\" & strNewFolderName & " "" /GRANT:" & st
rNewFolderName & ",FULL"
>> WScript.Echo sCmd
>>
cmd.exe /C NET SHARE NewFolderName="C:\test02\NewFolderName " /GRANT:NewFolderName,FULL
Again it's obvious that there is a spurious space before the closing/second quote.
& " "" /GRANT:" &
should be
& """ /GRANT:" &
Second rule:
Use the .Echo
ed string to test your command from a console.
Assuming this test succeeds, you then can use
oShell.Run sCmd
or - even better:
iRet = oShell.Run(sCmd, [intWindowStyle], [bWaitOnReturn])
with some confidence.
If you are willing to learn, you could look at
How To Quote Like a Pro
Build your command in a more structured way