VB 字符串中的转义双引号
我使用以下代码从 VB6 执行 schtasks
命令。执行时,如果文件夹包含空格,则忽略文件夹。例如,"C:\program files\test\test.exe"
将转换为 "c:\program "
。我该如何解决这个问题?
MyAppname = Chr(34) & App.Path & "\" & App.EXEName & ".exe" & Chr(34)
StrCommand = "schtasks /create /sc ONLOGON /RL HIGHEST /tn myapp /tr " & MyAppname
Shell StrCommand, vbHide
新任务添加为 "c:\program"
而不是 "C:\program files\test\test.exe"
I have used following piece of code to execute schtasks
command from VB6. While executing it, ignores folder if they contains spaces. For example, "C:\program files\test\test.exe"
will be converted to "c:\program "
. How do I solve this issue?
MyAppname = Chr(34) & App.Path & "\" & App.EXEName & ".exe" & Chr(34)
StrCommand = "schtasks /create /sc ONLOGON /RL HIGHEST /tn myapp /tr " & MyAppname
Shell StrCommand, vbHide
New task added as "c:\program"
instead of "C:\program files\test\test.exe"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您尝试过使用双引号吗?无论如何,2011 年任何人都不应该受到本机 VB6 shell 命令的限制。这是一个使用 ShellExecuteEx 的函数,用途更加广泛。
Did you try using double-quotes? Regardless, no one in 2011 should be limited by the native VB6 shell command. Here's a function that uses ShellExecuteEx, much more versatile.
转义 VB6 或 VBScript 字符串中的引号理论上很简单,但看起来常常令人恐惧。您可以用另一个双引号转义一个双引号。
示例:
“c:\program files\my app\app.exe”
如果我想转义双引号,以便将其传递给 Joe 列出的 shell 执行函数或 VB6 Shell 函数,我会这样写:
How does这个工作?第一个和最后一个引号将字符串包裹起来,让 VB 知道这是一个字符串。然后,字符串中按字面显示的每个引号都会在其前面添加另一个双引号以对其进行转义。
当您尝试传递带有多个引用部分的字符串时,情况会变得更加疯狂。请记住,您想要传递的每个引用都必须转义。
如果我想将这两个带引号的短语作为由空格分隔的单个字符串传递(这并不罕见):
"c:\program files\my app\app.exe" "c:\documents and settings\steve"
我会输入:
我已经帮助我的系统管理员使用了一些带有更多引号的 VBScript。
它并不漂亮,但这就是它的工作原理。
Escaping quotes in VB6 or VBScript strings is simple in theory although often frightening when viewed. You escape a double quote with another double quote.
An example:
"c:\program files\my app\app.exe"
If I want to escape the double quotes so I could pass this to the shell execute function listed by Joe or the VB6 Shell function I would write it:
How does this work? The first and last quotes wrap the string and let VB know this is a string. Then each quote that is displayed literally in the string has another double quote added in front of it to escape it.
It gets crazier when you are trying to pass a string with multiple quoted sections. Remember, every quote you want to pass has to be escaped.
If I want to pass these two quoted phrases as a single string separated by a space (which is not uncommon):
"c:\program files\my app\app.exe" "c:\documents and settings\steve"
I would enter this:
I've helped my sysadmins with some VBScripts that have had even more quotes.
It's not pretty, but that's how it works.
另一个例子:
祝你好运!
Another example:
Good luck!