In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail the example analysis of Stream, WshShell, WshUrlShortcut objects and Shell.Application parameters. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
1.Stream object
Component: "Adodb.Stream"
There are the following ways:
Cancel method
The method of use is as follows
Object.Cancel
Description: cancels a call to a pending asynchronous Execute or Open method.
Close method
The method of use is as follows
Object.Close
: close the object
CopyTo method
The method of use is as follows
Object.CopyTo (destStream, [CharNumber])
Description: copy the data of the object. DestStream points to the object to be copied. CharNumber is an optional parameter, which refers to the number of bytes to be copied. Do not select all of them.
Flush method
The method of use is as follows
Object.Flush
Description:
LoadFromFile method
The method of use is as follows
Object.LoadFromFile (FileName)
Description: load the file specified by FileName into the object, and the parameter FileName is the specified user name.
Open method
The method of use is as follows
Object.Open (Source, [Mode], [Options], [UserName], [Password])
Description: open the object
Parameter description: Sourece object source, but not specified
Mode specifies the open mode, but not. The optional parameters are as follows:
AdModeRead = 1
AdModeReadWrite = 3
AdModeRecursive = 4194304
AdModeShareDenyNone = 16
AdModeShareDenyRead = 4
AdModeShareDenyWrite = 8
AdModeShareExclusive = 12
AdModeUnknown = 0
AdModeWrite = 2
Options specifies the options to be enabled, but not. The optional parameters are as follows:
AdOpenStreamAsync = 1
AdOpenStreamFromRecord = 4
AdOpenStreamUnspecified=-1
UserName specifies the user name, but not.
Password specifies the password of the user name
Read method
The method of use is as follows:
Object.Read (Numbytes)
Description: read the binary content of the specified length.
Parameter description: the search degree specified by Numbytes to be read. If not specified, all will be read.
ReadText method
The method of use is as follows:
Object.ReadText (NumChars)
Description: read text of specified length
Parameter description: the search degree specified by NumChars to be read. If not specified, all will be read.
SaveToFile method
The method of use is as follows:
Object.SaveToFile (FileName, [Options])
Description: write the contents of the object to the file specified by FileName
Parameter description: file specified by FileName
Options for Options access can be left unspecified. Optional parameters are as follows:
AdSaveCreateNotExist = 1
AdSaveCreateOverWrite = 2
SetEOS method
The method of use is as follows:
Object.setEOS ()
Description:
SkipLine method
The method of use is as follows:
Object.SkipLine ()
Description:
Write method
The method of use 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 method of use 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.
Options for Options writing, but not specified. Optional parameters are as follows:
AdWriteChar = 0
AdWriteLine = 1
Have the following attributes:
Charset
EOS returns whether the data in the object is empty.
LineSeparator specifies the newline format. Optional parameters are
AdCR = 13
AdCRLF =-1
AdLF = 10
Mode specifies or adds back the mode.
Position specifies or returns the current pointer to the data in the object. (new OPEN: 0)
Size returns the size of the data in the object.
Whether the object status of State is turned on.
The data type specified or returned by Type. Optional parameters are:
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 WshSpecialFolders objects to provide access to Windows shell folders, such as desktop folders, start menu folders, and personal documents folders.
The following table describes the methods related to the WshShell object.
Method description
CreateShortcut creates and returns a WshShortcut object.
ExpandEnvironmentStrings extends the PROCESS environment variable and returns the result string.
Popup displays a message window containing the specified message.
RegDelete removes 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
Annotation
If strType specifies the location of the environment variable, the possible values are "System", "User", "Volatile", and "Process". If strType is not provided, the method retrieves system environment variables in Windows NT or process environment variables in Windows 95.
Only "Process" is supported for the Windows 95 dint strType parameter.
The following variables are provided by the Windows operating system. Scripts can also get environment variables set by other applications.
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 Windows NT).
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.
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 refer to
WshEnvironment object
WshEnvironment object
The WshEnvironment object is not given directly and can be accessed using the WshShell.Environment property.
ProgID N/A
File name 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 enumerated items.
The number of length enumerated 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 a WshSpecialFolders object to access Windows's shell folders, such as the desktop folder, the start menu folder, and the personal documents folder.
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 refer to
WshSpecialFolders object
WshSpecialFolders object
The object is not given directly. To get the WshSpecialFolders object, use the WshShell.SpecialFolders property.
ProgID N/A
File name WSHom.Ocx
CLSID
IID
The following table describes the properties associated with the WshSpecialFolders object.
Attribute description
Item specifies the full path to the folder (default).
The number of Count enumerated items.
The number of length enumerated items (JScript).
WshSpecialFolders.Item
The Item property returns the full path to the folder specified by strFolderName. It is the default property.
Grammar
WshShell.SpecialFolders.Item ("strFolderName") = strFolderPath
WshShell.SpecialFolders ("strFolderName") = strFolderPath
Annotation
If the requested folder (strFolderName) is not available, WshShell.SpecialFolders ("strFolderName") returns NULL. For example, Windows 95 does not have an AllUsersDesktop folder, and if strFolderName = AllUsersDesktop, it returns NULL.
The following specified folders are available for Windows 95 and Windows NT 4.0 operating systems:
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 refer to
WshShell.SpecialFolders attribute
WshShell.CreateShortcut
The CreateShortcut method creates a WshShortcut object and returns it. If the shortcut title ends with .url, a 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 refer to
WshShortcut object, WshUrlShortcut object
WshShortcut object
The object is not given directly. To get the WshShortcut object, use the WshShell.CreateShortcut method.
ProgID N/A
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
The parameters of the Arguments shortcut object.
Description of the Description shortcut object.
The hotkey for the Hotkey shortcut object.
The icon location of the IconLocation shortcut object.
The destination path of the TargetPath shortcut object.
The 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 stores shortcuts to the specified file system.
WshShortcut.Arguments
The Arguments property provides parameters for 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 hotkeys for shortcut objects. Hotkeys are keyboard shortcuts to start or switch programs.
Grammar
WshShortcut.HotKey = strHotKey
Annotation
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 found in WINUSER.H. Hotkeys are not case sensitive.
Hotkeys can only activate shortcuts located on the Windows desktop or on the Windows start menu.
Windows Explorer does not accept ESC, ENTER, TAB, SPACE, PRINT SCREEN, or BACKSPACE, even if WshShortcut.Hotkey complies with Win32 API and supports them. 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 refer to
WshSpecialFolders object
WshShortcut.IconLocation
The IconLocation property provides the icon location of the shortcut object. The format of the icon location should be "Path,index".
Grammar
WshShortcut.IconLocation = strIconLocation
WshShortcut.TargetPath
The TargetPath property provides the target path to the shortcut object.
Grammar
WshShort
WshUrlShortcut object
The object is not given directly. To get the WshUrlShortcut object, use the WshShell.CreateShortcut method.
ProgID N/A
File name WSHom.Ocx
CLSID
IID
The following table describes the properties related to the WshUrlShortcut object.
Attribute description
The full path to the FullName URL shortcut object.
The destination 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 property provides the full path to the shortcut object.
Grammar
WshUrlShortcut.FullName = strFullName
WshUrlShortcut.TargetPath
The TargetPath property provides the target path to the shortcut object.
Grammar
WshUrlShortcut.TargetPath = strTargetPath
WshUrlShortcut.Save
The Save method saves a shortcut that points to the location specified by the FullName property.
Grammar
WshUrlShortcut.Save
WshShell.ExpandEnvironmentStrings
The ExpandEnvironmentStrings method extends the PROCESS environment variable in strString and returns the result string. Variables are enclosed by the'% 'character.
Environment variables are not case sensitive.
Grammar
WshShell.ExpandEnvironmentStrings (strString) = strExpandedString
Example
MsgBox "Prompt is" & WshShell.ExpandEnviromentStrings ("% PROMPT%")
WshShell.Popup
The Popup method displays a pop-up message box window containing messages specified by strText. The window title of the message box is specified by strTitle. If strTitle is omitted, the window title is Windows Scripting Host.
Grammar
WshShell.Popup (strText, [natSecondsToWait], [strTitle], [natType]) = intButton
Annotation
If natSecondsToWait is provided and its value is greater than zero, the message box closes after natSecondsToWait seconds.
The meaning of natType is not the same as that in Win32? The same as in the MessageBox function. The following table shows the values and meanings in natType. The values in the following table can be combined.
Button Typ
Value description
0 displays the OK button
1 display the OK and cancel buttons
2 display the stop, retry, and ignore buttons
3 display the Yes, No, and cancel buttons
4 display "Yes" and "No" buttons
5 display the retry and cancel buttons
Icon Typ
Value description
16 display the stop marker icon
32 display the question mark icon
48 display exclamation point icon
64 display information tag icon
The above two tables do not cover all the values of natType. For a complete list, see the Win32 documentation.
The return value intButton indicates the button number that the user clicked. If the user does not click the button before natSecondsToWait seconds, the intButton is set 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?"
Please refer to
Wscript.Echo method
Wscript.Echo
The Echo method displays parameters in the window (Wscript.exe) or the Command prompt window (Cscript.exe).
Parameters are separated by spaces. In Cscript.exe, this method outputs a carriage return / line feed (CR LF) pair after the last parameter is displayed.
Grammar
Wscript.Echo [anyArg...]
Example
Wscript.Echo
Wscript.Echo 1, 2, 3
Wscript.Echo "Windows Scripting Host is cool."
WshShell.RegDelete
RegDelete removes the key or value named strName from the registry.
Grammar
WshShell.RegDelete strName
Parameters.
StrName
If the strName ends with a backslash (\), the method removes the key instead of the value.
The strName parameter must start with one of the following root keys:
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"
Please refer to
WshShell.RegRead method, WshShell.RegWrite method
WshShell.RegRead
The RegRead method returns a registry key or value named strName.
Grammar
WshShell.RegRead (strName) = strValue
Parameters.
StrName
If the strName ends with a backslash (\), the method returns a key instead of a value.
The strName parameter must start with the following root key name.
Short Long
HKCU HKEY_CURRENT_USER
HKLM HKEY_LOCAL_MACHINE
HKCR HKEY_CLASSES_ROOT
HKEY_USERS
HKEY_CURRENT_CONFIG
Annotation
The RegRead method supports only REG_SZ, REG_EXPAND_SZ, REG_DWORD, REG_BINARY, and REG_MULTI_SZ data types. RegRead returns DISP_E_TYPEMISMATCH if there are other data types in the registry.
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"
Please refer to
WshShell.RegDelete method, WshShell.RegWrite method
WshShell.RegWrite
The RegWrite method sets the registry key or value named strName.
Grammar
WshShell.RegWrite strName, anyValue, [strType]
Parameters.
StrName
If the strName ends with a backslash (\), the method sets the key instead of the value.
The strName parameter must start with the following root key name.
Short Long
HKCU HKEY_CURRENT_USER
HKLM HKEY_LOCAL_MACHINE
HKCR HKEY_CLASSES_ROOT
HKEY_USERS
HKEY_CURRENT_CONFIG
AnyValue
When 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 strType of 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"
Please refer to
WshShell.RegDelete method, WshShell.RegWrite method
WshShell.Run
The Run method creates a new process that executes strCommand in the style of an intWindowStyle window.
Grammar
WshShell.Run (strCommand, [intWindowStyle], [blnWaitOnReturn])
Parameters.
StrCommand
The environment variables inside the strCommand parameter are automatically extended.
IntWindowStyle
This is the value of the wShowWindow element set within the STARTUPINFO structure for the new process. It has the same meaning as the nCmdShow parameter in ShowWindow, and can take one of the following values. 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 sorted in Z order.
SW_RESTORE
9 activate and display the window. If the window is minimized or maximized, it is restored to its original size and position. This flag should be specified when restoring the minimized window of the application.
SW_SHOW
5 activate and display the window at the current size and position.
SW_SHOWMAXIMIZED
3 activate the window and maximize the window.
SW_SHOWMINIMIZED
2 activate the window and display it to a minimum.
SW_SHOWMINNOACTIVE
7 minimize the display window. The active window remains active.
SW_SHOWNA
8 displays the window in its current state. The active window remains active.
SW_SHOWNOACTIVATE
4 display by the nearest size and position of the window. The active window remains active.
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 blnWaitOnReturn is not specified or its value is FALSE, the method immediately returns to the script to continue 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. About the use of Shell.Application
3.1.Create Shell object
Var Shell = new ActiveXObject ("Shell.Application")
3.2.Using Shell properties and methods
Shell.Application
Shell.Parent
Shell.CascadeWindows ()
Shell.TileHorizontally ()
Shell.TileVertically ()
Shell.ControlPanelItem (sDir) / * for example: sysdm.cpl * /
Shell.EjectPC ()
Shell.Explore (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 () / * return ShellWindows object * /
FFolder = Shell.NameSpace (vDir) / * returns the Folder object of the open 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 (0meme message meme 0x0040pr 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
, /
This is the end of this article on "sample analysis of Stream, WshShell, WshUrlShortcut objects and Shell.Application parameters". 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.