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