Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to choose a special path under vbs

2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail how to take a special path under vbs. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

1. Use the SpecialFolder constant of FSO

FSO's SpecialFolder constant depends on GetSpecialFolder (SpecialFolder). Unfortunately, there are only 3 SpecialFolder constants. 0-2 Windows 0 corresponds to WindowsFolder, which is your Windows folder. If your system is installed on disk C, then the path string "C:\ Windows" is returned. 1 returns "C:\ Windows\ system32" for SystemFolder,GetSpecialFolder (1). 2 stands for temporary folder, so I don't need to say any more, right?

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

Dim fso

Set fso = CreateObject ("Scripting.FileSystemObject") / / bind FSO object

Dim tempfolder

Const TemporaryFolder = 2

Set tempfolder = fso.GetSpecialFolder (TemporaryFolder)

Wscript.Echo tempfolder

Save the above code as a vbs file and open it and pop up the path where your temporary folder is located. This string is stored in the variable tempfolder, okay?

2. Use WshShell to get system environment variables.

The Wscript.Shell object provides a thing like Environment. Returns the collection of objects for WshEnvironment. Let's take a look at an example:

Set WshShell=Wscript.CreateObject ("Wscript.Shell") / / bind WSH object

Set WshSysEnv=WshShell.Environment ("Process")

Wscript.Echo WshSysEnv.Item ("SYSTEMROOT")

Save the above code as a vbs file, run, does it pop up your system path? "C:\ windows", right?

Some people may ask, what if you want to take another path? Depending on your system environment variables, there are generally the following system environment variables:

Name description

The number of processors running on the NUMBER_OF_PROCESSORS computer.

The type of processor used by the PROCESSOR_ARCHITECTURE user workstation.

The processor ID of the PROCESSOR_IDENTIFIER user workstation.

The processor level of the PROCESSOR_LEVEL user workstation.

The processor version of the PROCESSOR_REVISION user workstation.

The operating system used by the OS user station.

The command (usually cmd.exe) used by COMSPEC to run the Command prompt window.

HOMEDRIVE local primary drive (usually C drive).

The default path for HOMEPATH users (usually\ users\ default on WindowsNT).

PATH path environment variable.

The extension of the PATHEXT executable file (typically .com, .exe, .bat, or .cmd).

The PROMPT command prompt (usually $pinch).

The local drive where the SYSTEMDRIVE system is located (for example, c:\).

The SYSTEMROOT system directory (for example, c:\ winnt). Same as WINDIR.

WINDIR system directory (for example, c:\ winnt). Same as SYSTEMROOT.

The directory where TEMP stores temporary files (for example, c:\ temp). The user can change.

The directory where TMP stores temporary files (for example, c:\ temp). The user can change.

You can replace the SYSTEMROOT in WshSysEnv.Item ("SYSTEMROOT") with the variables above.

3. Use the SpecialFolders attribute of WshShell

The SpecialFolders property provides a WshSpecialFolders object to access Windows's shell folders, such as the desktop folder, the start menu folder, and the personal documents folder.

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 total SpecialFolders attributes?

AllUsersDesktop

AllUsersStartMenu

AllUsersPrograms

AllUsersStartup

Desktop

Favorites

Fonts

MyDocuments

NetHood

PrintHood

Programs

Recent

SendTo

StartMenu

Startup

Templates

If you look at the above folder, you can guess what the path is, right? If you think I'm incomplete, you can use the following script code to see for yourself:

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 the available SpecialFolders pops up one by one.

This is the end of this article on "how to take a special path under vbs". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report