华域联盟 vbs Wscript.Shell 对象详细介绍!!特好的东西第1/2页

Wscript.Shell 对象详细介绍!!特好的东西第1/2页

分类:程序

WshShell 对象

ProgID Wscript.Shell

文件名 WSHom.Ocx

CLSID F935DC22-1CF0-11d0-ADB9-00C04FD58A0B

IID F935DC21-1CF0-11d0-ADB9-00C04FD58A0B

下表说明和 WshShell 对象有关的属性。

属性 说明

Environment 返回 WshEnvironment 集合对象。

SpecialFolders 使用 WshSpecialFolders 对象提供对 Windows shell 文件夹的访问,如桌面文件夹,开始菜单文件夹和个人文档文件夹。

下表说明和 WshShell 对象有关的方法。

方法 说明

CreateShortcut 创建并返回 WshShortcut 对象。

ExpandEnvironmentStrings 扩展 PROCESS 环境变量并返回结果字符串。

Popup 显示包含指定消息的消息窗口。

RegDelete 从注册表中删除指定的键或值。

RegRead 从注册表中返回指定的键或值。

RegWrite 在注册表中设置指定的键或值。

Run 创建新的进程,该进程用指定的窗口样式执行指定的命令。

WshShell.Environment

Environment 属性返回 WshEnvironment 对象。

语法

WshShell.Environment ( [strType]) = objWshEnvironment

注释

若 strType 指定了环境变量所处的位置,可能值为 "System"、"User"、"Volatile" 和 "Process"。若未提供 strType,则该方法在 Windows NT 中检索系统环境变量或在 Windows 95 中检索进程环境变量。

对于 Windows 95,strType 参数仅支持 "Process"。

下列变量是由 Windows 操作系统提供的。脚本也可获取由其他应用程序设置的环境变量。

名称 说明

NUMBER_OF_PROCESSORS 计算机上运行的处理器数目。

PROCESSOR_ARCHITECTURE 用户工作站使用的处理器类型。

PROCESSOR_IDENTIFIER 用户工作站的处理器 ID。

PROCESSOR_LEVEL 用户工作站的处理器级。

PROCESSOR_REVISION 用户工作站的处理器版本。

OS 用户工作站所用的操作系统。

COMSPEC 用于运行“命令提示”窗口的命令(通常为 cmd.exe)。

HOMEDRIVE 本地主驱动器(通常为 C 驱动器)。

HOMEPATH 用户的默认路径(在 Windows NT 上通常为 usersdefault)。

PATH 路径环境变量。

PATHEXT 可执行文件的扩展名(通常为 .com、 .exe、.bat 或 .cmd)。

PROMPT 命令提示符(通常为 $P$G)。

SYSTEMDRIVE 系统所在的本地驱动器(例如,c:)。

SYSTEMROOT 系统目录(例如,c:winnt)。和 WINDIR 相同。

WINDIR 系统目录(例如 c:winnt)。和 SYSTEMROOT 相同。

TEMP 存储临时文件的目录(例如,c:temp)。用户可更改。

TMP 存储临时文件的目录(例如,c:temp)。用户可更改。

示例

'' 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")

请参阅

WshEnvironment 对象

WshEnvironment 对象

WshEnvironment 对象未直接给出,可用 WshShell.Environment 属性来访问。

ProgID N/A

文件名 WSHom.Ocx

CLSID

IID

下表描述与 WshEnvironment 对象关联的属性。

属性 说明

Item 获取或设置指定的环境变量值。

Count 枚举项的数目。

length 枚举项的数目 (JScript)。

下表描述与 WshEnvironment 对象关联的方法。

方法 说明

Remove 删除指定的环境变量。

WshShell.SpecialFolders

SpecialFolders 属性提供 WshSpecialFolders 对象以便访问 Windows 的 shell 文件夹,例如桌面文件夹、开始菜单文件夹和个人文档文件夹。

语法

WshShell.SpecialFolders = objWshSpecialFolders

示例

'' This code fragment shows how to access the desktop folder

Set WshShell = Wscript.CreateObject("Wscript.Shell")

MsgBox "Your desktop is " & WshShell.SpecialFolders("Desktop")

请参阅

WshSpecialFolders 对象

WshSpecialFolders 对象

该对象未直接给出。要得到 WshSpecialFolders 对象,请使用 WshShell.SpecialFolders 属性。

ProgID N/A

文件名 WSHom.Ocx

CLSID

IID

下表描述与 WshSpecialFolders 对象关联的属性。

属性 描述

Item 指定文件夹的完整路径(默认)。

Count 枚举项的数目。

length 枚举项的数目 (JScript) 。

WshSpecialFolders.Item

Item 属性返回由 strFolderName 指定的文件夹的完整路径。它是默认属性。

语法

WshShell.SpecialFolders.Item("strFolderName") = strFolderPath

