A summary of some methods for taking special paths under VBS _VBS

Source: Internet
Author: User
Tags constant
1, with the FSO SpecialFolder constant

The FSO's SpecialFolder constant relies on a function of GetSpecialFolder (SpecialFolder), which, regrettably, has only 3 SpecialFolder constants, 0-2,0 corresponds to Windowsfolder, Is your Windows folder, if your system is installed in the C disk, then return is "C:\Windows" this path string. 1 corresponds to Systemfolder,getspecialfolder (1) to return to "C:\Windows\system32". 2 represents a temporary folder, don't I say more?

The following is an example of a temporary folder path string:

Dim FSO
Set fso = CreateObject ("Scripting.FileSystemObject")//Binding FSO Object
Dim TempFolder
Const Temporaryfolder = 2
Set TempFolder = fso. GetSpecialFolder (Temporaryfolder)
WScript.Echo TempFolder

You save the above code as a VBS file and try to open the path to your temporary folder. This string is stored in the variable tempfolder, okay?

2, using WshShell to take the system environment variable

The Wscript.Shell object provides environment this one dongdong. Returns the collection of objects for the wshenvironment. First look at an example:

Set wshshell=wscript.createobject ("Wscript.Shell")//Binding WSH Object
Set wshsysenv=wshshell.environment ("Process")
WScript.Echo Wshsysenv.item ("SYSTEMROOT")

Save the above code as a VBS file, run, is not pop-up your system path? "C:\windows," right?

Someone would ask, if you want to take another path? Depending on your system environment variables, the system environment variables are generally the following:

Name Description
Number_of_processors the number of processors running on the computer.
Processor_architecture the type of processor used by the user station.
Processor_identifier the processor ID of the user station.
Processor_level The processor level of the user station.
Processor_revision the processor version of the user station.
The operating system used by the OS user station.
ComSpec the command (usually Cmd.exe) that is used to run the command Prompt window.
Homedrive the local master drive (usually the C drive).
The default path for the HomePath user (usually \users\default on windowsnt).
Path PATH environment variable.
Pathext the extension of the executable file (usually. com,. exe,. bat, or. cmd).
The prompt command prompt (usually $p$g).
The local drive (for example, C:\) where the systemdrive system resides.
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). User can change.
TMP stores the directory of temporary files (for example, C:\Temp). User can change.

You can replace the SYSTEMROOT in Wshsysenv.item ("SYSTEMROOT") with the above variable.

3, with the WshShell specialfolders properties

The Specialfolders property provides Wshspecialfolders objects to access Windows shell folders, such as Desktop folders, Start menu folders, and personal document folders.

The following Biweilun gives an example:

Set wshshell=wscript.createobject ("Wscript.Shell")
WScript.Echo "Yourdesktopis" &wshshell.specialfolders ("Desktop")

This is a string that pops up the path to your desktop folder, but you can also choose to save it with a string. So, what are the specialfolders attributes altogether?

Allusersdesktop
Allusersstartmenu
Allusersprograms
AllUsersStartup
Desktop
Favorites
Fonts
MyDocuments
NetHood
PrintHood
Programs
Recent
SendTo
StartMenu
Startup
Templates

The above folder can you guess what the path is? If you think I'm not fully written, you can use the following scripting code to see:

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 popped up to show.

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.