shell.run 带变量 [英] shell.run with variable

查看:42
本文介绍了shell.run 带变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 VBS 很陌生,我想从 VBS 脚本启动一个文件.但是当我使用 String 变量时,我在让 shell.run 工作时遇到了问题.

I'm quite new to VBS and I want to start a file from a VBS script. But I've got a problem getting the shell.run to work when I use a String variable.

Set objShell = CreateObject("WScript.Shell")
sNewestFile = "D:\Path with spaces\calendar with spaces.ics"
objShell.Run sNewestFile

如果我将其更改为实际的字符串而不是变量,它就可以工作.

If I change it to the actual String instead of the Variable, it works.

Set objShell = CreateObject("WScript.Shell") 
objShell.Run """D:\Path with spaces\calendar with spaces.ics"""

我已经用围绕变量的不同 "" 组合测试了几件事情,但似乎没有任何效果.要么是系统找不到文件的失败,要么是编译器错误.

I've tested several things with different combinations of "" around the variable but nothing seems to work. Either there is a failure that the System can't find the file or a Compiler error.

推荐答案

为了引用你的变量,我建议你使用这个函数:

To quote your variable, i recommend you to use this function :

Function DblQuote(Str)
    DblQuote = Chr(34) & Str & Chr(34)
End Function

你的代码看起来像这样:

And your code looks like this one :

Set Ws = CreateObject("WScript.Shell")
sNewestFile = "D:\Path with spaces\calendar with spaces.ics"
Ws.Run DblQuote(sNewestFile),1,True
'****************************************
Function DblQuote(Str)
    DblQuote = Chr(34) & Str & Chr(34)
End Function
'****************************************

这篇关于shell.run 带变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