0
strNewFolderName=%username%

oShell.run "cmd.exe /C NET SHARE strNewFolderName =""C:\test02\" & strNewFolderName & " "" /GRANT:" & strNewFolderName & ",FULL"

Kindly could you pleaes tell me where I forgot to type quotes ?

Thank you in advance for your answers.

Zong
  • 6,160
  • 5
  • 32
  • 46

2 Answers2

0

you have extra quotes here " "" /GRANT:" are you trying to include quotes in the script? if so you could use & Chr(34) for extra quotes, see this [Link] (Adding quotes to a string in VBScript)

Community
  • 1
  • 1
0

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 .Echoed 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

Community
  • 1
  • 1
Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96