Author Archive | jbmurphy

Uninstall old Java Version via vbscript

Here is my current script from removing previous versions of java via VBScript

'  FILENAME: UninstallAllOldJava.vbs
'  AUTHOR: jbmurphy
'  SYNOPSIS: This script looks for older versions of Java and removes them
'  DESCRIPTION: Searches add remove programs for J2SE or Java and removes if not current version
'  NOTES: - Must edit strCurrentVersion to match the version you want to keep
'	- if called with a computer name will, run against remote machine
'	- logs to local path defined in strLogPath
'	- assumes admin priv
'  EXAMPLE: UninstallAllOldJava.vbs
'  EXAMPLE: UninstallAllOldJava.vbs \\workststion
'  INPUTS: \\workststion (optional)
'  RETURNVALUE: logs to value in strLogPath
'  ChangeLog:
'  	2009-10-27: jbmurphy-changes made

'On Error Resume Next
Option Explicit
DIM objFSO, strComputer, strCurrentVersion, objWMIService, colInstalledVersions
DIM objVersion, strLogPath, strLogName, strExecQuery

IF WScript.Arguments.Count > 0 then
    strComputer = replace(WScript.Arguments(0),"\\","")
    strComputer = "."

strLogPath = "%TEMP%"
strLogName = "Java_Uninstall.log"

strCurrentVersion = "Java(TM) 6 Update 15"
strExecQuery = "Select * from Win32_Product Where Name LIKE '%Java 2 Runtime Environment%' OR Name LIKE '%J2SE Runtime Environment%' OR Name LIKE '%Java(TM)%'"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledVersions = objWMIService.ExecQuery (strExecQuery)

LogIt String(120, "_")
LogIt String(120, "¯")
For Each objVersion in colInstalledVersions
    If objVersion.Name = strCurrentVersion then
       LogIt Now() & ": " &replace(strComputer,".","localhost") & ": Current version is installed: " & objVersion.Name & ":" & objVersion.IdentifyingNumber
       LogIt Now() & ": " &replace(strComputer,".","localhost") & ": Uninstalling: " & objVersion.Name  & ":" & objVersion.IdentifyingNumber
    end if
LogIt String(120, "_")
LogIt String(120, "¯")
LogIt String(120, " ")

Sub LogIt (strLineToWrite)
    'wscript.echo strLineToWrite
    DIM ts
    If Not objFSO.FolderExists(strLogPath) Then MakeDir(strLogPath)
    Set ts = objFSO.OpenTextFile(strLogPath & strLogName, 8, True)
    ts.WriteLine strLineToWrite
End Sub

Function MakeDir (strPath)
	Dim strParentPath
	On Error Resume Next
	strParentPath = objFSO.GetParentFolderName(strPath)

  If Not objFSO.FolderExists(strParentPath) Then MakeDir strParentPath
	If Not objFSO.FolderExists(strPath) Then objFSO.CreateFolder strPath
	On Error Goto 0
  MakeDir = objFSO.FolderExists(strPath)
End Function

Sub KillProc()
   '# kills jusched.exe and jqs.exe if they are running.  These processes will cause the installer to fail.
   Dim wshShell
   Set wshShell = CreateObject("WScript.Shell")
   wshShell.Run "Taskkill /F /IM jusched.exe /T", 0, True
   wshShell.Run "Taskkill /F /IM jqs.exe /T", 0, True
End Sub

Trying to settle on a script documentation header

I want to add a header to all my scripts, keep things organized
This seemed like a good place to start.


'  SYMMARY: A summary of what this script does
'  DESCRIPTION: A more in depth description of the script
'  EXAMPLE: document a way of calling the script, plus expected output
'  EXAMPLE: example calling the script differently
'  EXAMPLE: rinse and repeat as needed
'  INPUTS: \\servername,yes,log (example)
'  RETURNVALUE: output type
'  ChangeLog:
'  	YYYY-MM-DD: username-changes made

What do you use? Am I missing something?

Powered by WordPress. Designed by WooThemes