**DONOTDELETE**
(Lurker)
2015-10-30 12:21 PM
Windows 7 script - Error failed to find/open script [Log.kix]

Hi guys, hope someone can help. I have created a Log.kix script which calls 2 other scripts within it but when I run the first Log.kix script I get an Error failed to find/open script [Log.kix]

I'm running the script on a local Windows 7 Enterprise PC, the scripts are stored on C:\Netlogon\ the folder also contains the kix32.exe

I'm running the script from the command prompt by typing C:\Netlogon\KIX32.EXE Log.KIX

I have posted the 3 three scripts I have, the log.kix calls the software_inventory.kix and to write PC software information to a .csv file

Please can someone assist? My first problem is the error I'm getting above when trying to run the script (log.kix) on a local PC to test, from command prompt.

Log.kix
 Code:
[color:#333399];******************************************
;*** Initialise Global script variables ***

CALL @LDRIVE+"C:\Netlogon\UDF_Global.kix"
$UpdatesScripts_Loc = "C:\Netlogon\"
$LogonLogs = "C:\Netlogon\Software_Inventory\"

;*** End Initialise Global script variables ***
;**********************************************

	IF @ProductType="Windows NT Workstation" OR @ProductType="Windows 2000 Professional" OR @ProductType="Windows XP Professional" OR @ProductType="Windows XP Professional Tablet PC" OR @ProductType="Windows 7 Enterprise"
		CALL $UpdatesScripts_Loc+"Software_Inventory.kix"
	ENDIF

;	*** End Write Logon info	                       				     		***
;	***************************************************************************************************
[/color]

Software_Inventory.kix
[color:#3333FF]; ========================================================================

$uninstallkey="HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\"
$PackageList=Chr(34)+"PC"+Chr(34)+","+CHR(34)+"Software_Name"+CHR(34)+","+CHR(34)+"Software_Version"+Chr(34)+","+Chr(34)+"Software_Publisher"+Chr(34)

$Index=0
:PackageLoop
$package=ENUMKEY($uninstallkey, $Index)
If @ERROR = 0
	$SoftwareName=READVALUE($uninstallkey+$package,"Displayname")
	If $SoftwareName<>""
		If InStr($SoftwareName,"Security Update For")=0 AND InStr($SoftwareName,"Update for Windows XP")=0 AND InStr($SoftwareName,"Windows XP Hotfix")=0 AND InStr($SoftwareName,"Hotfix for Windows XP")=0 AND InStr($SoftwareName,"Windows 2000 Hotfix")=0
			$SoftwareVersion="N/A"
			$SoftwareVersion=READVALUE($uninstallkey+$package,"DisplayVersion")
			If $SoftwareVersion=""
				$SoftwareVersion="N/A"
			EndIf
			$Publisher="N/A"
			$Publisher=READVALUE($uninstallkey+$package,"Publisher")
			If $Publisher=""
				$Publisher="N/A"
			EndIf
			$PackageList = $PackageList + @CRLF +CHR(34)+ @WKSTA +CHR(34)+ "," +CHR(34)+ $SoftwareName +CHR(34)+ "," +CHR(34)+ $SoftwareVersion+CHR(34)+","+Chr(34)+$Publisher+Chr(34)
		ENDIF
	EndIf
	$Index=$Index+1
	Goto PackageLoop
EndIf

LogtoFile("ForceOverwrite",$LogonLogs+"Software_Inventory\"+@WKSTA+".csv",$PackageList)[/color]

UDF_Global.kix
[color:#6633FF];*** Global Variables ***

$GlobalScripts_Loc = @LDRIVE+"C:\Netlogon\"

;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
;FUNCTION      ChkRegSec
;ACTION        Checks if the user can write to the specified registry key
;SYNTAX        ChkRegSec(RegistryKey)
;PARAMETERS    RegistryKey
;                Registry key to check for write access (in form HKLM\Key\Subkey or HKCU\Key\Subkey)
;RETURNS       0 if write permission OK, error code if failed
;EXAMPLE       IF ChkRegSec("HKLM\Software\MiltonKeynesCouncil")<>0 ? "No permission to write to registry" ENDIF
;
  FUNCTION ChkRegSec( $RegKey )
	DIM $regsectest
	$ChkRegSec = 0
	$regsectest = WriteValue($RegKey, "MKCTESTSEC", "Passed", "REG_SZ")
	If $regsectest <> 0
		Shell $GlobalScripts_Loc+"regseclog.bat "+@USERID+" "+@WKSTA+" "+@TIME+" "+@DATE+" "+@LSERVER+" "+$RegKey
		$ChkRegSec = $regsectest
	EndIf
  EndFunction
;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
;FUNCTION		ChkPerms
;ACTION			Checks if the user can write to the specified registry key
;AUTHOR			Jeremy Smedley
;VERSION		1.00
;KIXTART		4.21
;DATE CREATED	2006/03/21
;SYNTAX			ChkPerms(Type, Location)
;PARAMETERS		Type
;				Registry or Folder
;				Location
;               Folder or Registry key to check for write access (in form HKLM\Key\Subkey or HKCU\Key\Subkey, or Drive:\folder)
;RETURNS		0 if write + delete permission OK, 1 if no write permission, 2 if no delete permission
;EXAMPLE		IF ChkPerms("Registry","HKLM\Software\MiltonKeynesCouncil")=1 ? "No permission to write to registry" ENDIF
;
  Function ChkPerms( $chkpermstype, $chkpermsLocation )
	DIM $chkpermstest, $chkpermstest2, $chkpermstatus
	Select
		Case $chkpermstype="Registry"
			$chkpermstest = WriteValue($chkpermsLocation, "MKCTESTSEC", "Passed", "REG_SZ")
			$chkpermstest2 = ReadValue($chkpermsLocation, "MKCTESTSEC")
			If $chkpermstest2 = "Passed"
				$chkpermstest = DelValue($chkpermsLocation, "MKCTESTSEC")
				If $chkpermstest = 0
					$chkpermstatus = 0
				Else
					$chkpermstatus = 2
				EndIf
			Else
				$chkpermstatus = 1
			EndIf
			$ChkPerms = $chkpermstatus
		Case $chkpermstype="Folder"
			Copy @LDRIVE+"C:\Logons\securitytest.txt" $chkpermsLocation+"\securitytest.txt"
			If Exist($chkpermsLocation+"\securitytest.txt")
				Del $chkpermsLocation+"\securitytest.txt"
				If Exist($chkpermsLocation+"\securitytest.txt")
					$chkpermstatus = 2
				Else
					$chkpermstatus = 0
				EndIf
			Else
				$chkpermstatus = 1
			EndIf
			$ChkPerms = $chkpermstatus
		Case 1
			$ChkPerms = 50
	EndSelect
  EndFunction
;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
;FUNCTION		LogtoFile
;ACTION			Writes data to log file
;AUTHOR			Jeremy Smedley
;VERSION		1.00
;KIXTART		4.21
;DATE CREATED	2006/03/21
;SYNTAX			LogtoFile(Function, Location, Data)
;PARAMETERS		Function
;				Append or Overwrite
;				Location
;               File to write to
;				Data
;				Required contents of file
;RETURNS		N/A
;EXAMPLE		LogtoFile("Append",$LogonLogs+"byuser\user1","Testing User1 logging")
;
  Function LogtoFile( $LogtoFile_Fn, $LogtoFile_Loc, $LogtoFile_Data )
	$LogtoFile_x = FreeFileHandle()
	IF $LogtoFile_x >0
		Select
			Case $LogtoFile_Fn = "Append"
				IF Open( $LogtoFile_x , $LogtoFile_Loc , 5 ) = 0
					$LogtoFile_y = WriteLine( 1 , $LogtoFile_Data + @CRLF )
					$LogtoFile_y = Close($LogtoFile_x)
				ENDIF
			Case $LogtoFile_Fn = "ForceOverwrite"
				IF EXIST ($LogtoFile_Loc)
					DEL $LogtoFile_Loc
				ENDIF
				IF Open( $LogtoFile_x , $LogtoFile_Loc , 5 ) = 0
					$LogtoFile_y = WriteLine( 1 , $LogtoFile_Data + @CRLF )
					$LogtoFile_y = Close($LogtoFile_x)
				ENDIF
			Case $LogtoFile_Fn = "Overwrite"
				RUN "CMD.exe /C ECHO "+$LogtoFile_Data+">"+"$LogtoFile_Loc"
			Case 1
				RUN "CMD.exe /C ECHO "+$LogtoFile_Data+">>"+"$LogtoFile_Loc"
		EndSelect
	EndIf
  EndFunction
;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$[/color]


Mart
(KiX Supporter)
2015-10-30 01:37 PM
Re: Windows 7 script - Error failed to find/open script [Log.kix]

 Quote:

I'm running the script from the command prompt by typing C:\Netlogon\KIX32.EXE Log.KIX


What happens if you include the full path to the script?

Like:
 Quote:

C:\Netlogon\KIX32.EXE c:\netlogon\Log.KIX


**DONOTDELETE**
(Lurker)
2015-10-30 01:39 PM
Re: Windows 7 script - Error failed to find/open script [Log.kix]

Update I think the script command I was using wrong. I changed directory to get to the Netlogon folder and then ran different script and this worked (c:\Netlogon>C:\Netlogon\KIX32.EXE network.KIX).

So now I run the log.kix and it looks like it runs but no software information on the PC is written to a .csv file. Please can some help with my log.kix file to see if the code needs changing?

Thanks


LonkeroAdministrator
(KiX Master Guru)
2015-10-31 02:07 AM
Re: Windows 7 script - Error failed to find/open script [Log.kix]

You are writing to:
C:\Netlogon\Software_Inventory\Software_Inventory\wksta.csv

Maybe the path is just wrong?


**DONOTDELETE**
(Lurker)
2015-11-02 12:17 PM
Re: Windows 7 script - Error failed to find/open script [Log.kix]

I'm writing to C:\Netlogon\Software_Inventory\

I now appear to be getting error: unknown command [logtofile]! when running software_inventory.kix

Not sure why?


**DONOTDELETE**
(Lurker)
2015-11-02 04:57 PM
Re: Windows 7 script - Error failed to find/open script [Log.kix]

Ok getting a bit further, my script now seems to be running but nothing no .csv file is being created within C:\Netlogon\Software_Inventory. Below is my code.

First script which then calls software_inventory.kix and also my UDF_global.kix

If anyone can assist. Thanks

Log.kix
 Code:
;	***************************************************************************************************
;	*** Write logon info to $LogonLogs Keep Last Item!						***

;******************************************
;*** Initialise Global script variables ***

CALL "C:\Netlogon\UDF_Global.kix"
$UpdatesScripts_Loc = "\\hbs002592\c$\Netlogon\"
$LogonLogs = "\\hbs002592\c$\Netlogon\Software_Inventory\"

;*** End Initialise Global script variables ***
;**********************************************

	IF @ProductType="Windows NT Workstation" OR @ProductType="Windows 2000 Professional" OR @ProductType="Windows XP Professional" OR @ProductType="Windows XP Professional Tablet PC" OR @ProductType="Windows 7 Enterprise Edition (N)"
		CALL $UpdatesScripts_Loc+"Software_Inventory.kix"
	ENDIF

;	*** End Write Logon info	                       				     		***
;	***************************************************************************************************
RETURN



Software_Inventory.kix
; ========================================================================

CALL "\\hbs002592\c$\Netlogon\UDF_Global.kix"
$UpdatesScripts_Loc = "\\hbs002592\c$\Netlogon\"
$LogonLogs = "\\hbs002592\c$\Netlogon\Software_Inventory\"

$uninstallkey="HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\"
$PackageList=Chr(34)+"PC"+Chr(34)+","+CHR(34)+"Software_Name"+CHR(34)+","+CHR(34)+"Software_Version"+Chr(34)+","+Chr(34)+"Software_Publisher"+Chr(34)

$Index=0
:PackageLoop
$package=ENUMKEY($uninstallkey, $Index)
If @ERROR = 0
	$SoftwareName=READVALUE($uninstallkey+$package,"Displayname")
	If $SoftwareName<>""
		If InStr($SoftwareName,"Security Update For")=0 AND InStr($SoftwareName,"Update for Windows 7")=0 AND InStr($SoftwareName,"Windows 7 Hotfix")=0 AND InStr($SoftwareName,"Hotfix for Windows 7")=0 AND InStr($SoftwareName,"Windows 7 Hotfix")=0
			$SoftwareVersion="N/A"
			$SoftwareVersion=READVALUE($uninstallkey+$package,"DisplayVersion")
			If $SoftwareVersion=""
				$SoftwareVersion="N/A"
			EndIf
			$Publisher="N/A"
			$Publisher=READVALUE($uninstallkey+$package,"Publisher")
			If $Publisher=""
				$Publisher="N/A"
			EndIf
			$PackageList = $PackageList + @CRLF +CHR(34)+ @WKSTA +CHR(34)+ "," +CHR(34)+ $SoftwareName +CHR(34)+ "," +CHR(34)+ $SoftwareVersion+CHR(34)+","+Chr(34)+$Publisher+Chr(34)
		ENDIF
	EndIf
	$Index=$Index+1
	Goto PackageLoop
EndIf

LogtoFile("ForceOverwrite",$LogonLogs+"Software_Inventory\"+@WKSTA+".csv",$PackageList)


UDF_global.kix
;*** Global Variables ***

$GlobalScripts_Loc = @LDRIVE+"\updates\"

;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
;FUNCTION      ChkRegSec
;ACTION        Checks if the user can write to the specified registry key
;AUTHOR        Jeremy Smedley
;VERSION       1.00
;KIXTART       4.21
;DATE CREATED  2003/08/14
;SYNTAX        ChkRegSec(RegistryKey)
;PARAMETERS    RegistryKey
;                Registry key to check for write access (in form HKLM\Key\Subkey or HKCU\Key\Subkey)
;RETURNS       0 if write permission OK, error code if failed
;EXAMPLE       IF ChkRegSec("HKLM\Software\MiltonKeynesCouncil")<>0 ? "No permission to write to registry" ENDIF
;
  FUNCTION ChkRegSec( $RegKey )
	DIM $regsectest
	$ChkRegSec = 0
	$regsectest = WriteValue($RegKey, "MKCTESTSEC", "Passed", "REG_SZ")
	If $regsectest <> 0
		Shell $GlobalScripts_Loc+"regseclog.bat "+@USERID+" "+@WKSTA+" "+@TIME+" "+@DATE+" "+@LSERVER+" "+$RegKey
		$ChkRegSec = $regsectest
	EndIf
  EndFunction
;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
;FUNCTION		ChkPerms
;ACTION			Checks if the user can write to the specified registry key
;AUTHOR			Jeremy Smedley
;VERSION		1.00
;KIXTART		4.21
;DATE CREATED	2006/03/21
;SYNTAX			ChkPerms(Type, Location)
;PARAMETERS		Type
;				Registry or Folder
;				Location
;               Folder or Registry key to check for write access (in form HKLM\Key\Subkey or HKCU\Key\Subkey, or Drive:\folder)
;RETURNS		0 if write + delete permission OK, 1 if no write permission, 2 if no delete permission
;EXAMPLE		IF ChkPerms("Registry","HKLM\Software\MiltonKeynesCouncil")=1 ? "No permission to write to registry" ENDIF
;
  Function ChkPerms( $chkpermstype, $chkpermsLocation )
	DIM $chkpermstest, $chkpermstest2, $chkpermstatus
	Select
		Case $chkpermstype="Registry"
			$chkpermstest = WriteValue($chkpermsLocation, "MKCTESTSEC", "Passed", "REG_SZ")
			$chkpermstest2 = ReadValue($chkpermsLocation, "MKCTESTSEC")
			If $chkpermstest2 = "Passed"
				$chkpermstest = DelValue($chkpermsLocation, "MKCTESTSEC")
				If $chkpermstest = 0
					$chkpermstatus = 0
				Else
					$chkpermstatus = 2
				EndIf
			Else
				$chkpermstatus = 1
			EndIf
			$ChkPerms = $chkpermstatus
		Case $chkpermstype="Folder"
			Copy @LDRIVE+"\updates\securitytest.txt" $chkpermsLocation+"\securitytest.txt"
			If Exist($chkpermsLocation+"\securitytest.txt")
				Del $chkpermsLocation+"\securitytest.txt"
				If Exist($chkpermsLocation+"\securitytest.txt")
					$chkpermstatus = 2
				Else
					$chkpermstatus = 0
				EndIf
			Else
				$chkpermstatus = 1
			EndIf
			$ChkPerms = $chkpermstatus
		Case 1
			$ChkPerms = 50
	EndSelect
  EndFunction
;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
;FUNCTION		LogtoFile
;ACTION			Writes data to log file
;AUTHOR			Jeremy Smedley
;VERSION		1.00
;KIXTART		4.21
;DATE CREATED	2006/03/21
;SYNTAX			LogtoFile(Function, Location, Data)
;PARAMETERS		Function
;				Append or Overwrite
;				Location
;               File to write to
;				Data
;				Required contents of file
;RETURNS		N/A
;EXAMPLE		LogtoFile("Append",$LogonLogs+"byuser\user1","Testing User1 logging")
;
  Function LogtoFile( $LogtoFile_Fn, $LogtoFile_Loc, $LogtoFile_Data )
	$LogtoFile_x = FreeFileHandle()
	IF $LogtoFile_x >0
		Select
			Case $LogtoFile_Fn = "Append"
				IF Open( $LogtoFile_x , $LogtoFile_Loc , 5 ) = 0
					$LogtoFile_y = WriteLine( 1 , $LogtoFile_Data + @CRLF )
					$LogtoFile_y = Close($LogtoFile_x)
				ENDIF
			Case $LogtoFile_Fn = "ForceOverwrite"
				IF EXIST ($LogtoFile_Loc)
					DEL $LogtoFile_Loc
				ENDIF
				IF Open( $LogtoFile_x , $LogtoFile_Loc , 5 ) = 0
					$LogtoFile_y = WriteLine( 1 , $LogtoFile_Data + @CRLF )
					$LogtoFile_y = Close($LogtoFile_x)
				ENDIF
			Case $LogtoFile_Fn = "Overwrite"
				RUN "CMD.exe /C ECHO "+$LogtoFile_Data+">"+"$LogtoFile_Loc"
			Case 1
				RUN "CMD.exe /C ECHO "+$LogtoFile_Data+">>"+"$LogtoFile_Loc"
		EndSelect
	EndIf
  EndFunction



Mart
(KiX Supporter)
2015-11-02 05:11 PM
Re: Windows 7 script - Error failed to find/open script [Log.kix]

Ok, first of all you are writing to the path Lonkero suggested.

You use LogtoFile("ForceOverwrite",$LogonLogs+"Software_Inventory\"+@WKSTA+".csv",$PackageList) as the command to write the data to the log file. The variable $logonLogs is set to "\\hbs002592\c$\Netlogon\Software_Inventory\" and you add +"Software_Inventory\"+@WKSTA+".csv" to that.

What error codes do you get just after you try to write to the log file? I usually display @error and @serror in these cases to find out what is causing this.

Regular users cannot access \\systemname\c$ so unless the user is an admin on the target system or custom permissions have been set this will not work.


**DONOTDELETE**
(Lurker)
2015-11-03 11:42 AM
Re: Windows 7 script - Error failed to find/open script [Log.kix]

Brilliant thanks guys you were both correct about the path $logonLogs is set to "\\hbs002592\c$\Netlogon\Software_Inventory which I amended to $logonLogs is set to "\\hbs002592\c$\Netlogon\ now it's working and creating the .csv file with the info on software.

One thing though the script is not picking up windows 7 enterprise security updates, hotfixes and .net updates. Below is the code I have but it's not working, any ideas? Thanks

---------------------
 Code:
CALL "\\hbs002592\c$\Netlogon\UDF_Global.kix"
$UpdatesScripts_Loc = "\\hbs002592\c$\Netlogon\"
$LogonLogs = "\\hbs002592\c$\Netlogon\"

$uninstallkey="HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\"
$PackageList=Chr(34)+"PC"+Chr(34)+","+CHR(34)+"Software_Name"+CHR(34)+","+CHR(34)+"Software_Version"+Chr(34)+","+Chr(34)+"Software_Publisher"+Chr(34)

$Index=0
:PackageLoop
$package=ENUMKEY($uninstallkey, $Index)
If @ERROR = 0
	$SoftwareName=READVALUE($uninstallkey+$package,"Displayname")
	If $SoftwareName<>""
		If InStr($SoftwareName,"Security Update For")=0 AND InStr($SoftwareName,"Update for Windows 7 Enterprise")=0 AND InStr($SoftwareName,"Windows 7 Enterprise Hotfix")=0 AND InStr($SoftwareName,"Hotfix for Windows 7 Enterprise")=0 AND InStr($SoftwareName,"Windows 7 Enterprise Hotfix")=0
			$SoftwareVersion="N/A"
			$SoftwareVersion=READVALUE($uninstallkey+$package,"DisplayVersion")
			If $SoftwareVersion=""
				$SoftwareVersion="N/A"
			EndIf
			$Publisher="N/A"
			$Publisher=READVALUE($uninstallkey+$package,"Publisher")
			If $Publisher=""
				$Publisher="N/A"
			EndIf
			$PackageList = $PackageList + @CRLF +CHR(34)+ @WKSTA +CHR(34)+ "," +CHR(34)+ $SoftwareName +CHR(34)+ "," +CHR(34)+ $SoftwareVersion+CHR(34)+","+Chr(34)+$Publisher+Chr(34)
		ENDIF
	EndIf
	$Index=$Index+1
	Goto PackageLoop
EndIf

LogtoFile("ForceOverwrite",$LogonLogs+"Software_Inventory\"+@WKSTA+".csv",$PackageList)

-------------------------------


Glenn BarnasAdministrator
(KiX Supporter)
2015-11-03 01:05 PM
Re: Windows 7 script - Error failed to find/open script [Log.kix]

User1234 - Please use code tags around your code - it's difficult to read without them. Use the Code button if you're using the full screen editor, or simply place
 Code:
[CODE] and [\CODE]
around your code. Note that you need a forward slash - /CODE, but I can't display that here.

Also - GOTO has been long deprecated, despite the simple examples in the user manual. Using While/Loop is recommended, something like:
 Code:
$package=ENUMKEY($uninstallkey, $Index)  ; get the FIRST index value
While Not @ERROR
  do stuff...
  $Index = $Index + 1
  $package=ENUMKEY($uninstallkey, $Index)  ; must do this at the end also to get the NEXT index value
Loop
Basically, you get the loop control value before entering the loop, do stuff in the loop, and then repeat the line of code to get the control value again just before the loop ends. In this case, the ERROR macro is set before entering the loop, and again at the end, just prior to the loop starting again. When ERROR is set, the loop is not run and the process continues after the Loop statement.

Glenn


**DONOTDELETE**
(Lurker)
2015-11-03 03:12 PM
Re: Windows 7 script - Error failed to find/open script [Log.kix]

Thanks Glenn but I'm quite new to kix scripting, are you able to show me how I can fit this into my code? Thanks

 Code:
CALL "\\hbs002592\c$\Netlogon\UDF_Global.kix"
$UpdatesScripts_Loc = "\\hbs002592\c$\Netlogon\"
$LogonLogs = "\\hbs002592\c$\Netlogon\"

$uninstallkey="HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\"
$PackageList=Chr(34)+"PC"+Chr(34)+","+CHR(34)+"Software_Name"+CHR(34)+","+CHR(34)+"Software_Version"+Chr(34)+","+Chr(34)+"Software_Publisher"+Chr(34)

$Index=0
:PackageLoop
$package=ENUMKEY($uninstallkey, $Index)
If @ERROR = 0
	$SoftwareName=READVALUE($uninstallkey+$package,"Displayname")
	If $SoftwareName<>""
		If InStr($SoftwareName,"Security Update For")=0 
			$SoftwareVersion="N/A"
			$SoftwareVersion=READVALUE($uninstallkey+$package,"DisplayVersion")
			If $SoftwareVersion=""
				$SoftwareVersion="N/A"
			EndIf
			$Publisher="N/A"
			$Publisher=READVALUE($uninstallkey+$package,"Publisher")
			If $Publisher=""
				$Publisher="N/A"
			EndIf
			$PackageList = $PackageList + @CRLF +CHR(34)+ @WKSTA +CHR(34)+ "," +CHR(34)+ $SoftwareName +CHR(34)+ "," +CHR(34)+ $SoftwareVersion+CHR(34)+","+Chr(34)+$Publisher+Chr(34)
		ENDIF
	EndIf
	$Index=$Index+1
	Goto PackageLoop
EndIf

LogtoFile("ForceOverwrite",$LogonLogs+"Software_Inventory\"+@WKSTA+".csv",$PackageList)


**DONOTDELETE**
(Lurker)
2015-11-03 03:30 PM
Re: Windows 7 script - Error failed to find/open script [Log.kix]

I tried to put what you said into my code but when I run it I get Error : ENDIF without IF! Line 36

Not sure if I have put this in correctly?

 Code:
[color:#330099]CALL "\\hbs002592\c$\Netlogon\UDF_Global.kix"
$UpdatesScripts_Loc = "\\hbs002592\c$\Netlogon\"
$LogonLogs = "\\hbs002592\c$\Netlogon\"

$uninstallkey="HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\"
$PackageList=Chr(34)+"PC"+Chr(34)+","+CHR(34)+"Software_Name"+CHR(34)+","+CHR(34)+"Software_Version"+Chr(34)+","+Chr(34)+"Software_Publisher"+Chr(34)

$Index=0
:PackageLoop
$package=ENUMKEY($uninstallkey, $Index)
While Not @ERROR = 0
	$SoftwareName=READVALUE($uninstallkey+$package,"Displayname")
	If $SoftwareName<>""
		If InStr($SoftwareName,"Security Update For")=0 AND InStr($SoftwareName,"Update for Windows XP")=0 AND InStr($SoftwareName,"Windows XP Hotfix")=0 AND InStr($SoftwareName,"Hotfix for Windows XP")=0 AND InStr($SoftwareName,"Windows 2000 Hotfix")=0 AND InStr($SoftwareName,"Update for Windows 7")=0 AND InStr($SoftwareName,"Windows 7 Hotfix")=0 AND InStr($SoftwareName,"Hotfix for Windows 7")=0
			$SoftwareVersion="N/A"
			$SoftwareVersion=READVALUE($uninstallkey+$package,"DisplayVersion")
			If $SoftwareVersion=""
				$SoftwareVersion="N/A"
			EndIf
			$Publisher="N/A"
			$Publisher=READVALUE($uninstallkey+$package,"Publisher")
			If $Publisher=""
				$Publisher="N/A"
			EndIf
			$PackageList = $PackageList + @CRLF +CHR(34)+ @WKSTA +CHR(34)+ "," +CHR(34)+ $SoftwareName +CHR(34)+ "," +CHR(34)+ $SoftwareVersion+CHR(34)+","+Chr(34)+$Publisher+Chr(34)
		ENDIF
	EndIf
	$Index=$Index+1
	$package=ENUMKEY($uninstallkey, $Index)
	Loop
EndIf

LogtoFile("ForceOverwrite",$LogonLogs+"Software_Inventory\"+@WKSTA+".csv",$PackageList)[/color]


Henriques
(Fresh Scripter)
2015-11-03 04:38 PM
Re: Windows 7 script - Error failed to find/open script [Log.kix]

Try changing the Loop statement with the last Endif.

Mart
(KiX Supporter)
2015-11-03 04:40 PM
Re: Windows 7 script - Error failed to find/open script [Log.kix]

The extra EndIf directly after the Loop might be breaking things. If I counted correctly it is not needed anymore. Every If can optionally have one Else but absolutely needs one Endif. Also you use While Not @ERROR = 0. It would be better to use While Not @ERROR or While @ERROR = 0 or While @ERROR <> 0 depending on when you want the code to be executed or not.

**DONOTDELETE**
(Lurker)
2015-11-03 04:44 PM
Re: Windows 7 script - Error failed to find/open script [Log.kix]

Just tried that (see code below) the csv gets created but doesn't data in it, the csv is blank.

 Code:
CALL "\\hbs002592\c$\Netlogon\UDF_Global.kix"
$UpdatesScripts_Loc = "\\hbs002592\c$\Netlogon\"
$LogonLogs = "\\hbs002592\c$\Netlogon\"

$uninstallkey="HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\"
$PackageList=Chr(34)+"PC"+Chr(34)+","+CHR(34)+"Software_Name"+CHR(34)+","+CHR(34)+"Software_Version"+Chr(34)+","+Chr(34)+"Software_Publisher"+Chr(34)

$Index=0
:PackageLoop
$package=ENUMKEY($uninstallkey, $Index)
While Not @ERROR = 0
	$SoftwareName=READVALUE($uninstallkey+$package,"Displayname")
	If $SoftwareName<>""
		If InStr($SoftwareName,"Security Update For")=0 AND InStr($SoftwareName,"Update for Windows XP")=0 AND InStr($SoftwareName,"Windows XP Hotfix")=0 AND InStr($SoftwareName,"Hotfix for Windows XP")=0 AND InStr($SoftwareName,"Windows 2000 Hotfix")=0 AND InStr($SoftwareName,"Update for Windows 7")=0 AND InStr($SoftwareName,"Windows 7 Hotfix")=0 AND InStr($SoftwareName,"Hotfix for Windows 7")=0
			$SoftwareVersion="N/A"
			$SoftwareVersion=READVALUE($uninstallkey+$package,"DisplayVersion")
			If $SoftwareVersion=""
				$SoftwareVersion="N/A"
			EndIf
			$Publisher="N/A"
			$Publisher=READVALUE($uninstallkey+$package,"Publisher")
			If $Publisher=""
				$Publisher="N/A"
			EndIf
			$PackageList = $PackageList + @CRLF +CHR(34)+ @WKSTA +CHR(34)+ "," +CHR(34)+ $SoftwareName +CHR(34)+ "," +CHR(34)+ $SoftwareVersion+CHR(34)+","+Chr(34)+$Publisher+Chr(34)
		ENDIF
	EndIf
	$Index=$Index+1
	$package=ENUMKEY($uninstallkey, $Index)
	EndIf
Loop

LogtoFile("ForceOverwrite",$LogonLogs+"Software_Inventory\"+@WKSTA+".csv",$PackageList)


**DONOTDELETE**
(Lurker)
2015-11-03 04:53 PM
Re: Windows 7 script - Error failed to find/open script [Log.kix]

Ok Mart thanks. Below is what I have now after your last comment. When running it now write software info to csv but still not information on windows 7 updates, hotfixes and .net updates.

How does the code look now to you?

 Code:
CALL "\\hbs002592\c$\Netlogon\UDF_Global.kix"
$UpdatesScripts_Loc = "\\hbs002592\c$\Netlogon\"
$LogonLogs = "\\hbs002592\c$\Netlogon\"

$uninstallkey="HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\"
$PackageList=Chr(34)+"PC"+Chr(34)+","+CHR(34)+"Software_Name"+CHR(34)+","+CHR(34)+"Software_Version"+Chr(34)+","+Chr(34)+"Software_Publisher"+Chr(34)

$Index=0
:PackageLoop
$package=ENUMKEY($uninstallkey, $Index)
While Not @ERROR
	$SoftwareName=READVALUE($uninstallkey+$package,"Displayname")
	If $SoftwareName<>""
		If InStr($SoftwareName,"Security Update For")=0 AND InStr($SoftwareName,"Update for Windows XP")=0 AND InStr($SoftwareName,"Windows XP Hotfix")=0 AND InStr($SoftwareName,"Hotfix for Windows XP")=0 AND InStr($SoftwareName,"Windows 2000 Hotfix")=0 AND InStr($SoftwareName,"Update for Windows 7")=0 AND InStr($SoftwareName,"Windows 7 Hotfix")=0 AND InStr($SoftwareName,"Hotfix for Windows 7")=0
			$SoftwareVersion="N/A"
			$SoftwareVersion=READVALUE($uninstallkey+$package,"DisplayVersion")
			If $SoftwareVersion=""
				$SoftwareVersion="N/A"
			EndIf
			$Publisher="N/A"
			$Publisher=READVALUE($uninstallkey+$package,"Publisher")
			If $Publisher=""
				$Publisher="N/A"
			EndIf
			$PackageList = $PackageList + @CRLF +CHR(34)+ @WKSTA +CHR(34)+ "," +CHR(34)+ $SoftwareName +CHR(34)+ "," +CHR(34)+ $SoftwareVersion+CHR(34)+","+Chr(34)+$Publisher+Chr(34)
		ENDIF
	EndIf
	$Index=$Index+1
	$package=ENUMKEY($uninstallkey, $Index)
	Loop

LogtoFile("ForceOverwrite",$LogonLogs+"Software_Inventory\"+@WKSTA+".csv",$PackageList)


Mart
(KiX Supporter)
2015-11-03 04:58 PM
Re: Windows 7 script - Error failed to find/open script [Log.kix]

The code looks ok. You could take out the :PackageLoop label as it is not used anymore. For the missing updates, do they have a value in the registry for the DisplayName? If they don’t then they will never end up in the logfile because you only write data to the file if there is a displayname.

Software inventory is always a pesky thing. I tried several apps and script and none of them showed all installed products, updates, hotfixes, etc...


**DONOTDELETE**
(Lurker)
2015-11-03 05:22 PM
Re: Windows 7 script - Error failed to find/open script [Log.kix]

Thanks Mart

I found that Winows 7 updates are now stored in the registry under,

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages

But how could I include the script to read this info as well. Current script is what I have below.

 Code:
CALL "\\hbs002592\c$\Netlogon\UDF_Global.kix"
$UpdatesScripts_Loc = "\\hbs002592\c$\Netlogon\"
$LogonLogs = "\\hbs002592\c$\Netlogon\"

$uninstallkey="HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\"
$PackageList=Chr(34)+"PC"+Chr(34)+","+CHR(34)+"Software_Name"+CHR(34)+","+CHR(34)+"Software_Version"+Chr(34)+","+Chr(34)+"Software_Publisher"+Chr(34)

$Index=0
$package=ENUMKEY($uninstallkey, $Index)
While Not @ERROR
	$SoftwareName=READVALUE($uninstallkey+$package,"Displayname")
	If $SoftwareName<>""
		If InStr($SoftwareName,"Security Update For")=0 AND InStr($SoftwareName,"Update for Windows XP")=0 AND InStr($SoftwareName,"Windows XP Hotfix")=0 AND InStr($SoftwareName,"Hotfix for Windows XP")=0 AND InStr($SoftwareName,"Windows 2000 Hotfix")=0 AND InStr($SoftwareName,"Update for Windows 7")=0 AND InStr($SoftwareName,"Windows 7 Hotfix")=0 AND InStr($SoftwareName,"Hotfix for Windows 7")=0
			$SoftwareVersion="N/A"
			$SoftwareVersion=READVALUE($uninstallkey+$package,"DisplayVersion")
			If $SoftwareVersion=""
				$SoftwareVersion="N/A"
			EndIf
			$Publisher="N/A"
			$Publisher=READVALUE($uninstallkey+$package,"Publisher")
			If $Publisher=""
				$Publisher="N/A"
			EndIf
			$PackageList = $PackageList + @CRLF +CHR(34)+ @WKSTA +CHR(34)+ "," +CHR(34)+ $SoftwareName +CHR(34)+ "," +CHR(34)+ $SoftwareVersion+CHR(34)+","+Chr(34)+$Publisher+Chr(34)
		ENDIF
	EndIf
	$Index=$Index+1
	$package=ENUMKEY($uninstallkey, $Index)
	Loop

LogtoFile("ForceOverwrite",$LogonLogs+"Software_Inventory\"+@WKSTA+".csv",$PackageList)


Mart
(KiX Supporter)
2015-11-04 09:24 AM
Re: Windows 7 script - Error failed to find/open script [Log.kix]

You could simple enumerate the extra registry key and loop through all found keys just like you do already with the first registry key. A simple copy, paste would do the trick as long as you change the registry key in the code you copy and paste so it takes the other registry key.
Doing a simple copy and paste might not be the cleanest way but if you are new to kix it certainly is the easiest way. I also made a few small changes to keep everything readable (break the long lines into several lines) and used a shortcut to get to the registry key (HKLM instead of HKEY_LOCAL_MACHINE).

Something like (untested):
 Code:
Call "\\hbs002592\c$\Netlogon\UDF_Global.kix"
$UpdatesScripts_Loc = "\\hbs002592\c$\Netlogon\"
$LogonLogs = "\\hbs002592\c$\Netlogon\"


;Enumerate keys in HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\
$uninstallkey = "HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\"
$PackageList = Chr(34) + "PC" + Chr(34) + "," + Chr(34) + "Software_Name" + Chr(34) + "," + Chr(34) + "Software_Version" + Chr(34) + "," + Chr(34) + "Software_Publisher" + Chr(34)

$Index = 0
$package = EnumKey($uninstallkey, $Index)
While Not @ERROR
	$SoftwareName = ReadValue($uninstallkey + $package, "Displayname")
	If $SoftwareName <> ""
		If InStr($SoftwareName, "Security Update For") = 0 And InStr($SoftwareName, "Update for Windows XP") = 0
				And InStr($SoftwareName, "Windows XP Hotfix") = 0 And InStr($SoftwareName, "Hotfix for Windows XP") = 0
				And InStr($SoftwareName, "Windows 2000 Hotfix") = 0 And InStr($SoftwareName, "Update for Windows 7") = 0
				And InStr($SoftwareName, "Windows 7 Hotfix") = 0 And InStr($SoftwareName, "Hotfix for Windows 7") = 0
			$SoftwareVersion = "N/A"
			$SoftwareVersion = ReadValue($uninstallkey + $package, "DisplayVersion")
			If $SoftwareVersion = ""
				$SoftwareVersion = "N/A"
			EndIf
			$Publisher = "N/A"
			$Publisher = ReadValue($uninstallkey + $package, "Publisher")
			If $Publisher = ""
				$Publisher = "N/A"
			EndIf
			$PackageList = $PackageList + @CRLF + Chr(34) + @WKSTA + Chr(34) + "," + Chr(34) + $SoftwareName + Chr(34) + "," + Chr(34) + $SoftwareVersion + Chr(34) + "," + Chr(34) + $Publisher + Chr(34)
		EndIf
	EndIf
	$Index = $Index + 1
	$package = EnumKey($uninstallkey, $Index)
Loop

;Enumerate keys in HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages
$uninstallkey = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages"

$Index = 0
$package = EnumKey($uninstallkey, $Index)
While Not @ERROR
	$SoftwareName = ReadValue($uninstallkey + $package, "Displayname")
	If $SoftwareName <> ""
		If InStr($SoftwareName, "Security Update For") = 0 And InStr($SoftwareName, "Update for Windows XP") = 0
			And InStr($SoftwareName, "Windows XP Hotfix") = 0 And InStr($SoftwareName, "Hotfix for Windows XP") = 0
			And InStr($SoftwareName, "Windows 2000 Hotfix") = 0 And InStr($SoftwareName, "Update for Windows 7") = 0
			And InStr($SoftwareName, "Windows 7 Hotfix") = 0 And InStr($SoftwareName, "Hotfix for Windows 7") = 0
			$SoftwareVersion = "N/A"
			$SoftwareVersion = ReadValue($uninstallkey + $package, "DisplayVersion")
			If $SoftwareVersion = ""
				$SoftwareVersion = "N/A"
			EndIf
			$Publisher = "N/A"
			$Publisher = ReadValue($uninstallkey + $package, "Publisher")
			If $Publisher = ""
				$Publisher = "N/A"
			EndIf
			$PackageList = $PackageList + @CRLF + Chr(34) + @WKSTA + Chr(34) + "," + Chr(34) + $SoftwareName + Chr(34) + "," + Chr(34) + $SoftwareVersion + Chr(34) + "," + Chr(34) + $Publisher + Chr(34)
		EndIf
	EndIf
	$Index = $Index + 1
	$package = EnumKey($uninstallkey, $Index)
Loop

LogtoFile("ForceOverwrite", $LogonLogs + "Software_Inventory\" + @WKSTA + ".csv", $PackageList)


**DONOTDELETE**
(Lurker)
2015-11-04 10:51 AM
Re: Windows 7 script - Error failed to find/open script [Log.kix]

Thanks Mart

You mentioned the if the windows 7 updates have a display within the registry. I checked and the under the location below it doesn't have a displayname for each of the updates.

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages


**DONOTDELETE**
(Lurker)
2015-11-04 01:19 PM
Re: Windows 7 script - Error failed to find/open script [Log.kix]

Putting the security updates aside for now.

One issue that I have found with the software_inventory reading the uninstall key on windows 7 PC's, is that it doesn't read all the software displayname's even though all the software have displayname. If does log most of the software but not all.

I ran the script on an XP PC with the same code and it picks out all the software within the uninstall key within the registry.

Anyone have any idea why it would not log all the software with displaynames on the windows 7 PC to the csv? Thanks


NTDOCAdministrator
(KiX Master)
2015-11-04 06:59 PM
Re: Windows 7 script - Error failed to find/open script [Log.kix]

You might look at some very old code I have here.

My Computer Info script
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=138538&site_id=1#import

Software depends on what type of installer was used. Some locations are updated/added for MSI that regular EXE Installers don't use the same location. Certainly a haberdashery of methods in the Registry. Then some applications use a display name or product name and some don't which makes it very difficult to be 100%