' Name : SP Management Utlility
' Author : Prem Dhanendran

'Create an instance of the File System object
   dim objfile, navfile
   set objfile = Createobject("Scripting.FileSystemObject")

if isobject(objfile) then 
   set navfile = objfile.opentextfile("L:\OTAI\Package\sp.txt")
end if

'Read the Config file sp.txt on L: Drive line by line to determine the highest SP available to install
while not navfile.atendofline
   nav  = navfile.readline
   nav1 = Right(nav,13)
   nav2 = Mid(nav1,1,1)
   'Wscript.Echo "nav2 is " & nav2
   'To determine if the SP Number is above 100 
   if nav2 = "S" then
      nav3 = Mid(nav1,3,3)
      'Wscript.Echo"Over 100 SP " & nav3
      if nav2 = "\" then
         'To determine if the SP Number is below 100
         nav3 = Mid(nav1,4,2)
         'Wscript.Echo"under 100 SP " & nav3
      end if
   end if

'Determined the Highest SP number available to install at this point
   Wscript.Echo"Highest SP Num is " & nav3

'Create an instance of the Scripting Shell
   Set WshShell = CreateObject("WScript.Shell")

'Delete reference files from previous installations of the SP 
   'WshShell.run "cmd /c ""del c:\OTAI\servicepack\sp.txt /f",0,True 
   'WshShell.run "cmd /c ""del c:\OTAI\sp.txt /f",0,True 

'Create reference file on the program files folder to determine the current SP on Local Machine
   WshShell.run "cmd /c ""del c:\PROGRA~1\OTAI\mysp.txt",0,True 
   WshShell.run "cmd /c ""dir c:\PROGRA~1\OTAI\SP*_inc.bat /b /od>c:\PROGRA~1\OTAI\mysp.txt",0,True 

'Create a second instance of the File System object
   dim objfile1, navfile1
   set objfile1 = Createobject("Scripting.FileSystemObject")

'Read the Config file mysp.txt on C: Drive line by line to determine the highest SP on the Local Machine
   if isobject(objfile1) then 
      set navfile1 = objfile1.opentextfile("c:\PROGRA~1\OTAI\mysp.txt")
      set navfile2 = objfile1.Getfile("C:\PROGRA~1\OTAI\mysp.txt")
   end if

   If navfile2.size > 0 then

while not navfile1.atendofline
   nav = navfile1.readline
   'wscript.echo "Nav is " & nav
   nav4 = Right(nav,13)
   nav5 = Mid(nav4,1,1) 
   nav8 = len(nav)

   'To determine if the SP Number is above 100 
   if nav8 = 13 then
      nav6 = Mid(nav4,3,3)
         'Wscript.Echo"Over 100 SP " & nav6
      if nav8 = 11 then
         nav6 = Mid(nav,3,1)
         'Wscript.Echo"Under 10 SP " & nav6
         'To determine if the SP Number is below 100 
         if nav8 = 12 then
            nav6 = Mid(nav,3,2)
         'Wscript.Echo"under 100 SP " & nav6
         end if
      end if
   end if
 else nav6 = 0
  end if
'Determined the Highest SP number on Local Machine at this point
Wscript.Echo"Latest SP on user's PC is " & nav6
'wscript.echo "Nav3 is " & nav3
'Compute the difference between the highest SP available and latest SP on Local Machine
n = nav3 - nav6

'wscript.echo " N is " & n

'Message for user if PC already Up-to-Date
   if n <= 0 then
      wscript.echo"Your PC is already Up-to-date"
   end if

'***-----------------------------------Alternate method if you want to read latest SP from Registry--------------------------***
'Const HKEY_LOCAL_MACHINE = &H80000002
'strComputer = "."
'Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
    'strComputer & "\root\default:StdRegProv")
    'strKeyPath = "SOFTWARE\OTAI\ErrorHandler"
'strValueName = "Service Pack No."
'oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
'Wscript.Echo "Current SP Number is " & strValue
'n = nav3 - strvalue

strvalueincr = nav6 + 1
'Run the Actual batch files for updating the remaining SPs one by one automatically by going through the loop n times
'For I = 1 to n
'  strSP = "SP"& strValueincr &"_inc.bat"
'   strSp0 = "SP0"& strValueincr &"_inc.bat"
'   strSp00 = "SP00"& strValueincr &"_inc.bat"
'   dim WshShell, oExec
'   set WshShell = CreateObject("WScript.Shell")
'   'Run the SP from Cmd prompt

'   WshShell.run "cmd /c ""dir L:\OTAI\Package\"& strSP &" /s /b >>C:\OTAI\sp.txt +h",0,True 
'   WshShell.run "cmd /c ""dir L:\OTAI\Package\"& strSP0 &" /s /b >>C:\OTAI\sp.txt +h",0,True 
'   WshShell.run "cmd /c ""dir L:\OTAI\Package\"& strSP00 &" /s /b >>C:\OTAI\sp.txt +h",0,True
'   strvalueincr = strvalueincr + 1

'Error Handling incase of Local machine having the latest SP already, since n will be zero.
if objfile.FileExists("L:\OTAI\Package\sp.txt") then 
   if isobject(objfile) then 
      set navfile = objfile.opentextfile("L:\OTAI\Package\sp.txt")
         For I = 1 to nav6
      while not navfile.atendofline
         nav7 = navfile.readline
         'msgbox ("Line is") & nav7
         WshShell.run "cmd /c """&nav7&"",1,True 
      'Confirmation Message to User
      Wscript.Echo"OTAI Service packs updated to " & nav3
   end if
   'Confirmation Message to User 
   Wscript.Echo"Thank you"
end if


8 Years
Discussion Span
Last Post by premdeeprem
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.