Although the Windows system is operated every day, I have taken a look at the relevant information in msdn. Nima has a big head and it is not good at English. Secondly, I am not familiar with some class libraries on Windows. After all, I am dealing with Java more often. I have read so many class libraries, but I don't know how to call them. I am so helpless. I am going to learn them one by one. It is a little impractical. Gradually accumulate...
This CP asked me to write a vbs script to check whether the terminal device has been installed with a specified patch and whether the remote desktop service has been enabled. Instead, I had to search for information and finally generate the following script.
Key Data source:
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. fullnameif lcase (right (host, Len (host)-route Rev (host, "\") = "wscript.exe" then WS. run "cscript" "& wscript. scriptfullname & CHR (34), 0 wscript. quitend ifset oexec = ws. exec ("netstat-ano") dim allinputallinput = "" doallinput = allinput & oexec. stdout. readline & vbcrlfloop while not oexec. stdout. atendofstream set objfso = Createobject ("Script Ing. fileSystemObject ") set objtextfile = objfso. opentextfile ("checkresult", 2, true) If instr (allinput, "3389")> 0 then' has enabled remote desktop, check whether the patch has installed ckinfo = checkos () if instr (ckinfo, "indows 7")> 0 then'win7 has installed the patch status1 = checkparticipant hotfix ("2621440") 'kb2621440 status2 = checkparticipant hotfix ("2667402 ") 'kb2621440 status = status1 and status2if status = true then' msgbox "1", 64, "check result" objtextfile. write Line (1) elseif status = false then 'msgbox "0", 64, "check result" objtextfile. writeline (0) end if else status = checkparticipant hotfix ("2621440") 'kb2621440 if status = true then 'msgbox "1", 64, "check result" objtextfile. writeline (1) elseif status = false then 'msgbox "0", 64, "check result" objtextfile. writeline (0) end if end ifelse 'msgbox "1", 64, "check result" objtextfile. writeline (1) end if status = checkparticipant ularhotfix (hotfixid) If Status = true thenwscript. echo "the Microsoft KB" & hotfixid & "is installed. "elseif status = false thenwscript. echo "the Microsoft KB" & hotfixid & "is not installed. "Else 'errorwscript. echo "error, unable to check for Microsoft KB. error is: "& statusend ifprivate function checkparticipant hotfix (strhotfixid) '''''''''''''''''''''''''''''''''''''''' ''' version 1.0 'Check S if a particle hotfix is installed or not. 'This function has these 3 return options: 'true, false, <error description> '''''''''''''''''''''''''''''''''''' ''' on error resume nextset ob1_miservice = GetObject ("winmgmts: "_ &" {impersonationlevel = impersonate }! \\. \ Root \ cimv2 ") if err. number <> 0 thencheckparticipant hotfix = "WMI cocould not connect to computer 'localcompute'" Exit function' no reason to continueend ifstrwmiforesp = "select * From win32_quickfixengineering where hotfixid = 'q" & strhotfixid & _ "'or hotfixid = 'kb" & strhotfixid & "'" set colquickfixes = ob1_miservice. execquery (strwmiforesp) If err. number <> 0 then' if an error occurscheckpartic Ularhotfix = "unable to get WMI hotfix Info" else 'error number 0 meaning no error occured tal = colquickfixes. countif tal> 0 thencheckparticipant hotfix = true 'hf installedelse checkparticipant hotfix = false 'hf not installedend ifend ifset colquickfixes = nothingerr. clearon error goto 0end function 'check the operating system version private function checkos () set ob1_miservice = GetObject ("winmgmts:" _ & "{impersonationlevel = Impersonate }! \. \ Root \ cimv2 ") set coloperatingsystems = arrays. execquery _ (" select * From nation ") for each objoperatingsystem in coloperatingsystems osinfo = objoperatingsystem. Caption nextcheckos = osinfoend Function