Three methods for solving path with spaces in vbs

Source: Internet
Author: User

In vbs, if the program to be run contains spaces, errors are often prompted in the usual way. In fact, there are two different solutions:

    1. Add three double quotes before and after the application. The Code is as follows:

 

 

[C-sharp] View plaincopyprint?
    1. Set wshell = Createobject ("wscript. Shell ")
    2. Wshell. Run "" C:/program files/360/360 SE/360se.exe ", 5, true
    3. Set wshell = nothing

Set wshell = Createobject ("wscript. Shell") wshell. Run "" C:/program files/360/360 SE/360se.exe ", 5, true set wshell = nothing

 

 

    1. Use CHR (34) to enclose strings with quotation marks. The Code is as follows:

 

 

[C-sharp] View plaincopyprint?
    1. Temp = "C:/program files/360/360 se3/360se.exe"
    2. Path = CHR (34) & temp & CHR (34)
    3. Set wshell = Createobject ("wscript. Shell ")
    4. Wshell. Run path, 1, true
    5. Set wshell = nothing

Temp = "C:/program files/360/360 se3/360se.exe" Path = CHR (34) & temp & CHR (34) set wshell = Createobject ("wscript. shell ") wshell. run path, 1, true set wshell = nothing

 

 

3. To increase readability, use the following code to define constants:

 

[C-sharp] View plaincopyprint?
    1. Public const vbquote = """"
    2. Temp = "C:/program files/360/360 se3/360se.exe"
    3. Path = vbquote & temp & vbquote
    4. Set wshell = Createobject ("wscript. Shell ")
    5. Wshell. Run path, 1, true
    6. Set wshell = nothing

Public const vbquote = "temp =" C:/program files/360/360 se3/360se.exe "Path = vbquote & temp & vbquoteset wshell = Createobject (" wscript. shell ") wshell. run path, 1, true set wshell = nothing

 

 

Some explanations:

    1. Because vbs regards double quotation marks as a value container, if you need to use double quotation marks as a value, you need to use a double quotation mark before and after it.
    2. While CHR (integer I) is the character corresponding to I in the ASCII code table, and 34 corresponds to double quotation marks in the ASCII code table.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.