wscript.shell object

1. 3个属性:A.当前目录 B.系统属性(处理器的个数,类型,操作系统相关,根目录,root驱动,可执行文件。。)C.特殊目录(desktop,startmemnum,Favorites .....)


//当前目录
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
WScript.Echo WshShell.CurrentDirectory

//C.特殊目录
set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")

2.几个方法:
AppActivate Method | CreateShortcut Method | ExpandEnvironmentStrings Method | LogEvent Method | Popup Method | RegDelete Method | RegRead Method | RegWrite Method | Run Method | SendKeys Method | Exec Method


1。AppActivate Method:激活转移focus
set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "calc"
WshShell.AppActivate "Calculator"(窗口上边的标题名字)

2。CreateShortcut Method(不用解释拉,用的不多)

3。ExpandEnvironmentStrings Method (我也不是很清楚具体用途)

Remarks
The ExpandEnvironmentStrings method expands environment variables defined in the PROCESS environment space only. Environment variable names, which must be enclosed between "%" characters, are not case-sensitive.

Example
The following code expands the Windows Directory environment variable and displays it:

[VBScript]
set WshShell = WScript.CreateObject("WScript.Shell")
WScript.Echo "WinDir is " & WshShell.ExpandEnvironmentStrings("%WinDir%")

4.LogEvent Method

向EventLog 里面添加内容
Set WshShell = WScript.CreateObject("WScript.Shell")
rc = runLoginScript() 'Returns true if logon succeeds.

if rc then
WshShell.LogEvent 0, "Logon Script Completed Successfully"
else
WshShell.LogEvent 1, "Logon Script failed"
end if

5。Popup Method

var WshShell = WScript.CreateObject("WScript.Shell");
var BtnCode = WshShell.Popup("Do you feel alright?", 7, "Answer This Question:", 4 + 32);
switch(BtnCode) {
case 6:
WScript.Echo("Glad to hear you feel alright.");
break;
case 7:
WScript.Echo("Hope you're feeling better soon.");
break;
case -1:
WScript.Echo("Is there anybody out there?");
break;
谈出一个窗口函数,可以定制窗口

6。注册表读写
Dim WshShell, bKey
Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.RegWrite "HKCU\Software\ACME\FortuneTeller\", 1, "REG_BINARY"
WshShell.RegWrite "HKCU\Software\ACME\FortuneTeller\MindReader", "Goocher!", "REG_SZ"

bKey = WshShell.RegRead("HKCU\Software\ACME\FortuneTeller\")
WScript.Echo WshShell.RegRead("HKCU\Software\ACME\FortuneTeller\MindReader")

WshShell.RegDelete "HKCU\Software\ACME\FortuneTeller\MindReader"
WshShell.RegDelete "HKCU\Software\ACME\FortuneTeller\"
WshShell.RegDelete "HKCU\Software\ACME\"

7.Run Method 运行一个新的程序

The following VBScript code does the same thing, except it specifies the window type, waits for Notepad to be shut down by the user, and saves the error code returned from Notepad when it is shut down.

Set WshShell = WScript.CreateObject("WScript.Shell")
Return = WshShell.Run("notepad " & WScript.ScriptFullName, 1, true)


8。SendKeys Method 输入键盘

9。Exec Method
Runs an application in a child command-shell, providing access to the StdIn/StdOut/StdErr streams.

Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")

Set oExec = WshShell.Exec("calc")

Do While oExec.Status = 0
WScript.Sleep 100
Loop

WScript.Echo oExec.Status

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值