Wscript.Shell Object Detailed Introduction!! Special Good Things 1th 2 page _vbs

Source: Internet
Author: User
Tags modifier
Category: Programs
WshShell objects
ProgID Wscript.Shell
FileName Wshom.ocx
CLSID f935dc22-1cf0-11d0-adb9-00c04fd58a0b
IID f935dc21-1cf0-11d0-adb9-00c04fd58a0b


The following table describes the properties associated with the WshShell object.

Attribute description
Environment returns the Wshenvironment collection object.
Specialfolders uses the Wshspecialfolders object to provide access to Windows shell folders, such as Desktop folders, Start menu folders, and personal documents folders.


The following table describes the methods associated with the WshShell object.

Method description
CreateShortcut creates and returns a Wshshortcut object.
ExpandEnvironmentStrings expands the PROCESS environment variable and returns the result string.
Popup displays the message window that contains the specified message.
RegDelete deletes the specified key or value from the registry.
RegRead returns the specified key or value from the registry.
RegWrite sets the specified key or value in the registry.
Run creates a new process that executes the specified command with the specified window style.


Wshshell.environment
The Environment property returns the Wshenvironment object.

Grammar
Wshshell.environment ([strtype]) = Objwshenvironment

Comments
If the strtype specifies where the environment variable is located, the value may be "System", "User", "Volatile", and "Process". If Strtype is not provided, the method retrieves the system environment variable in Windows NT or retrieves the process environment variable in Windows 95.

Only "Process" is supported for Windows 95,strtype parameters.

The following variables are provided by the Windows operating system. Scripts can also get environment variables that are set by other applications.

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 (typically usersdefault on Windows NT).
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 where the systemdrive system resides (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). User can change.
TMP stores the directory of temporary files (for example, c:temp). User can change.


Example
' Retrieve the number_of_processors system environment variable
Set WshShell = WScript.CreateObject ("Wscript.Shell")

Set wshsysenv = wshshell.environment ("SYSTEM")
WScript.Echo Wshsysenv ("Number_of_processors")

Please see
Wshenvironment objects


Wshenvironment objects
The Wshenvironment object is not directly given and can be accessed using the Wshshell.environment property.

ProgID N/A
FileName Wshom.ocx
Clsid
Iid


The following table describes the properties associated with the Wshenvironment object.

Attribute description
Item Gets or sets the specified environment variable value.
The number of count enumeration items.
The number of length enumeration items (JScript).


The following table describes the methods associated with the Wshenvironment object.

Method description
Remove deletes the specified environment variable.


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

Grammar
Wshshell.specialfolders = Objwshspecialfolders

Example
' This code fragment shows how to access the Desktop folder
Set WshShell = WScript.CreateObject ("Wscript.Shell")
MsgBox "Your Desktop is" & Wshshell.specialfolders ("desktop")
Please see
Wshspecialfolders objects

Wshspecialfolders objects
The object is not directly given. To get the Wshspecialfolders object, use the Wshshell.specialfolders property.

ProgID N/A
FileName Wshom.ocx
Clsid
Iid


The following table describes the properties associated with the Wshspecialfolders object.

Attribute description
ITEM Specifies the full path of the folder (default).
The number of count enumeration items.
The number of length enumeration items (JScript).

Wshspecialfolders.item
The Item property returns the full path of the folder specified by strFolderName. It is the default property.

Grammar
WshShell.SpecialFolders.Item ("strfoldername") = Strfolderpath
Wshshell.specialfolders ("strfoldername") = Strfolderpath

Comments
If the requested folder (strFolderName) is not available, wshshell.specialfolders ("strFolderName") returns NULL. For example, Windows 95 does not have a Allusersdesktop folder and returns NULL if strFolderName = Allusersdesktop.

The Windows 95 and Windows NT 4.0 operating systems provide the following specified folders:
Allusersdesktop
Allusersstartmenu

Allusersprograms

AllUsersStartup

Desktop

Favorites

Fonts

MyDocuments

NetHood

PrintHood

Programs

Recent

SendTo

StartMenu

Startup

Templates

Example
' This fragment returns the full path for the Windows Desktop folder
Set WshShell = WScript.CreateObject ("Wscript.Shell")
Strmydesktop = Wshshell.specialfolders ("Desktop")

' List All special folders
For each strfolder in Wshshell.specialfolders
MsgBox Strfolder
Next

Please see
Wshshell.specialfolders Property


