Re: another Blaster question

From: Mark Greenwood (m_jgreenwood_at_yahoo.com)
Date: 08/15/03


Date: 15 Aug 2003 13:10:00 -0700


Here is some Awesome VB code that will help you along your way..
watch for wordwraps.

Option Explicit

Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const WindowsFolder = 0
Const SystemFolder = 1

Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
Dim WshNetwork : Set WshNetwork = CreateObject("Wscript.Network")
Dim WshShell : Set WshShell = CreateObject("WScript.Shell")
Dim WshSysEnv : Set WshSysEnv = WshShell.Environment("SYSTEM")
dim strpath : strpath="\\TAC05\SOFT$\Patches\DESKTOP"
dim strpathA : strpathA="\\\\TAC05\\SOFT$\\Patches\\DESKTOP"
Dim DoThing
Dim GetOS
Dim GetSP
Dim fVer
Dim Os
Dim strAutoexec
Dim strDesktop
Dim strPrograms
Dim strStartMenu
Dim strStartup
Dim strVer
Dim fIE6Sec
Dim fWSHSec
Dim wJVMSec
Dim strSPDrive
Dim regTemp
Dim Disk
Dim GetIE
Dim wMsgsec
'*********************************************************************
' Set variable to indicate the version of the Windows operating system
'*********************************************************************
GetOS = GetTheOS 'WXP, W2K, NT4, WME, or W98
GetSP = GetServicePack 'SP1, SP2, SP3, SP4, SP5, SP6 Or None

'***************************************************************************
' Set variables to indicate the common folders that are in different
'locations on different versions of Windows
'***************************************************************************
If GetOS = "WXP" Or GetOS = "W2K" Or GetOS = "NT4" Then
 strDesktop = WshShell.SpecialFolders("AllUsersDesktop")
 strPrograms = WshShell.SpecialFolders("AllUsersPrograms")
 strStartMenu = WshShell.SpecialFolders("AllUsersStartMenu")
 strStartup = WshShell.SpecialFolders("AllUsersStartup")
End if

If GetOS = "W98" Then
 strDesktop = WshShell.SpecialFolders("Desktop")
 strPrograms = WshShell.SpecialFolders("Programs")
 strStartMenu = WshShell.SpecialFolders("StartMenu")
 strStartup = WshShell.SpecialFolders("Startup")
End if

