1
' open ie
2
set ie=wscript.createobject("internetexplorer.application")
3
ie.width=800
4
ie.height=336
5
ie.resizable=0
6
ie.navigate "http://www.blogjava.net/waterye/archive/2005/09/03/11886.aspx"
7
ie.visible=1
8
wscript.sleep 10000
9
ie.quit
1
' 显示ip地址
2
strComputer = "."
3
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
4
Set IPConfigSet = objWMIService.ExecQuery _
5
("Select IPAddress from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
6
For Each IPConfig in IPConfigSet
7
If Not IsNull(IPConfig.IPAddress) Then
8
For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
9
WScript.Echo IPConfig.IPAddress(i)
10
Next
11
End If
12
Next
1
' 配置ip, subnetmask, gateway, dns servers
2
Set colNetAdapters = objWMIService.ExecQuery _
3
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
4
strIPAddress = Array("192.168.0.6")
5
strSubnetMask = Array("255.255.255.0")
6
strGateway = Array("192.168.0.1")
7
strGatewayMetric = Array(1)
8
arrDNSServers = Array("202.96.128.166", "202.96.128.86")
9
For Each objNetAdapter in colNetAdapters
10
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
11
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
12
objNetAdapter.SetDNSServerSearchOrder(arrDNSServers)
13
If errEnable = 0 Then
14
WScript.Echo "The IP address has been changed."
15
Else
16
WScript.Echo "The IP address could not be changed."
17
End If
18
Next
1
' 调用shell
2
Set WshShell = Wscript.CreateObject("Wscript.Shell")
3
WshShell.Run ("notepad " & Wscript.ScriptFullName)
1
' 调用COM对象
2
Set fs = Wscript.CreateObject("Scripting.FileSystemObject")
3
Set a = fs.CreateTextFile("file.txt", True)
4
a.WriteLine("foo bar")
5
a.Close
1
' 删除服务(小心操作)
2
strComputer = "."
3
Set objWMIService = GetObject("winmgmts:" _
4
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
5
serviceName = "MySql"
6
Set colListOfServices = objWMIService.ExecQuery _
7
("Select * from Win32_Service Where Name = '" & serviceName & "'")
8
For Each objService in colListOfServices
9
WScript.Echo objService.DisplayName
10
objService.StopService()
11
objService.Delete()
12
Next
1
' 显示系统的最后启动时间
2
strComputer = "."
3
Set objWMIService = GetObject _
4
("winmgmts:\\" & strComputer & "\root\cimv2")
5
Set colOperatingSystems = objWMIService.ExecQuery _
6
("Select * from Win32_OperatingSystem")
7
For Each objOS in colOperatingSystems
8
dtmBootup = objOS.LastBootUpTime
9
dtmLastBootupTime = WMIDateStringToDate(dtmBootup)
10
Wscript.Echo "LastBootupTime: " & dtmLastBootupTime
11
Next
12
Function WMIDateStringToDate(dtmBootup)
13
WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) & "/" & _
14
Mid(dtmBootup, 7, 2) & "/" & Left(dtmBootup, 4) _
15
& " " & Mid (dtmBootup, 9, 2) & ":" & _
16
Mid(dtmBootup, 11, 2) & ":" & Mid(dtmBootup, _
17
13, 2))
18
End Function
1
' 拔掉网线时都能收到通知
2
strComputer = "."
3
4
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\wmi")
5
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
6
("Select * from MSNdis_StatusMediaDisconnect")
7
8
Do While True
9
Set strLatestEvent = colMonitoredEvents.NextEvent
10
Wscript.Echo "A network connection has been lost:"
11
WScript.Echo strLatestEvent.InstanceName, Now
12
Wscript.Echo
13
Loop BTW: 使用"Windows Script Host"在emule上可找到不少ebook, 个人觉得Apress.-.Managing.Enterprise.Systems.with.the.Windows.Script.Host.2002.chm较好