VBScriptメモ2
4938 ワード
毎日Windowsのシステムを操作していますが、MSDNの関連資料を狙ってみると、ニマ、頭が大きくなって、英語が下手です.次にwindowsの上のいくつかのクラスライブラリに対して全く見覚えがなくて、結局もっと多い時JAVAと付き合っています.そんなに多くの種類のライブラリを見て、しかしどのように呼び出すことを知らないで、本当に灰はいつも仕方がなくて、一つ一つ勉強して、今また少し現実的ではありません.少しずつ積み重ねて...
今回のCPは私にVBSスクリプトを書いて端末設備が指定したパッチをかけたかどうか、リモートデスクトップサービスを開いたかどうかを検査させて、仕方なくあちこちで資料を探して最終的に次のようなスクリプトを出しました.
重要資料出典:
http://community.spiceworks.com/scripts/show/349-check-if-a-windows-update-is-installed-on-a-pc-vbs
http://msdn.microsoft.com/en-us/library/aa387287%28v=vs.85%29.aspx
http://www.w3school.com.cn/vbscript/index.asp
今回のCPは私にVBSスクリプトを書いて端末設備が指定したパッチをかけたかどうか、リモートデスクトップサービスを開いたかどうかを検査させて、仕方なくあちこちで資料を探して最終的に次のようなスクリプトを出しました.
重要資料出典:
http://community.spiceworks.com/scripts/show/349-check-if-a-windows-update-is-installed-on-a-pc-vbs
http://msdn.microsoft.com/en-us/library/aa387287%28v=vs.85%29.aspx
http://www.w3school.com.cn/vbscript/index.asp
Set ws = CreateObject("WScript.Shell")
host = WScript.FullName
If LCase( right(host, len(host)-InStrRev(host,"\")) ) = "wscript.exe" Then
ws.run "cscript """ & WScript.ScriptFullName & chr(34), 0
WScript.Quit
End If
Set oexec = ws.Exec("netstat -ano")
Dim allInput
allInput = ""
Do
allInput = allInput & oExec.StdOut.ReadLine & vbCRLF
Loop While Not oExec.StdOut.AtEndOfStream
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile ("checkResult", 2, True)
If InStr(allInput,"3389")>0 Then
'
ckinfo = checkOS()
If InStr(ckinfo,"indows 7")>0 Then
'win7
status1 = CheckParticularHotfix("2621440") 'KB2621440
status2 = CheckParticularHotfix("2667402") 'KB2621440
status = status1 And status2
If status = true Then
'MsgBox "1", 64, " "
objTextFile.WriteLine(1)
ElseIf status = false Then
'MsgBox "0", 64, " "
objTextFile.WriteLine(0)
End If
Else
status = CheckParticularHotfix("2621440") 'KB2621440
If status = true then
'MsgBox "1", 64, " "
objTextFile.WriteLine(1)
ElseIf status = false Then
'MsgBox "0", 64, " "
objTextFile.WriteLine(0)
End If
End If
Else
'MsgBox "1", 64, " "
objTextFile.WriteLine(1)
End If
status = CheckParticularHotfix(HotFixID)
If status = true then
wscript.Echo "The Microsoft KB" & HotFixID & " IS installed."
ElseIf status = false Then
wscript.Echo "The Microsoft KB" & HotFixID & " is NOT installed."
Else
'Error
wscript.Echo "Error, unable to check for Microsoft KB. Error is: " & status
End If
private Function CheckParticularHotfix(strHotfixID)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Version 1.0
' Checks if a particular hotfix is installed or not.
' This function has these 3 return options:
' TRUE, FALSE, <error description>
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
On error resume next
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\.\root\cimv2")
if err.number <> 0 then
CheckParticularHotfix = "WMI could not connect to computer 'localCompute'"
exit function 'No reason to continue
end if
strWMIforesp = "Select * from Win32_QuickFixEngineering where HotFixID = 'Q" & strHotfixID &_
"' OR HotFixID = 'KB" & strHotfixID & "'"
Set colQuickFixes = objWMIService.ExecQuery (strWMIforesp)
if err.number <> 0 Then 'if an error occurs
CheckParticularHotfix = "Unable to get WMI hotfix info"
else 'Error number 0 meaning no error occured
tal = colQuickFixes.count
if tal > 0 then
CheckParticularHotfix = True 'HF installed
else
CheckParticularHotfix = False 'HF not installed
end If
end if
Set colQuickFixes = Nothing
Err.Clear
On Error GoTo 0
End Function
'
private Function checkOS()
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
osInfo = objOperatingSystem.Caption
Next
checkOS = osInfo
End Function