Parameters and usage of Stream, WshShell, WshUrlShortcut object, and Shell. Application

Source: Internet
Author: User
Tags delete key

Kafree collection
Source: The source cannot be determined for Forum reprinting. Please contact us if you have any copyright questions.
1. Stream Object
Component: "Adodb. Stream"
There are the following methods:
Cancel Method
The usage is as follows:
Object. Cancel
Description: cancels the call of an asynchronous Execute or Open method suspended for execution.
Close Method
The usage is as follows:
Object. Close
: Close the object
CopyTo Method
The usage is as follows:
Object. CopyTo (destStream, [CharNumber])
Note: copy the data of the image. destStream points to the image to be copied. CharNumber is an optional parameter, indicating the number of bytes to be copied. If not, it is all copied.
Flush Method
The usage is as follows:
Object. Flush
Note:
LoadFromFile Method
The usage is as follows:
Object. LoadFromFile (FileName)
Note: mount the file specified by FileName into the object. The FileName parameter is the specified user name.
Open Method
The usage is as follows:
Object. Open (Source, [Mode], [Options], [UserName], [Password])
Note: Open the object,
Parameter description: Sourece object source, not specified
Mode specifies the open Mode. Optional parameters are as follows:
AdModeRead = 1
AdModeReadWrite = 3
AdModeRecursive = 4194304
AdModeShareDenyNone = 16
AdModeShareDenyRead = 4
AdModeShareDenyWrite = 8
Admodemo-exclusive = 12
AdModeUnknown = 0
AdModeWrite = 2
Options:
AdOpenStreamAsync = 1
AdOpenStreamFromRecord = 4
AdOpenStreamUnspecified =-1
UserName: Specifies the user name. Do not specify it.
Password specifies the Password of the user name
Read Method
The usage is as follows:
Object. Read (Numbytes)
Description: reads the binary content of the specified length.
Parameter description: Numbytes specifies the degree to be read. If not specified, all data is read.
ReadText Method
The usage is as follows:
Object. ReadText (NumChars)
Description: reads the text of a specified length.
Parameter description: NumChars specifies the degree to be read. If it is not specified, all data is read.
SaveToFile Method
The usage is as follows:
Object. SaveToFile (FileName, [Options])
Description: writes the object content to the file specified by FileName.
Parameter description: file specified by FileName
The Options access option is not specified. The optional parameters are as follows:
AdSaveCreateNotExist = 1
AdSaveCreateOverWrite = 2
SetEOS Method
The usage is as follows:
Object. setEOS ()
Note:
SkipLine Method
The usage is as follows:
Object. SkipLine ()
Note:
Write Method
The usage is as follows:
Object. Write (Buffer)
Description: loads the specified data into the object.
Parameter description: Buffer is the specified content to be written.
WriteText Method
The usage is as follows:
Object. Write (Data, [Options])
Description: loads the specified text data into the object.
Parameter description: Data is the specified content to be written.
The Options write option is not specified. The optional parameters are as follows:
AdWriteChar = 0
AdWriteLine = 1
Has the following attributes:
Charset
Whether the data in the object is null is returned by EOS.
LineSeparator specifies the line feed format. Optional parameters include
AdCR = 13
AdCRLF =-1
AdLF = 10
Mode or return Mode.
Position specifies or returns the current pointer to the image data. (New OPEN: 0)
Size returns the Size of the data in the object.
Whether the status of the State add-back object is enabled.
Data Type specified or returned. The optional parameter is:
AdTypeBinary = 1
AdTypeText = 2
2. WshShell and WshUrlShortcut objects
WshShell object
ProgID Wscript. Shell
File Name WSHom. Ocx
CLSID F935DC22-1CF0-11d0-ADB9-00C04FD58A0B
IID F935DC21-1CF0-11d0-ADB9-00C04FD58A0B
The following table describes the properties related to 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 document folders.
The following table describes the methods related to the WshShell object.
Method description
CreateShortcut is created and the WshShortcut object is returned.
ExpandEnvironmentStrings extends the PROCESS environment variables and returns the result string.
Popup displays the message window containing 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 and runs the specified command in the specified window style.
WshShell. Environment
The Environment attribute returns the WshEnvironment object.
Syntax
WshShell. Environment ([strType]) = ob1_shenvironment
Note
If strType specifies the location of the environment variable, the values may be "System", "User", "Volatile", and "Process ". If strType is not provided, this method retrieves system environment variables in Windows NT or process environment variables in Windows 95.
For Windows 95, the strType parameter only supports "Process ".
The following variables are provided by the Windows operating system. The script can also obtain environment variables set by other applications.
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.
COMSPEC is the command used to run the "command prompt" window (usually cmd.exe ).
HOMEDRIVE local master drive (usually C drive ).
The default path of the HOMEPATH user (\ users \ default is usually used on Windows NT ).
PATH environment variable.
The extension of the PATHEXT executable 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.
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 ")
See
WshEnvironment object
WshEnvironment object
The WshEnvironment object is not provided directly and can be accessed using the WshShell. Environment attribute.
ProgID N/
File Name WSHom. Ocx
CLSID
IID
The following table describes the attributes associated with the WshEnvironment object.
Attribute description
Item.
Count refers to the number of enumerated 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 the WshSpecialFolders object to Access Windows shell Folders, such as desktop folders, Start Menu folders, and personal document folders.
Syntax
WshShell. SpecialFolders = obw.shspecialfolders
Example
'This code fragment shows how to access the desktop folder
Set WshShell = Wscript. CreateObject ("Wscript. Shell ")
MsgBox "Your desktop is" & WshShell. SpecialFolders ("Desktop ")
See
WshSpecialFolders object
WshSpecialFolders object
This object is not provided directly. To obtain the WshSpecialFolders object, use the WshShell. SpecialFolders attribute.
ProgID N/
File Name WSHom. Ocx
CLSID
IID
The following table describes the attributes associated with the WshSpecialFolders object.
Attribute description
Item specifies the full path of the folder (default ).
Count refers to the number of enumerated items.
The number of length enumeration items (JScript ).
WshSpecialFolders. Item
The full path of the folder specified by strFolderName is returned. It is the default property.
Syntax
WshShell. SpecialFolders. Item ("strFolderName") = strFolderPath
WshShell. SpecialFolders ("strFolderName") = strFolderPath
Note
If the requested folder (strFolderName) is unavailable, WshShell. SpecialFolders ("strFolderName") returns NULL. For example, Windows 95 does not have the AllUsersDesktop folder. If strFolderName = AllUsersDesktop, NULL is returned.
Windows 95 and Windows NT 4.0 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
See
WshShell. SpecialFolders attributes
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.
Syntax
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
See
WshShortcut object and WshUrlShortcut object
WshShortcut object
This object is not provided directly. To obtain the WshShortcut object, use the WshShell. CreateShortcut method.
ProgID N/
File Name WSHom. Ocx
CLSID F935DC28-1CF0-11d0-ADB9-00C04FD58A0B
IID F935DC27-1CF0-11d0-ADB9-00C04FD58A0B
The following table describes the properties related to the WshShortcut object.
Attribute description
Parameters of the Arguments shortcut object.
Description of the shortcut object.
The Hotkey of the shortcut object.
The icon position of the IconLocation shortcut object.
The target path of the TargetPath shortcut object.
Window style of the WindowStyle shortcut object.
The working directory of the WorkingDirectory shortcut object.
The following table describes the methods related to the WshShortcut object.
Method description
Save saves shortcuts to the specified file system.
WshShortcut. Arguments
The Arguments attribute provides the parameters of the shortcut object.
Syntax
WshShortcut. Arguments = strArguments
WshShortcut. Description
The Description attribute describes the shortcut objects.
Syntax
WshShortcut. Description = strDescription
WshShortcut. Hotkey
The HotKey attribute provides the HotKey of the shortcut object. The hotkey is the keyboard shortcut for starting or Switching programs.
Syntax
WshShortcut. HotKey = strHotKey
Note
The strHotKey BNF syntax 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 found in WINUSER. H. The hotkeys are case insensitive.
The hotkey can only activate shortcuts on Windows desktop or Windows Start Menu.
Windows resource manager does not accept ESC, ENTER, TAB, SPACE, print screen, or BACKSPACE, even if WshShortcut. Hotkey follows Win32 API support. Therefore, we recommend 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"
See
WshSpecialFolders object
WshShortcut. IconLocation
The IconLocation attribute provides the icon location of the shortcut object. The format of the icon position should be "Path, index ".
Syntax
WshShortcut. IconLocation = strIconLocation
WshShortcut. TargetPath
The TargetPath attribute provides the target path of the shortcut object.
Syntax
WshShort
WshUrlShortcut object
This object is not provided directly. To obtain the WshUrlShortcut object, you can use the WshShell. CreateShortcut method.
ProgID N/
File Name WSHom. Ocx
CLSID
IID
The following table describes the properties related to the WshUrlShortcut object.
Attribute description
Full path of the FullName URL Shortcut object.
The target path of the TargetPath URL Shortcut object.
The following table describes the methods related to the WshUrlShortcut object.
Method description
Save saves the shortcut to the specified file system.
WshUrlShortcut. FullName
The FullName attribute provides the complete path of the shortcut object.
Syntax
WshUrlShortcut. FullName = strFullName
WshUrlShortcut. TargetPath
The TargetPath attribute provides the target path of the shortcut object.
Syntax
WshUrlShortcut. TargetPath = strTargetPath
WshUrlShortcut. Save
The Save method saves a shortcut that points to the location specified by the FullName attribute.
Syntax
WshUrlShortcut. Save
WshShell. ExpandEnvironmentStrings
The ExpandEnvironmentStrings method extends the PROCESS environment variable in strString and returns the result string. The variable is enclosed by '%.
Environment variables are case insensitive.
Syntax
WshShell. ExpandEnvironmentStrings (strString) = strExpandedString
Example
MsgBox "Prompt is" & WshShell. ExpandEnviromentStrings ("% PROMPT % ")
WshShell. Popup
The Popup method displays a pop-up message box window. The messages contained in the message box are specified by strText. The title of the message box is specified by strTitle. If strTitle is omitted, the window title is Windows Scripting Host.
Syntax
WshShell. Popup (strText, [natSecondsToWait], [strTitle], [natType]) = intButton
Note
If natSecondsToWait is provided and its value is greater than zero, the message box is closed after natSecondsToWait seconds.
What is natType in Win32? The MessageBox function is the same. The following table lists the values and meanings of natType. The values in the following table can be combined.
Button type
Value description
0. The "OK" button is displayed.
1. The "OK" and "cancel" buttons are displayed.
2. The "Terminate", "retry", and "Ignore" buttons are displayed.
3. the "yes", "no", and "cancel" buttons are displayed.
4. the "yes" and "no" buttons are displayed.
5. The "retry" and "cancel" buttons are displayed.
Icon type
Value description
16 show the stop icon
32 display question mark icon
48 display exclamation point icon
64 Display Information Mark icon
The above two tables do not cover all natType values. For a complete list, see the Win32 documentation.
The returned value intButton indicates the number of the buttons clicked by the user. If you do not click the button before natSecondsToWait seconds, set intButton to-1.
Value description
1 "OK" button
2 "cancel" button
3 "stop" button
4 "retry" button
5 "Ignore" button
6 "yes" button
7 "no" button
Example
Set WshShell = Wscript. CreateObject ("Wscript. Shell ")
WshShell. Popup "Where do you want to go today? "
See
Wscript. Echo Method
Wscript. Echo
Echo parameters are displayed in the window (in cscript.exe.
Parameters are separated by spaces. In Cscript.exe, this method outputs a carriage return/line feed (cr lf) after the last parameter is displayed ).
Syntax
Wscript. Echo [anyArg...]
Example
Wscript. Echo
Wscript. Echo 1, 2, 3
Wscript. Echo "Windows Scripting Host is cool ."
WshShell. RegDelete
RegDelete deletes a key or value named strName from the registry.
Syntax
WshShell. RegDelete strName
Parameters
StrName
If strName ends with a backslash (\), this method deletes the key instead of the value.
The strName parameter must start with the root key name of one of the following columns:
Short Root Key name long root key name
HKCU HKEY_CURRENT_USER
HKLM HKEY_LOCAL_MACHINE
HKCR HKEY_CLASSES_ROOT
HKEY_USERS
HKEY_CURRENT_CONFIG
Example
Set WshShell = Wscript. CreateObject ("Wscript. Shell ")
WshShell. RegDelete "HKCU \ ScriptEngine \ Value" 'delete value "Value"
WshShell. RegDelete "HKCU \ ScriptEngine \ Key \" 'delete key "Key"
See
WshShell. RegRead method, WshShell. RegWrite Method
WshShell. RegRead
The RegRead method returns the registry key or value named strName.
Syntax
WshShell. RegRead (strName) = strValue
Parameters
StrName
If strName ends with a backslash (\), this method returns the key instead of the value.
The strName parameter must start with the root key name of the following column.
Short Long
HKCU HKEY_CURRENT_USER
HKLM HKEY_LOCAL_MACHINE
HKCR HKEY_CLASSES_ROOT
HKEY_USERS
HKEY_CURRENT_CONFIG
Note
The RegRead method only supports the REG_SZ, REG_EXPAND_SZ, REG_DWORD, REG_BINARY, and REG_MULTI_SZ data types. If the registry has other data types, RegRead returns DISP_E_TYPEMISMATCH.
Example
Set WshShell = Wscript. CreateObject ("Wscript. Shell ")
WshShell. RegRead ("HKCU \ ScriptEngine \ Val") 'read from value "Val"
WshShell. RegRead ("HKCU \ ScriptEngine \ Key \") 'read from key "Key"
See
WshShell. RegDelete method, WshShell. RegWrite Method
WshShell. RegWrite
The RegWrite method sets the registry key or value named strName.
Syntax
WshShell. RegWrite strName, anyValue, [strType]
Parameters
StrName
If strName ends with a backslash (\), this method sets the key instead of the value.
The strName parameter must start with the root key of the following column.
Short Long
HKCU HKEY_CURRENT_USER
HKLM HKEY_LOCAL_MACHINE
HKCR HKEY_CLASSES_ROOT
HKEY_USERS
HKEY_CURRENT_CONFIG
AnyValue
When the strType is REG_SZ or REG_EXPAND_SZ, The RegWrite method automatically converts anyValue to a string. If strType is REG_DWORD, anyValue is converted to an integer. If strType is REG_BINARY, anyValue must be an integer.
StrType
The RegWrite method supports the following strtypes: REG_SZ, REG_EXPAND_SZ, REG_DWORD, and REG_BINARY. If other data types are passed as strType, RegWrite returns E_INVALIDARG.
Example
Set WshShell = Wscript. CreateObject ("Wscript. Shell ")
WshShell. RegWrite "HKCU \ ScriptEngine \ Value", "Some string value"
WshShell. RegWrite "HKCU \ ScriptEngine \ Key \", 1 "REG_DWORD"
See
WshShell. RegDelete method, WshShell. RegWrite Method
WshShell. Run
Run method to create a new process that runs strCommand in the intWindowStyle window.
Syntax
WshShell. Run (strCommand, [intWindowStyle], [blnWaitOnReturn])
Parameters
StrCommand
Environment variables within the strCommand parameter are automatically extended.
IntWindowStyle
This is the value of the wShowWindow element set for the new process in the STARTUPINFO structure. The meaning is the same as that of the nCmdShow parameter in ShowWindow. One of the following values is recommended. Name Value Meaning
SW_HIDE
0. Hide the window and activate another window.
SW_MINIMIZE
6. Minimize the specified window and activate the next top-level window in Z-order.
SW_RESTORE
9. Activate and display the window. If the window is minimized or maximized, It is restored to the original size and position. Specify this flag when restoring the minimal window of the application.
SW_SHOW
5. Activate and display the window with the current size and position.
SW_SHOWMAXIMIZED
3. Activate the window and maximize the display.
SW_SHOWMINIMIZED
2. Activate the window and minimize the display of the window.
SW_SHOWMINNOACTIVE
7. Minimize the display window. The activity window maintains the activity.
SW_SHOWNA
8. The window is displayed in the current status. The activity window maintains the activity.
SW_SHOWNOACTIVATE
4. display by the nearest size and position of the window. The activity window maintains the activity.
SW_SHOWNORMAL
1. Activate and display a window. If the window is minimized or maximized, It is restored to its original size and position.
BlnWaitOnReturn
If you do not specify blnWaitOnReturn or its value is FALSE, this method immediately returns to the script for further execution without waiting for the process to end.
If blnWaitOnReturn is set to TRUE, the Run method returns any error code returned by the application. If blnWaitOnReturn is not specified or its value is FALSE, Run Returns Error code 0 (zero ).
Example
'This fragment launches Notepad with the current executed script
Set WshShell = Wscript. CreateObject ("Wscript. Shell ")
WshShell. Run ("notepad" & Wscript. ScriptFullName)
WshShell. Run ("% windir % \ notepad" & Wscript. ScriptFullName)
'This fragment returns the error code from the executed application
Return = WshShell. Run ("notepad" & Wscript. ScriptFullName, 1, TRUE)
3. Use of Shell. Application
3.1 create a Shell object
Var Shell = new ActiveXObject ("Shell. Application ");
3.2 use Shell attributes and Methods
Shell. Application
Shell. Parent
Shell. CascadeWindows ()
Shell. TileHorizontally ()
Shell. TileVertically ()
Shell. ControlPanelItem (sDir)/* For example: sysdm. cpl */
Shell. EjectPC ()
Shell. cmde (vDir)
Shell. Open (vDir)
Shell. FileRun ()
Shell. FindComputer ()
Shell. FindFiles ()
Shell. Help ()
Shell. MinimizeAll ()
Shell. UndoMinimizeALL ()
Shell. RefreshMenu ()
Shell. SetTime ()
Shell. TrayProperties ()
Shell. ShutdownWindows ()
Shell. Suspend ()
OWindows = Shell. Windows ()/* returns the ShellWindows object */
FFolder = Shell. NameSpace (vDir)/* return the Folder object of the opened vDir */
OFolder = Shell. BrowseForFolder (Hwnd, sTitle, iOptions [, vRootFolder])/* select folder dialog box */
/* Example:
Function BrowseFolder ()
{
Var Message = "Clear select folder ";
Var Shell = new ActiveXObject ("Shell. Application ");
Var Folder = Shell. BrowseForFolder (0, Message, 0x0040,0x11 );
If (Folder! = Null)
{
Folder = Folder. items (); // returns the FolderItems object
Folder = Folder. item (); // returns the Folderitem object
Folder = Folder. Path; // return Path
If (Folder. charAt (varFolder. length-1 )! = "\\"){
Folder = varFolder + "\\";
}
Return Folder;
}
}
*/
/* Example:
Var Folder = Shell. NameSpace ("C: \"); // returns the Folder object
*/
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.