Wshshell.createshortcut
The CreateShortcut method creates a Wshshortcut object and returns it. If the shortcut title ends with a. URL, the Wshurlshortcut object is created.

Grammar
Wshshell.createshortcut (strpathname) = Objshortcut

Example
' This code fragment creates a shortcut
"To the currently executing script
Set WshShell = WScript.CreateObject ("Wscript.Shell")
Set Oshelllink = wshshell.createshortcut ("Current Script.lnk")
Oshelllink.targetpath = Wscript.scriptfullname
Oshelllink.save
Set Ourllink = Wshshell.createshortcut ("Microsoft Web Site.url")
Ourllink.targetpath = "http://www.microsoft.com"
Ourllink.save

Please see
Wshshortcut objects, Wshurlshortcut objects

Wshshortcut objects
The object is not directly given. To get the Wshshortcut object, use the Wshshell.createshortcut method.

ProgID N/A
FileName Wshom.ocx
CLSID f935dc28-1cf0-11d0-adb9-00c04fd58a0b
IID f935dc27-1cf0-11d0-adb9-00c04fd58a0b


The following table describes the properties associated with the Wshshortcut object.

Attribute description
Arguments the shortcut object's parameters.
Description a description of the shortcut object.
Hotkey the shortcut object's hotkey.
IconLocation the icon position of the shortcut object.
TargetPath the target path of the shortcut object.
WindowStyle the window style of the shortcut object.
WorkingDirectory The working directory of the shortcut object.


The following table describes the methods associated with the Wshshortcut object.

Method description
Save stores the shortcuts in the specified file system.

Wshshortcut.arguments
The Arguments property provides the parameters of the shortcut object.

Grammar
Wshshortcut.arguments = strarguments

Wshshortcut.description
The Description property provides a description of the shortcut object.

Grammar
Wshshortcut.description = strdescription

Wshshortcut.hotkey
The HotKey property provides a hotkey for the shortcut object. A hotkey is a keyboard shortcut for starting or switching programs.

Grammar
Wshshortcut.hotkey = Strhotkey

Comments
The BNF syntax for Strhotkey is as follows:

Hotkey:: = modifier* KeyName
Modifier:: = "ALT +" | "Ctrl +" | "Shift+" | "Ext+"
KeyName:: = "A". "Z" |
"0". "9" |
"Back" | "Tab" | "Clear" | "Return" |
"Escape" | "Space" | "Prior" | ...

The names of all keys can be winuser. Found in H. Hot keys are case-insensitive.

Hotkeys can only activate shortcuts that are located on the Windows desktop or the Windows Start menu.

Windows Explorer does not accept ESC, ENTER, TAB, Space, PRINT screen, or BACKSPACE, even if Wshshortcut.hotkey follows the Win32 API. Therefore, it is recommended that you do not use these keys in shortcuts.

Example
Set WshShell = WScript.CreateObject ("Wscript.wshshell")
Strdesktop = Wshshell.specialfolders ("Desktop")
Set omyshortcut = wshshell.createshortcut (Strdesktop & "A_key.lnk")
Omyshortcut.targetpath = "%windir%notepad.exe"
Omyshortcut.hotkey = "Alt+ctrl+f"
Omyshortcut.save
WScript.Echo Omyshortcut.hotkey = "Alt+ctrl+f"

Please see
Wshspecialfolders objects

Wshshortcut.iconlocation
The IconLocation property provides the icon location of the shortcut object. The format of the icon position should be "Path,index".

Grammar
Wshshortcut.iconlocation = Striconlocation

Wshshortcut.targetpath
The TargetPath property provides the destination path for the shortcut object.

Grammar
Wshshortcut.targetpath = Strtargetpath

Wshshortcut.windowstyle
The WindowStyle property provides a window style for the shortcut object.

Grammar
Wshshortcut.windowstyle = Natwindowstyle

Wshshortcut.workingdirectory
WorkingDirectory provides a working directory for a shortcut object.

Grammar
Wshshortcut.workingdirectory = Strworkingdirectory

Wshshortcut.save
The Save method saves the shortcut object to the location specified by the FullName property.

Grammar
Wshshortcut.save

Wshurlshortcut objects
The object is not directly given. To get the Wshurlshortcut object, you can use the Wshshell.createshortcut method.

ProgID N/A
FileName Wshom.ocx
Clsid
Iid

Current 1/2 page 12 Next read the full text
Related Article

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.