Views
WinstScripts
>>
softinventory
last edited 1 year ago by sehlers
Qualified for opsi 3
------------------------------------------------------------
;Copyright (c) uib gmbh (www.uib.de)
;published under the Terms of the General Public License.
[Initial]
Message=Softwareinventarisierung ...
;Erstellt am 04.04.2006 von Patrick Ohler
;Veraendert 19/10/2007 Rupert Roeder
LogLevel=2
ExitOnError=false
ScriptErrorMessages=on
TraceMode=off
[Aktionen]
;Variablen fuer BetriebssystemsVersion (OS)-Test
DefVar $OS$
set $OS$ = GetOS
DefVar $NTVersion$
set $NTVersion$ = GetNTVersion
DefVar $PcName$
Set $PcName$ = GetRegistryStringValue("[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName] ComputerName")
DefVar $OpsiRegKey$
Set $OpsiRegKey$ = "HKLM\SOFTWARE\opsi.org"
DefVar $TEMP$
Set $TEMP$ = "c:\tmp"
DefVar $ServerLog$
Set $ServerLog$ = GetRegistryStringValue("["+$OpsiRegKey$+"\shareinfo] configdrive")
DefVar $LogFile$
Set $LogFile$ = $TEMP$ + "\softwareinformation.log"
DefStringList $lines$
DefStringList $splitedline$
DefVar $test$
DefVar $result$
DefStringList $collectList$
DefVar $single$
DefVar $uninstkey$
Set $uninstkey$="HKEY_LOCAL_MACHINE\software\microsoft\windows\currentversion\uninstall"
if ($OS$ = "Windows_NT" OR $OS$="Windows_95")
; for writing a fresh file, delete the old one
Files_deleteOldInventory
DosInAnIcon_printHeader
; extract the informations from the registry
DosInAnIcon_ReadRegistryKeys
DefVar $UninstallProduct$
DefVar $DisplayName$
DefVar $DisplayVersion$
DefVar $Section$
DefVar $Key$
DefVar $Splitter$
DefStringlist $reglines$
DosInAnIcon_writeHeader
Set $reglines$ = loadTextFile($TEMP$+"\inventory.reg")
for $singleline$ in $reglines$ do sub_grepProduct
DosInAnIcon_writeFooter
opsiservicecall $LogFile$
if IniVar("useCollectExe")="yes"
sub_useCollectExe
endif
; delete temporary files
Files_delete
endif
[DosInAnIcon_writeHeader]
echo "method":"setSoftwareInformation" > $LogFile$
echo "params": [ >> $LogFile$
echo "hostId": "%hostId%", >> $LogFile$
echo "info": >> $LogFile$
echo { >> $LogFile$
[DosInAnIcon_writeFooter]
echo } >> $LogFile$
echo ] >> $LogFile$
[sub_grepProduct]
set $single$ = EscapeString:$singleline$
Set $splitter$ = "[" + $uninstkey$ + "\"
Set $Key$ = takestring(1, splitstring($single$, $splitter$))
if not ($Key$ = "")
; found
Set $UninstallProduct$ = takestring(0, splitstring($Key$, "]"))
Set $Section$ = $uninstkey$ + "\" + $UninstallProduct$
Set $DisplayName$ = GetValueFromInifile ($TEMP$+"\inventory.reg",$Section$, '"DisplayName"', "")
Set $DisplayVersion$ = GetValueFromInifile ($TEMP$+"\inventory.reg",$Section$, '"DisplayVersion"', "")
DosInAnIcon_addProduct
endif
[DosInAnIcon_addProduct]
echo "$UninstallProduct$": >> $LogFile$
echo { >> $LogFile$
echo "DisplayName": "$DisplayName$", >> $LogFile$
echo "DisplayVersion": "$DisplayVersion$" >> $LogFile$
echo } >> $LogFile$
[sub_useCollectExe]
if (FileExists("%ScriptPath%\custom_ins_dir\collect.exe"))
; is there a "collect.exe" from the "application compatibility toolkit"?
; if yes start it
DosInAnIcon_startCollect
; make new section in log-file
DosInAnIcon_printCollectHeader
; extract only the name of the applications
set $collectList$ = getReturnListFromSection ('XMLPatch_findProducts '+$TEMP$+'\'+$PCName$+'.xml')
for $collectLine$ in $collectList$ do Sub_grepName
endif
[Files_deleteOldInventory]
delete $LogFile$
[DosInAnIcon_printHeader]
echo --------------------------------------------------- >> $LogFile$
echo Time of the last inventory of $PcName$ >> $LogFile$
date /T >> $LogFile$
time /T >> $LogFile$
echo --------------------------------------------------- >> $LogFile$
echo. >> $LogFile$
[DosInAnIcon_printCollectHeader]
echo. >> $LogFile$
echo. >> $LogFile$
echo --------------------------------------------------- >> $LogFile$
echo here it comes the inventory found by collect.exe >> $LogFile$
echo --------------------------------------------------- >> $LogFile$
echo. >> $LogFile$
[DosInAnIcon_ReadRegistryKeys]
regedit.exe /a $TEMP$\inventory.reg "$uninstkey$"
[Sub_grep]
set $single$ = EscapeString:$singleline$
set $splitedline$ = splitstring($single$, "=")
set $test$ = takestring(0,$splitedline$)
if ($test$ = '"DisplayName"')
set $result$ = takeString(1,$splitedline$)
DosInAnIcon_write
endif
[Sub_grepName]
set $single$ = EscapeString:$collectLine$
set $splitedline$ = splitstring($single$, '"')
set $result$ = takestring(1,$splitedline$)
DosInAnIcon_write
[DosInAnIcon_write]
echo $result$ >> $LogFile$
[Files_delete]
delete $TEMP$\inventory.reg
delete $TEMP$\$PcName$.xml
[DosInAnIcon_startCollect]
%ScriptPath%\custom_ins_dir\collect.exe /x /o $TEMP$ /f $PcName$.xml
[XMLPatch_findProducts]
openNodeSet
documentroot
all_childelements_with:
elementname:"SoftwareList"
all_childelements_with:
elementname:"Application"
end
return elements