Sur*_*esh 41 string vb6 escaping
我使用以下代码来执行schtasksVB6命令.执行时,如果文件夹包含空格,则忽略该文件夹.例如,"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
Run Code Online (Sandbox Code Playgroud)
添加新任务"c:\program"而不是"C:\program files\test\test.exe"
提前致谢.
Ste*_*ing 69
在VB6或VBScript字符串中转义引号在理论上很简单,但在查看时经常会令人恐惧.你用另一个双引号来逃避双引号.
一个例子:
"c:\ program files\my app\app.exe"
如果我想要转义双引号,那么我可以将它传递给Joe列出的shell执行函数或VB6 Shell函数,我会写它:
escapedString = """c:\program files\my app\app.exe"""
Run Code Online (Sandbox Code Playgroud)
这是如何运作的?第一个和最后一个引号包装字符串,让VB知道这是一个字符串.然后在字符串中显示的每个引号都在其前面添加了另一个双引号以逃避它.
当您尝试传递具有多个引用部分的字符串时,它会变得更加疯狂.请记住,您要传递的每个报价都必须进行转义.
如果我想将这两个引用的短语作为由空格分隔的单个字符串传递(这并不罕见):
"c:\ program files\my app\app.exe""c:\ documents and settings\steve"
我会输入这个:
escapedQuoteHell = """c:\program files\my app\app.exe"" ""c:\documents and settings\steve"""
Run Code Online (Sandbox Code Playgroud)
我帮助我的系统管理员使用了一些甚至更多引用的VBScripts.
它不漂亮,但它是如何工作的.
另一个例子:
Dim myPath As String = """" & Path.Combine(part1, part2) & """"
Run Code Online (Sandbox Code Playgroud)
祝好运!