If GetOS = "WXP" Then Call WriteLog("Installing available patches for
Windows XP")
If GetOS = "W2K" Then Call WriteLog("Installing available patches for
Windows 2000")
If GetOS = "NT4" Then Call WriteLog("Installing available patches for
Windows NT 4")
If GetOS = "W98" Then Call WriteLog("Installing available patches for
Windows 98")

'**********************************************************
'Windows XP, 2000, NT4, and 9x Updates
'**********************************************************
'Windows XP Updates
'**********************************************************
DoThing = False

If GetOS = "WXP" then
 If GetSP = "SP1" Or GetSP = "SP2" Then

        If CheckRegKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\Windows
XP\SP2\KB823980\Type") = FALSE then
                Call WriteLog("Installing Security Update KB823980")
                WshShell.Run strpath & "\\WINXP\\KB823980.exe -x /q /u", 1, TRUE
        Else
                Call WriteLog("Operating System Needs Service Pack 1 or 1a Installed
before Security Update Can Be Applied")

        End If
        
 End if
End If

'**********************************************************
'Windows 2000 Updates
'**********************************************************

If GetOS = "W2K" then
 If GetSP = "SP3" Or GetSP = "SP4" Then

        If CheckRegKey("HKEY_LOCAL_MACHINE\software\Microsoft\Updates\Windows
2000\SP5\KB823980\Type") = FALSE then
                Call WriteLog("Installing Security update KB823980")
                WshShell.Run strPath & "\Win2K\KB823980.exe -x /q /u", 1, TRUE
        Else
                Call WriteLog("Operating System Needs Service Pack 3 or 4 Installed
before Security Update Can Be Applied")
        End if

 End if
End if

'**********************************************************
'Windows NT4 Updates
'**********************************************************
' Install Secuirty Update on Windows NT4 for Blaster Worm
' Refer: Microsoft Knowledge Base Article Q823980i

If GetOS = "NT4" Then
 If GetSP = "SP6" or GetSP = "SP6a" Then

        If CompareVersion(Fso.GetFileVersion(Fso.GetSpecialFolder(SystemFolder)
& "\ole32.dll"), "4.0.1381.7224") = -1 Then
         If CompareVersion(Fso.GetFileVersion(Fso.GetSpecialFolder(SystemFolder)
& "\rpcrt4.dll"), "4.0.1381.7219") = -1 Then
          Call WriteLog("Installing Security Update Q823980i")
          WshShell.Run strPath & "\WinNT\Q823980i.exe -x /q /u", 1, TRUE
        Else
                Call WriteLog("The Operating System Needs Service Pack 6 or 6a
Installed before Security Update Can Be Applied")
         End if
    End if

 End if
End if

'***********************************************************************
' Create tag file on C: drive to indicate that this script has
completed
'***********************************************************************
If Fso.FileExists(strStartup & "\continue.vbs")Then
 Fso.CreateTextFile("c:\patchesdone.txt")
Else
 Msgbox "Done"
End if
Call WriteLog("Completed """ & Wscript.ScriptName & """")
'Exit Patches
Wscript.Quit

'**********************************************************
'Procedures
'**********************************************************
Function GetServicePack
 For Each Os in GetObject("WinMgmts://").ExecQuery("select * from
Win32_OperatingSystem where Primary=true")
' If (Os.CSDVersion) < "Service Pack 2" Then
  Select Case Os.CSDVersion
   Case "Service Pack 1" : GetServicePack = "SP1"
   Case "Service Pack 2" : GetServicePack = "SP2"
   Case "Service Pack 3" : GetServicePack = "SP3"
   Case "Service Pack 4" : GetServocePack = "SP4"
   Case "Service Pack 5" : GetServicePack = "SP5"
   Case "Service Pack 6" : GetServicePack = "SP6"
   Case Else GetServicePack = "None"
  End Select
 Next
End Function

'***************************************************************
'Function: Check the Registry Key
'***************************************************************
Function CheckRegKey(RegStr)
' Dim RegStr
  On Error Resume Next
  WshShell.RegRead RegStr
  If Err Then
    CheckRegKey = False
  Else
    CheckRegKey = True
  End If
On Error Goto 0
End Function

'***************************************************************
'Function: Check the OS Type
'***************************************************************
Function GetTheOS()
'Will work with most versions of WSH.
  Const OpenAsASCII = 0
  Const FailIfNotExist = 0

 Dim sResults, fFile

  Dim WshShell : Set WshShell = CreateObject("WScript.Shell")
  Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
  Dim sTemp : sTemp = WshShell.ExpandEnvironmentStrings("%TEMP%")
  Dim sTempFile : sTempFile = sTemp & "\runresult.tmp"

  WshShell.Run "%comspec% /c ver >" & sTempFile, 0, True

  Set fFile = FSO.OpenTextFile(sTempFile, ForReading, FailIfNotExist,
OpenAsASCII)

  sResults = fFile.ReadAll
  fFile.Close
  FSO.DeleteFile(sTempFile)

  Select Case True
'Add more info to the 98 and 95 to get the specific version. i.e. 98SE
95 a,b,or c
    Case InStr(sResults, "Windows 95") > 1 : GetTheOS = "W95"
    Case InStr(sResults, "Windows 98") > 1 : GetTheOS = "W98"
    Case InStr(sResults, "Windows NT") > 1 : GetTheOS = "NT4"
    Case InStr(sResults, "Windows 2000") > 1 : GetTheOS = "W2K"
    Case InStr(sResults, "Windows XP") > 1 : GetTheOS = "WXP"
    Case Else : GetTheOS = "Unknown"
  End Select
End Function

'***************************************************************
'Function: Compare the version being installed to the version
'already installed on the system
'***************************************************************
Function CompareVersion(ByVal Version1, ByVal Version2)
 Dim V1, V2, T1, T2
 ' Function returns -1 if Version1 < Version2
 ' Function returns 1 if Version1 > Version2
 ' Function returns 0 if Version1 = Version2
 CompareVersion = 0
 If Version1="" Or Version2="" Then
  If Version1<Version2 Then
   CompareVersion = -1
   Exit Function
  Else
   If V1>V2 Then
    CompareVersion = 1
    Exit Function
   Else
    CompareVersion = 0
    Exit Function
   End if
  End If
 End If
 T1 = Instr(Version1, ".")
 If T1 = 0 Then T1 = Len(Version1)+1
 T2 = Instr(Version2, ".")
 If T2 = 0 Then T2 = Len(Version2)+1
 Do While True
  V1 = CInt(Left(Version1,T1-1))
  V2 = CInt(Left(Version2,T2-1))
  If V1<V2 Then
   CompareVersion = -1
   Exit Function
  Else
   If V1>V2 Then
    CompareVersion = 1
    Exit Function
   End If
  End iF
  Version1 = Mid(Version1,T1+1)
  Version2 = Mid(Version2,T2+1)
  If Version1="" Or Version2="" Then
   If Version1<Version2 Then
    CompareVersion = -1
    Exit Function
   Else
    If V1>V2 Then
     CompareVersion = 1
     Exit Function
    Else
     CompareVersion = 0
     Exit Function
    End If
   End If
  End iF
  T1 = Instr(Version1, ".")
  If T1 = 0 Then T1 = Len(Version1)+1
  T2 = Instr(Version2, ".")
  If T2 = 0 Then T2 = Len(Version2)+1
 Loop
End Function

Sub DelFile(FilePath) ' For deleting files
 If (Fso.FileExists(FilePath)) Then Fso.DeleteFile(FilePath), TRUE
End Sub

Sub WriteLog(String) ' For writing description of installation to
Software Configuration.log
 Dim fLog
 ' Create the log file if it does not exist
 If not Fso.FileExists("c:\program files\software configuration.log")
Then
  Set fLog = Fso.CreateTextFile("c:\program files\Software
Configuration.log", TRUE)
  fLog.WriteLine("Software Configuration Log")
  fLog.Close
 End if
 ' Append to the log file
 Set fLog = Fso.OpenTextFile("c:\program Files\software
configuration.log", ForAppending)
 If String = "" Then
  fLog.WriteLine("")
  flog.Close
 Else
  fLog.WriteLine(Now & " " & String)
  fLog.Close
 End If
End Sub

'***************************************************************
'Function: Compare the File Date of the file being compared
'to the file date of the new file being installed
'***************************************************************
Function CompareFileDate(Version1,Version2)
 ' Function returns -1 if Version1 < Version2
 ' Function returns 1 if Version1 > Version2
 ' Function returns 0 if Version1 = Version2

If DateValue(Version1.datelastmodified)<DateValue(Version2) then
 CompareFileDate = -1
 Exit Function
ElseIf DateValue(Version1.datelastmodified)>DateValue(Version2) then
 CompareFileDate = 1
 Exit Function
Else
 CompareFileDate = 1
 Exit Function
End if

End Function

"Jerry" <nospam@hatespam.com> wrote in message news:<OqQeo0fYDHA.2328@TK2MSFTNGP12.phx.gbl>...
> BTW, we made sure the appropriate ports on the firewall were closed, the
> desktop patching is just because everyone around here is freakin out about
> this one for some reason -- someday we'll get SUS up and running --
> like I don't have enough to do :-(
>
> onward and backward
> later,
> G
>
> "Jerry" <nospam@hatespam.com> wrote in message
> news:ehwG3wfYDHA.652@TK2MSFTNGP10.phx.gbl...
> > Thanks very much, will try it first am when I get back to the office; hope
> > all hell hasn't broken loose by then
> >
> > "Tyler" <tjohnsto@butler.edu> wrote in message
> > news:O7QLi9dYDHA.2256@TK2MSFTNGP10.phx.gbl...
> > > Run "windows2000-kb823980-x86-enu.exe -x" to extract all the files. It
> > > creates a folder called update, inside that folder is the update.exe
> that
> > > you can use the /q and /u switches with.
> > >
> > > Struggled with it for half the morning.
> > >
> > > Tyler
> > >
> > > "G" <nospam@hatespam.com> wrote in message
> > > news:uJ%23$THdYDHA.2632@TK2MSFTNGP09.phx.gbl...
> > > > Please, what is the correct syntax for deploying the executable. I
> realize
> > > > this is a self-extracting archive. I am looking for complete
> unattended
> > > > installation for 1000 W2K users via batch file.
> > > >
> > > > I can get the file to the users pc's and can give them temporary admin
> > > > priviledges.
> > > >
> > > > I just need to know the correct command syntax for the file:
> > > > windows2000-kb823980-x86-enu.exe
> > > >
> > > > I tried with various combinations of -u and -q and nothing is working.
> > > > Files extract, but then I get the first screen prompting user to click
> Next.
> > > >
> > > > BTW, we just went from NT4 domain to 2003 AD last week, so don't say
> GPO,
> I
> > > > haven't the time to play with that..
> > > > Just need a quick and dirty push for this damn bug.
> > > > Thanx!!!
> > > >
> > > >
> > >
> > >
> >
> >



Relevant Pages