Summary of some methods for getting special paths in vbs

Source: Internet
Author: User

1. Use the specialfolder constant of FSO

The specialfolder constant of FSO depends on getspecialfolder (specialfolder). Unfortunately, specialfolder has only three constants, 0-2 and 0 correspond to windowsfolder, which is your Windows folder, if your system is attached to drive C, the returned path string is "C: \ Windows. 1 corresponds to systemfolder, getspecialfolder (1) returns "C: \ WINDOWS \ System32 ". 2 represents a Temporary Folder. Do not say more?

The following is an example of retrieving the Temporary Folder path string:

Dim FSO
Set FSO = Createobject ("scripting. FileSystemObject") // bind a FSO object
Dim tempfolder
Const temporaryfolder = 2
Set tempfolder = FSO. getspecialfolder (temporaryfolder)
Wscript. Echo tempfolder

You put the aboveCodeSave it as a vbs file and open it. The path of your Temporary Folder is displayed. This string is stored in the variable tempfolder. Do you understand?

2. Use wshshell to retrieve system environment variables

The wscript. Shell object provides environment. Returns a collection of wshenvironment objects. First look at an instance:

Set wshshell = wscript. Createobject ("wscript. Shell") // bind a wsh object
Set wshsysenv = wshshell. Environment ("process ")
Wscript. Echo wshsysenv. Item ("systemroot ")

Save the above Code as a vbs file and run it. Does your system path pop up? "C: \ Windows", right?

Someone may ask, what if I want to get another path? Depending on your system environment variables, the system environment variables are generally the following:

Description
Number_of_processors: Number of processors running on the computer.
Processor_architecture the type of processor used by the user workstation.
Processor_identifier the processor ID of the user workstation.
Processor_level the processor level of the user workstation.
Processor_revision the processor version of the user workstation.
The operating system used by the OS user workstation.
Comspecused to run the alert command to prompt the alert window (usually cmd.exe ).
Homedrive local master drive (usually C drive ).
The default path of the homepath user (\ Users \ default is usually used on WindowsNT ).
PATH environment variable.
The extension name of the pathextexecutable file (usually .com;.exe,. bat, or. cmd ).
Prompt command prompt (usually $ p $ g ).
The local drive where the systemdrive system is located (for example, c :\).
Systemroot system directory (for example, c: \ WINNT ). Same as WINDIR.
WINDIR system directory (for example, c: \ WINNT ). Same as systemroot.
Temp stores the directory of temporary files (for example, c: \ Temp ). Users can change the value.
Tmp directory for storing temporary files (for example, c: \ Temp ). Users can change the value.

You can use the preceding variables to replace systemroot in wshsysenv. Item ("systemroot.

3. Use the specialfolders attribute of wshshell

The specialfolders property provides the wshspecialfolders object to Access Windows Shell Folders, such as desktop folders, Start Menu folders, and personal document folders.

The following biweilun provides an example:

Set wshshell = wscript. Createobject ("wscript. Shell ")
Wscript. Echo "yourshorttopis" & wshshell. specialfolders ("desktop ")

This is a string that pops up the path of your Desktop Folder. Of course, you can also use a string to save it. What are the total specialfolders attributes?

Allusersdesktop
Allusersstartmenu
Allusersprograms
Allusersstartup
Desktop
Favorites
Fonts
Mydocuments
Nethood
Printhood
Programs
Recent
Sendto
Startmenu
Startup
Templates

You can guess the path of the above folder? If you think that I am not fully written, you can use the following script code:

Set wshshell = wscript. Createobject ("wscript. Shell ")
'Htp: // hi.baidu.com/biweilun
'Listallspecialfolders
For each strfolder in wshshell. specialfolders
Wscript. Echo strfolder
Next

You will find that all available specialfolders are displayed one by one.

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.