WshShell.SpecialFolders("strFolderName") = strFolderPath

注释

若请求的文件夹 (strFolderName) 不可用,则 WshShell.SpecialFolders("strFolderName") 返回 NULL。例如,Windows 95 没有 AllUsersDesktop 文件夹,如果 strFolderName = AllUsersDesktop,则返回 NULL。

Windows 95 和 Windows NT 4.0 操作系统提供下列指定文件夹:

AllUsersDesktop

AllUsersStartMenu

AllUsersPrograms

AllUsersStartup

Desktop

Favorites

Fonts

MyDocuments

NetHood

PrintHood

Programs

Recent

SendTo

StartMenu

Startup

Templates

示例

'' 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

请参阅

WshShell.SpecialFolders 属性

WshShell.CreateShortcut

CreateShortcut 方法创建 WshShortcut 对象并将其返回。如果快捷方式标题以 .url 结尾,就会创建 WshURLShortcut 对象。

语法

WshShell.CreateShortcut(strPathname) = objShortcut

示例

'' 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

请参阅

WshShortcut 对象、WshUrlShortcut 对象

WshShortcut 对象

该对象未直接给出。要获得 WshShortcut 对象,请使用 WshShell.CreateShortcut 方法。

ProgID N/A

文件名 WSHom.Ocx

CLSID F935DC28-1CF0-11d0-ADB9-00C04FD58A0B

IID F935DC27-1CF0-11d0-ADB9-00C04FD58A0B

下表说明和 WshShortcut 对象有关的属性。

属性 说明

Arguments 快捷方式对象的参数。

Description 快捷方式对象的说明。

Hotkey 快捷方式对象的热键。

IconLocation 快捷方式对象的图标位置。

TargetPath 快捷方式对象的目标路径。

WindowStyle 快捷方式对象的窗口样式。

WorkingDirectory 快捷方式对象的工作目录。

下表说明与 WshShortcut 对象有关的方法。

方法 说明

Save 将快捷方式存储到指定的文件系统中。

WshShortcut.Arguments

Arguments 属性提供快捷方式对象的参数。

语法

WshShortcut.Arguments = strArguments

WshShortcut.Description

Description 属性提供快捷方式对象的说明。

语法

WshShortcut.Description = strDescription

WshShortcut.Hotkey

HotKey 属性提供快捷方式对象的热键。热键是启动或切换程序的键盘快捷方式。

语法

WshShortcut.HotKey = strHotKey

注释

strHotKey 的BNF语法如下:

Hotkey ::= modifier* keyname

modifier ::= "ALT+" | "CTRL+" | "SHIFT+" | "EXT+"

keyname ::= "A" .. "Z" |

"0".. "9" |

"Back" | "Tab" | "Clear" | "Return" |

"Escape" | "Space" | "Prior" | ...

所有键的名称都可以在 WINUSER.H 中找到。热键不区分大小写。

热键只能激活位于 Windows 桌面或 Windows“开始”菜单的快捷方式。

Windows 资源管理器不接受 ESC、ENTER、TAB、SPACE、PRINT SCREEN 或 BACKSPACE,即使 WshShortcut.Hotkey 遵循 Win32 API 支持它们。因此,建议在快捷方式中不要用这些键。

示例

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"

请参阅

WshSpecialFolders 对象

WshShortcut.IconLocation

IconLocation 属性提供快捷方式对象的图标位置。图标位置的格式应为 "Path,index"。

语法

WshShortcut.IconLocation = strIconLocation

WshShortcut.TargetPath

TargetPath 属性提供快捷方式对象的目标路径。

语法

WshShortcut.TargetPath = strTargetPath

WshShortcut.WindowStyle

WindowStyle 属性提供快捷方式对象的窗口样式。

语法

WshShortcut.WindowStyle = natWindowStyle

WshShortcut.WorkingDirectory

WorkingDirectory 为一个快捷方式对象提供工作目录。

语法

WshShortcut.WorkingDirectory = strWorkingDirectory

WshShortcut.Save

Save 方法把快捷方式对象保存到由 FullName 属性指定的位置。

语法

WshShortcut.Save

WshUrlShortcut 对象

该对象未直接给出。要获取 WshUrlShortcut 对象,可使用 WshShell.CreateShortcut 方法。

ProgID N/A

文件名 WSHom.Ocx

CLSID

IID

1
2
下一页
阅读全文
您可能感兴趣的文章:

本文由 华域联盟 原创撰写:华域联盟 » Wscript.Shell 对象详细介绍!!特好的东西第1/2页

转载请保留出处和原文链接:https://www.cnhackhy.com/14309.htm

本文来自网络,不代表华域联盟立场,转载请注明出处。

作者: sterben

发表回复

联系我们

联系我们

2551209778

在线咨询: QQ交谈

邮箱: [email protected]

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

关注微博
返回顶部