VBS - 引号问题(开始) [英] VBS - Issue with quotes (beginning)
问题描述
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 ?
预先感谢您的回答.
推荐答案
使用 .Run 或 .Exec 时的第一条规则:
First rule when using .Run or .Exec:
将命令构建到一个变量中并回显它.
>> 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
显然,strNewFolderName
没有插入/替换,因为 VBScript 不会自动将变量内容放入字符串文字中/您忘记将 strNewFolderName
的第一个实例连接到字符串中.
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.
让我们进行串联:
>> 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:" &
应该是
& """ /GRANT:" &
第二条规则:
使用 .Echo
ed 字符串从控制台测试您的命令.
Use the .Echo
ed string to test your command from a console.
假设本次测试成功,则可以使用
Assuming this test succeeds, you then can use
oShell.Run sCmd
或者 - 甚至更好:
iRet = oShell.Run(sCmd, [intWindowStyle], [bWaitOnReturn])
有点信心.
如果你愿意学习,可以看看
If you are willing to learn, you could look at
这篇关于VBS - 引号问题(开始)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!