收集的Windows Script
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.aygfsteel.com/waterye/archive/2005/09/03/11886.aspx"
7
ie.visible=1
8
wscript.sleep 10000
9
ie.quit

2

3

4

5

6

7

8

9

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

2

3

4

5

6

7

8

9

10

11

12

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

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

1
' 調用shell
2
Set WshShell = Wscript.CreateObject("Wscript.Shell")
3
WshShell.Run ("notepad " & Wscript.ScriptFullName)

2

3

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

2

3

4

5

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

2

3

4

5

6

7

8

9

10

11

12

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

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

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

2

3

4

5

6

7

8

9

10

11

12

13

BTW: 使用"Windows Script Host"在emule上可找到不少ebook, 個人覺得Apress.-.Managing.Enterprise.Systems.with.the.Windows.Script.Host.2002.chm較好
posted on 2005-11-28 22:37 waterye 閱讀(681) 評論(0) 編輯 收藏 所屬分類: windows