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