Archive | SCCM

Simple vbscript (HTA) to install fonts via SCCM

We have a group of users that need the ability to install fonts (.ttf and .otf). They are not administrators for their machines, so we usually go down there and install the fonts using runas. Since advertised SCCM programs can run as system, I can write a script to copy the fonts into the fonts directory. If I mark the package as allow user to intereact and run as administrator, the script will pop for the user to pick the fonts they want to install. Here is my hta code that runs once a button is clicked:

	Set objShell = CreateObject("Shell.Application")
	Set objFolder = objShell.BrowseForFolder (0, "Install Fonts From (Source):", (0))
	If objFolder Is Nothing Then
		window.close
	Else
		Set objFolderItem = objFolder.Self
		objPath = objFolderItem.Path
	End If

	Set objFso = CreateObject("Scripting.FileSystemObject")
	Set objFolder = objFso.GetFolder(objPath)
	bolGotFonts = False
	For each objFile in objFolder.Files
		If objFolder.Files.Count > 0 Then
		  If lcase(objFso.GetExtensionName(objFile.Path))="ttf" OR lcase(objFso.GetExtensionName(objFile.Path))="otf" then
			bolGotFonts = True
			DataArea.InnerHTML = DataArea.InnerHTML & "<input type=""checkbox"" name=""" & objFile.Path & """>" & objFile.Path & "</input><br/>"
		  End if
		End If
	Next
	if bolGotFonts Then DataArea.InnerHTML = DataArea.InnerHTML & "<br/><input id=runbutton  class=""button"" type=""button"" value=""Install Font"" name=""run_button""

This code will popup a browse dialog and put the filenames found in the select directory into the HTA’s DataArea.innerHTML (DataArea is just a <div>) with a checkbox and button to initiate the copy of the files:

SUB InstallFont
    DIM colChkElem, strDriveName, objChkBox
    SET colChkElem = window.document.getElementsByTagName("input")
    FOR EACH objChkBox IN colChkElem
        IF objChkBox.Type = "checkbox" THEN
            IF objChkBox.checked THEN
                strFileName = objChkBox.name
                Set objShell = CreateObject("Shell.Application")
                Set objFolder = objShell.Namespace(FONTS)
                objFolder.CopyHere strFileName
            END IF
        END IF
    NEXT
    DataArea.InnerHTML = ""
END SUB

Seems to work!

Default MAPI profiles after using Office Customization Tool

We are rolling out a new windows 7 desktop (via sccm task sequence) and one of the packages is the newly released Office 2010. I have been using OCT to modify the outlook profile via a PRF file. We want to take advantage of “cached mode” so that is one of the setting I use the PRF and OCT to set. What if I wanted to change the behavior of one machine, so that it does not use “cached mode”? Do I have to re-install office?

Seems that the default mapi profile is created by importing the PRF file. In windows 7, this registry setting can be found here:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\14.0\User Settings\{GUID}\Create\Software\Microsoft\Office\14.0\Outlook\Setup\ImportPRF

And in Windows 2008 R2 X64 it is here:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Office\14.0\User Settings\{GUID}\Create\Software\Microsoft\Office\14.0\Outlook\Setup\ImportPRF

Just have this registry key (using 8.3 names) point to a PRF with different settings and the new MAPI profiles will use this PRF.

Just discovered TSConfig.INI

I can now customize my winpe to run a VNC Server from a batch using TSConfig.INI and [CustomHook]. In theory, I can use “Create task sequence media” to create a thumb drive, that will reboot into winpe, and I can connect via WinVNC to continue the lite touch task sequence.

I really need to sit down and read the documentation. What else am I missing?

Waking up a SCCM collection from vbscript.

I wanted to wake up all the machines in a collection using a vbscript. I know that SCCM has this built in, but I could not get it working. To troubleshoot I figured I would write a script to get collection members, and then wake them via the command line with this tool: http://www.gammadyne.com/cmdline.htm#wol

GetCollectionMembers "XXX00018"

Sub GetCollectionMembers (COLLECTION_NAME)
  Set objLocation = CreateObject("WbemScripting.SWbemLocator")
  Set objService = objLocation.ConnectServer("SERVERNAME", "root\SMS\site_XXX")
  strQuery = "SELECT * FROM SMS_FullCollectionMembership WHERE CollectionID = '" & COLLECTION_NAME & "'"
  Set objSourceCollectionMembers = objService.ExecQuery(strQuery)
  For Each Resource In objSourceCollectionMembers
	WakeMachine objService,Resource.ResourceID
  Next
End Sub

Sub WakeMachine (objService,ResourceID)
  Set Machines = objService.ExecQuery("Select * From SMS_R_System where ResourceID =" & ResourceID)
  For Each Machine In Machines
	Set objShell = CreateObject("Wscript.Shell")
	strCurrentDir = Replace(WScript.ScriptFullName,WScript.ScriptName,"")
	strCommand = strCurrentDir & "\wol.exe " & Replace(Machine.MACAddresses(0),":","")
	Set objExecObject = objShell.Exec(strCommand)
  Next
End Sub

SCCM “trickle” install.

We wanted to deploy software to our environment via and assigned advertisement in SCCM, but we wanted to be able to install packages to a subset of a collection. If there is an issue the next day, the whole enterprise would not down. We already had a collection that identified machines that need the package, we just want to deploy to the first 15 one day, and another 15 the next day.

Since WQL does not allow a SQL “TOP” I did not think I would be able to do it via a complex query. So I wrote the following vbscript to find machines in one Collection and add them to another collection:

Sub CopyMachinesToCollection (SOURCE_COLLECTION,TARGET_COLLECTION,ResourcesAtATime)
	Set objLocation = CreateObject(&quot;WbemScripting.SWbemLocator&quot;)
	Set oService = objLocation.ConnectServer(&quot;server&quot;, &quot;root\SMS\site_XXX&quot;)

	Set oSourceCollectionMembers = oService.ExecQuery(&quot;SELECT ResourceID, Name FROM SMS_FullCollectionMembership WHERE CollectionID = '&quot; &amp; SOURCE_COLLECTION &amp; &quot;'&quot;)
	Set oTargetCollection = oService.Get(&quot;SMS_Collection.CollectionID='&quot; &amp; TARGET_COLLECTION &amp; &quot;'&quot;)

	' Add ResourcesAtATime resources to
	counter=0
	For Each Resource In oSourceCollectionMembers
		if counter &lt; ResourcesAtATime then
			'Wscript.Echo Resource.ResourceID  &amp; &quot;-&quot; &amp; Resource.Name
			Set DirectRule = oService.Get(&quot;SMS_CollectionRuleDirect&quot;).SpawnInstance_()
			DirectRule.ResourceClassName = &quot;SMS_R_System&quot;
			DirectRule.ResourceID = Resource.ResourceID
			DirectRule.RuleName = Resource.Name
			oTargetCollection.AddMembershipRule DirectRule, SMSContext
			oTargetCollection.RequestRefresh False
			end if
			counter=counter+1
	Next
End Sub

Sub DeleteTargetCollection (TARGET_COLLECTION)
	Set objLocation = CreateObject(&quot;WbemScripting.SWbemLocator&quot;)
	Set oService = objLocation.ConnectServer(&quot;svnyem01&quot;, &quot;root\SMS\site_SVC&quot;)

	Set oTargetCollection = oService.Get(&quot;SMS_Collection.CollectionID='&quot; &amp; TARGET_COLLECTION &amp; &quot;'&quot;)

	' Delete all in oTargetCollection
	If Not IsNull(oTargetCollection.CollectionRules) Then
		For Each Rule In oTargetCollection.CollectionRules
			wscript.echo Rule.RuleName
			oTargetCollection.DeleteMembershipRule Rule
		Next
		oTargetCollection.RequestRefresh False
	End If
End Sub

Second sub removes all machines from the collection, and the first copies the first “x” from the soure to the destination

Using a sub-select to find machines that do not have the most recent version of a package.

Many people have blogged about this – how to find machines that don’t have the most recent version of a package installed.

First we write a query to show machines that don’t have the software installed (in this case firefox)
 select SMS_R_System.Name,SMS_R_System.LastLogonUserName
	from SMS_R_System
		inner join SMS_G_System_SYSTEM on SMS_G_System_SYSTEM.ResourceID = SMS_R_System.ResourceId
	where SMS_R_System.Client = 1
		and SMS_G_System_SYSTEM.SystemRole = "Workstation"
		and SMS_G_System_SYSTEM.Name not in (
			select SMS_R_System.Name
			from  SMS_R_System inner join SMS_G_System_ADD_REMOVE_PROGRAMS on SMS_G_System_ADD_REMOVE_PROGRAMS.ResourceID = SMS_R_System.ResourceId
			where SMS_R_System.Client = 1
			and SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName like "Mozilla Firefox%")
Next we write a query to show the machines that have the most recent software installed (this is used in the following query):
select SMS_R_System.Name, SMS_R_System.LastLogonUserName, SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName,
			SMS_G_System_ADD_REMOVE_PROGRAMS.Version
	from  SMS_R_System
		inner join SMS_G_System_ADD_REMOVE_PROGRAMS on SMS_G_System_ADD_REMOVE_PROGRAMS.ResourceID = SMS_R_System.ResourceId
	where SMS_R_System.Client = 1
		and SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName like "Mozilla Firefox%"
		and SMS_G_System_ADD_REMOVE_PROGRAMS.Version = "3.6.3 (en-US)"
	order by SMS_R_System.Name

Finally we write a query to show machines that aren’t in the query above

	select SMS_R_System.Name, SMS_R_System.LastLogonUserName, SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName, SMS_G_System_ADD_REMOVE_PROGRAMS.Version
	from  SMS_R_System inner join SMS_G_System_ADD_REMOVE_PROGRAMS on SMS_G_System_ADD_REMOVE_PROGRAMS.ResourceID = SMS_R_System.ResourceId
	where SMS_R_System.Client = 1
		and SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName like "Mozilla Firefox%"
		and SMS_R_System.Name not in (
			select SMS_R_System.Name
			from  SMS_R_System inner join SMS_G_System_ADD_REMOVE_PROGRAMS on SMS_G_System_ADD_REMOVE_PROGRAMS.ResourceID = SMS_R_System.ResourceId
			where SMS_R_System.Client = 1
			and SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName like "Mozilla Firefox%"
			and SMS_G_System_ADD_REMOVE_PROGRAMS.Version = "3.6.3 (en-US)")
order by SMS_R_System.Name

Import the First and Third queries into a collection and we have a collection that shows machines that need the updated package (including machines that don’t have any version of the package installed.)

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
'  LINKS:
'  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),"\\","")
ELSE
    strComputer = "."
END If

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)%'"
KillProc

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
    else
       LogIt Now() & ": " &replace(strComputer,".","localhost") & ": Uninstalling: " & objVersion.Name  & ":" & objVersion.IdentifyingNumber
       objVersion.Uninstall()
    end if
Next
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
    ts.close
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