/build/static/layout/Breadcrumb_cap_w.png

How To: Get user installed software on Windows 7 in KACE Inventory

Hi Everyone

I've created a fairly simple script that via a 2 step KACE Script will add all user installed software to the normal KACE Inventory with the name starting with "Userinstall [username] [original software name]"

How it works:

The first script run as the user and read all the HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall entries, this is where user installed applications add info about uninstallation
Then it take every entry in here, and from that it generate a new script called: C:\CH-Group\Install\SetUserInstall.vbs with all the info there is under the user's Add/Remove programs.
That script have to be run as a users with access to HKLM, that is why it is a new KScript, running as system.
The script first remove all the entries that it have created to make sure it clean up if the user remove the program
(If you go to: HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall you will see them in a key called "[Softwarename].user.[UserName]", so it will delete all that end with ".user.[username]")
Then it will create all the entries with the naming standard listed above, the "Displayname" how ever will show up as "Userinstall [username] [software name]" because that is what is listed in KACE, the reason I've chosing to do that is because the users we have are not local administrators and I wanna be able to easily be able to find out what the users have installed and who installed it.

This is how it is done:
You can replace the folder if you have one that you use for various stuff with the "C:\CH-Group\Install" in the script

Copy the script below as "GetUserInstall.vbs" (in the code brackets below)

Create a KScript:

Name: Get User Install
Type: Online KScript
Run on: Windows 7
Run As: User logged in to console
Scheduling: as you prefer (I've set it to run every 6 hours to start off with)
Verify:
    Verify that the file “$(KACE_DEPENDENCY_DIR)\GetUserInstall.vbs” exists.
On Success:
    Launch “$(KACE_SYS_DIR)\wscript.exe” with params “$(KACE_DEPENDENCY_DIR)\GetUserInstall.vbs”.

Create another KScript:

Name: Set User Install
Type: Offline KScript
Run on: Windows 7
Run As: [N/A]
Scheduling: as you prefer (I've set it to run every 6 hours to start off with)
Verify:
    Verify that the file “C:\CH-Group\Install\SetUserInstall.vbs” exists.
On Success:
    Launch “$(KACE_SYS_DIR)\wscript.exe” with params “C:\CH-Group\Install\SetUserInstall.vbs”.

I hope that it makes sense and you can use it :)

- René

On Error Resume Next
Const HKEY_CLASSES_ROOT   = &H80000000
Const HKEY_CURRENT_USER   = &H80000001
Const HKEY_LOCAL_MACHINE  = &H80000002
Const HKEY_USERS          = &H80000003

Const REG_SZ        = 1
Const REG_EXPAND_SZ = 2
Const REG_BINARY    = 3
Const REG_DWORD     = 4
Const REG_MULTI_SZ  = 7

Set oShell = CreateObject( "WScript.Shell" )
UserName=oShell.ExpandEnvironmentStrings("%UserName%")

' Chose computer name, registry tree and key path
'
strComputer = "." ' Use . for current machine
hDefKeyGet = HKEY_CURRENT_USER
hDefKeySet = HKEY_LOCAL_MACHINE
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"

' Connect to registry provider on target machine with current user
'
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")

' Enum the subkeys of the key path we've chosen
'
dim filesys, demofolder, filetxt
Set filesys = CreateObject("Scripting.FileSystemObject")
Set demofolder = filesys.GetFolder("C:\CH-Group\Install")
Set filetxt = demofolder.CreateTextFile("SetUserInstall.vbs", True)

filetxt.WriteLine("Const HKEY_CLASSES_ROOT   = &H80000000")
filetxt.WriteLine("Const HKEY_CURRENT_USER   = &H80000001")
filetxt.WriteLine("Const HKEY_LOCAL_MACHINE  = &H80000002")
filetxt.WriteLine("Const HKEY_USERS          = &H80000003")
filetxt.WriteLine("")
filetxt.WriteLine("Const REG_SZ        = 1")
filetxt.WriteLine("Const REG_EXPAND_SZ = 2")
filetxt.WriteLine("Const REG_BINARY    = 3")
filetxt.WriteLine("Const REG_DWORD     = 4")
filetxt.WriteLine("Const REG_MULTI_SZ  = 7")
filetxt.WriteLine("On Error Resume Next")
filetxt.WriteLine("Set oShell = CreateObject( ""WScript.Shell"" )")
filetxt.WriteLine("UserName=oShell.ExpandEnvironmentStrings(""%UserName%"")")
filetxt.WriteLine("")
filetxt.WriteLine("strComputer = ""."" ' Use . for current machine")
filetxt.WriteLine("")
filetxt.WriteLine("hDefKeySet = HKEY_LOCAL_MACHINE")
filetxt.WriteLine("strKeyPath = ""SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall""")
filetxt.WriteLine("")
filetxt.WriteLine("Set oReg = GetObject(""winmgmts:{impersonationLevel=impersonate}!\\"" & strComputer & ""\root\default:StdRegProv"")")
filetxt.WriteLine("")
filetxt.WriteLine("Dim sCompare")
filetxt.WriteLine("Dim lLen")
filetxt.WriteLine("oReg.EnumKey hDefKeySet, strKeyPath, arrSubKeys")
filetxt.WriteLine("")
filetxt.WriteLine("For Each strSubkey In arrSubKeys")
filetxt.WriteLine("")
filetxt.WriteLine("  lLen = Len("".user." & UserName & """)")
filetxt.WriteLine("  sCompare = Right(strSubkey, lLen)")
filetxt.WriteLine("' wscript.echo sCompare")
filetxt.WriteLine("	If UCASE(sCompare) = UCASE("".user." & UserName & """) Then")
filetxt.WriteLine("")
filetxt.WriteLine("     Return = oReg.DeleteKey(hDefKeySet, strKeyPath & ""\"" & strSubkey )")
filetxt.WriteLine("		If (Return = 0) And (Err.Number = 0) Then")
filetxt.WriteLine(" 	   	    'Wscript.Echo ""hDefKeySet\" & strKeyPath & "\"" & strSubkey & "".user."" & UserName & "" Deleted""")
filetxt.WriteLine("			Else")
filetxt.WriteLine("		    'Wscript.Echo ""CreateKey failed. Error = "" & Err.Number")
filetxt.WriteLine("		End If")
filetxt.WriteLine("	End If")
filetxt.WriteLine("Next")
filetxt.WriteLine("")
filetxt.WriteLine("")
filetxt.WriteLine("")
filetxt.WriteLine("")
filetxt.WriteLine("'Below here is generated depending on the user installs")
filetxt.WriteLine("")
filetxt.WriteLine("")
filetxt.WriteLine("")


oReg.EnumKey hDefKeyGet, strKeyPath, arrSubKeys

For Each strSubkey In arrSubKeys

if strSubkey <> "" Then

  ' Show the subkey
  '
'Wscript.Echo "Found: " & strSubkey

  'wscript.echo strSubkey
	Return = oReg.CreateKey(hDefKeySet, strKeyPath & "\" & strSubkey & ".user." & UserName)

	If (Return = 0) And (Err.Number = 0) Then
    	    'Wscript.Echo strKeyPath & "\" & strSubkey & ".user." & UserName & " created"
		Else
	    'Wscript.Echo "CreateKey failed. Error = " & Err.Number
	End If
filetxt.WriteLine("Return = oReg.CreateKey(hDefKeySet, strKeyPath & ""\" & strSubkey & ".user." & UserName & """)")

  ' Show its value names and types
  '
  strSubKeyPath = strKeyPath & "\" & strSubkey
  oReg.EnumValues hDefKeyGet, strSubKeyPath, arrValueNames, arrTypes

  For i = LBound(arrValueNames) To UBound(arrValueNames)
    strValueName = arrValueNames(i)
    Select Case arrTypes(i)

      ' Show a REG_SZ value
      '
      Case REG_SZ          
        oReg.GetStringValue hDefKeyGet, strSubKeyPath, strValueName, strValue
	strValue=replace(strValue,chr(34),"")
	If strValueName="DisplayName" Then
			Return = oReg.SetStringValue (hDefKeySet, strKeyPath & "\" & strSubkey & ".user." & UserName, strValueName, "UserInstall " & UserName & " - " & strValue)
		filetxt.WriteLine("Return = oReg.SetStringValue (hDefKeySet, strKeyPath & ""\" & strSubkey & ".user." & UserName & """, """  & strValueName & """ , ""UserInstall " & UserName & " - " & strValue & """)")
	Else
	Return = oReg.SetStringValue (hDefKeySet, strKeyPath & "\" & strSubkey & ".user." & UserName, strValueName, strValue)
		filetxt.WriteLine("Return = oReg.SetStringValue (hDefKeySet, strKeyPath & ""\" & strSubkey & ".user." & UserName & """, """  & strValueName & """ , """ & strValue & """)")
	If (Return = 0) And (Err.Number = 0) Then
    	    'Wscript.Echo "Created"
		Else
	    'Wscript.Echo "CreateKey failed. Error = " & Err.Number
	End If
	End If
       ' wscript.echo "  " & strValueName & " (REG_SZ) = " & strValue

      ' Show a REG_EXPAND_SZ value
      '
      Case REG_EXPAND_SZ
        oReg.GetExpandedStringValue hDefKeyGet, strSubKeyPath, strValueName, strValue
       ' wscript.echo "  " & strValueName & " (REG_EXPAND_SZ) = " & strValue
        Return = oReg.SetExpandedStringValue (hDefKeySet, strKeyPath & "\" & strSubkey & ".user." & UserName, strValueName, strValue)
	strValue=replace(strValue,chr(34),"")
	filetxt.WriteLine("Return = oReg.SetExpandedStringValue (hDefKeySet, strKeyPath & ""\" & strSubkey & ".user." & UserName & """, """ & strValueName & """, """ & strValue & """)")
	If (Return = 0) And (Err.Number = 0) Then
    	   ' Wscript.Echo "Created"
		Else
	    'Wscript.Echo "CreateKey failed. Error = " & Err.Number
	End If

      ' Show a REG_BINARY value
      '          
      Case REG_BINARY
        oReg.GetBinaryValue hDefKeyGet, strSubKeyPath, strValueName, arrBytes
	arrBytes=replace(arrBytes,chr(34),"")
        strBytes = ""
        For Each uByte in arrBytes
          strBytes = strBytes & Hex(uByte) & " "
        Next
       ' wscript.echo "  " & strValueName & " (REG_BINARY) = " & strBytes
	Return = oReg.SetBinaryValue (hDefKeySet, strKeyPath & "\" & strSubkey & ".user." & UserName, strValueName, arrBytes)
	filetxt.WriteLine("Return = oReg.SetBinaryValue (hDefKeySet, strKeyPath & ""\" & strSubkey & ".user." & UserName & """, """ & strValueName & """, """ & arrBytes &""")")


      ' Show a REG_DWORD value
      '
      Case REG_DWORD
        oReg.GetDWORDValue hDefKeyGet, strSubKeyPath, strValueName, uValue
	uValue=replace(uValue,chr(34),"")
        'wscript.echo "  " & strValueName & " (REG_DWORD) = " & CStr(uValue)				  
        Return = oReg.SetDWORDValue (hDefKeySet, strKeyPath & "\" & strSubkey & ".user." & UserName, strValueName, uValue)
	filetxt.WriteLine("Return = oReg.SetDWORDValue (hDefKeySet, strKeyPath & ""\" & strSubkey & ".user." & UserName & """, """ & strValueName & """, """ & uValue & """)")

      ' Show a REG_MULTI_SZ value
      '
      Case REG_MULTI_SZ
        oReg.GetMultiStringValue hDefKeyGet, strSubKeyPath, strValueName, arrValues
	arrValues=replace(arrValues,chr(34),"")				  				
       ' wscript.echo "  " & strValueName & " (REG_MULTI_SZ) ="
        For Each strValue in arrValues
       '   wscript.echo "    " & strValue 
        Next
        Return = oReg.SetMultiStringValue (hDefKeySet, strKeyPath & "\" & strSubkey & ".user." & UserName, strValueName, arrValues)
	filetxt.WriteLine("Return = oReg.SetMultiStringValue (hDefKeySet, strKeyPath & ""\" & strSubkey & ".user." & UserName & """ , """ & strValueName & """, """ & arrValues & """)")


    End Select

  Next
end if
Next



filetxt.Close 



Comments

  • I'm having some trouble with this one. I've tried copying different bits of the above script but they all seem to have errors. I'm sure it's something I'm doing wrong, but could you be more specific with what part of the above text we're supposed to use as the first .vbs script please? - AFCUjstrick 10 years ago
  • Hi

    I've tried uploading the script here:
    http://uploading.com/files/get/9db4cedf/GetUserInstall.vbs
    I hope it works, then in line 33/34 you can edit the name of the file and the path it should be located

    The hole file above is 1 file, the file then create a new one, the size of the 2nd file depend on how much is in the user's "uninstall" registry keys.

    The Kace kpkg files to directly upload is here:
    http://uploading.com/files/get/51mfe4f5/Script-478.kpkg
    http://uploading.com/files/get/42a84d1d/Script-479.kpkg
    if you prefer that =)

    - rené - rmeyer 10 years ago
  • Apologies for being difficult. That website appears to be a little bit abnormal.
    Is there any way you could place them somewhere else? Again sorry for the inconvenience. - AFCUjstrick 10 years ago
  • No worries :)

    http://wtrns.fr/gJksKbe52-S7W7

    Try that, it is on www.wetransfer.com should be simple and no dodgy content
    all is zipped in 1 file

    - rené - rmeyer 10 years ago
This post is locked

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