Page 1 of 2 12>
Topic Options
#197136 - 2009-12-15 06:54 PM Registry Scanning with List
Tesdall Offline
Getting the hang of it

Registered: 2009-10-02
Posts: 78
Loc: USA
I am trying to scan the registry of remote computers from a list i pulled out of active directory. The code that i have works seperate, but together i cannot get it to work. I'm guessing im the one at fault.

When i run this code on my machine, it displays the following information
8.0.6001.18702[0]
 Code:
Break on
$filename = "c:\test\version.txt"
$RowsType = Readvalue("HKLM\SOFTWARE\Microsoft\Internet Explorer", "Version")
If @ERROR = 0
   ? "Version: $RowsType"
If Open( 2 , "$filename" , 5 ) = 0
   $counter = 0
   While $counter < $rowstype
       $nul = WriteLine ( 2 , "$rowstype[$counter] " )
       $counter = $counter + 1
   Loop
   $nul = Close(2)
Endif
 


If i run this code, it displays every comptuer in the list. example
Line read: [BERK_WEBER]
Line read: [BERK_WOOD]

 Code:
IF Open(3, "c:\test\ie8.txt")  = 0
   $x = ReadLine(3)
   WHILE @ERROR = 0
      ? "Line read: [" + $x + "]"
      $x = ReadLine(3)
loop
     Close (3)


This code does not work. Any help?

 Code:
Break on
$filename = "c:\test\version.txt"
readline ("c:\test\ie8.txt") = 0
$computer = ReadLine(3)
   WHILE @ERROR = 0
      $computer = ReadLine(3)
$RowsType = Readvalue("\\$computer\HKLM\SOFTWARE\Microsoft\Internet Explorer", "Version")
If @ERROR = 0
   ? "Version: $RowsType"
If Open( 2 , "$filename" , 5 ) = 0
   $counter = 0
   While $counter < $rowstype
       $nul = WriteLine ( 2 , "$rowstype[$counter] " )
       $counter = $counter + 1
   Loop
   $nul = Close(2)
Endif


once again, i'm not very good with kix. I'm more of a batch file guy. However, the people that i work with usually request kix scripts. So i'm trying. Sorry if i screw this up.


Edited by Tesdall (2009-12-15 07:02 PM)
_________________________
Where ever you go, there you are.

Top
#197139 - 2009-12-15 07:09 PM Re: Registry Scanning with List [Re: Tesdall]
Tesdall Offline
Getting the hang of it

Registered: 2009-10-02
Posts: 78
Loc: USA
i noticed that one thing was messed up with the script, once again i suck at this.

i was missing '$computer' in my script. That got me a little futher, but now it just closes after the first computer in the list. Now i have to figure out how to keep it going.
_________________________
Where ever you go, there you are.

Top
#197140 - 2009-12-15 08:22 PM Re: Registry Scanning with List [Re: Tesdall]
Tesdall Offline
Getting the hang of it

Registered: 2009-10-02
Posts: 78
Loc: USA
I somehow got it to work...sheer luck i belive. How do i keep it going if it cannot connect to one of the machines. Alos, when it writes to the file it writes it like 8 times for each. Example:
 Code:
BERK_BRADY, 8.0.6001.18702, 
BERK_BRADY, 8.0.6001.18702, 
BERK_BRADY, 8.0.6001.18702, 
BERK_BRADY, 8.0.6001.18702, 
BERK_BRADY, 8.0.6001.18702, 
BERK_BRADY, 8.0.6001.18702, 
BERK_BRADY, 8.0.6001.18702, 
BERK_BRADY, 8.0.6001.18702, 
BERK_C_DOCK, 6.0.2900.5512, 
BERK_C_DOCK, 6.0.2900.5512, 
BERK_C_DOCK, 6.0.2900.5512, 
BERK_C_DOCK, 6.0.2900.5512, 
BERK_C_DOCK, 6.0.2900.5512, 
BERK_C_DOCK, 6.0.2900.5512,  


any way to clean this up?


Here is my new code

 Code:
 
Break on

$filename = ("c:\test\version.txt")
$list = ("C:\test\ie8.txt")

IF Open(3, "$list")  = 0
$computer = ReadLine(3)
WHILE @ERROR = 0
? "Computer: $computer"
$Computer = readline(3)

$Version = Readvalue("\\$computer\HKLM\SOFTWARE\Microsoft\Internet Explorer", "Version")

If @ERROR = 0
   ? "Version: $Version"

if @error = 1
loop

If Open( 2 , "$filename") = 0
   $counter = 0
   While $counter < $Version
       $nul = WriteLine ( 2 , "$computer, $Version, " )
       $counter = $counter + 1
   Loop

   $nul = Close(2)

Endif


Also when i run the command from the command prompt i get this:

 Code:

Computer: BERK_BECKY_K
Version: 8.0.6001.18702
Computer: BERK_BRADY
Version: 6.0.2900.5512
Computer: BERK_C_DOCK


Any idea why Becky_k is not showing up in the text file?
I'm not sittin still even though you guys are \:\)


Edited by Tesdall (2009-12-15 08:28 PM)
_________________________
Where ever you go, there you are.

Top
#197142 - 2009-12-15 09:08 PM Re: Registry Scanning with List [Re: Tesdall]
Tesdall Offline
Getting the hang of it

Registered: 2009-10-02
Posts: 78
Loc: USA
 Code:
 
Break on

$filename = ("c:\test\version.txt")
$list = ("C:\test\ie8.txt")

$Computercount = 0

IF Open( 1 , "$list")  = 0
$computer = ReadLine(1)
WHILE @ERROR = 0
? "Computer: $computer"
$Computer = readline(1)

$Computercount = $Computercount + 1

$Version = Readvalue("\\$computer\HKLM\SOFTWARE\Microsoft\Internet Explorer", "Version")

If @ERROR = 0
? "Version: $Version"

If Open( 2 , "$filename" , 5) = 0
   $counter = 0
   While $counter < $Computercount
       $write = WriteLine ( 2 , '$Version' + " " + '$Computer' + @CRLF)
       $counter = $counter + 1
   loop

$write = Close(2)

Endif


How do i make it keep looping if it hangs on one?


Edited by Tesdall (2009-12-15 09:23 PM)
_________________________
Where ever you go, there you are.

Top
#197145 - 2009-12-15 09:30 PM Re: Registry Scanning with List [Re: Tesdall]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
 Code:
$Version = Readvalue("\\$computer\HKLM\SOFTWARE\Microsoft\Internet Explorer", "Version")
is not so good.. try this
 Code:
$Version = Readvalue('\\' + $computer + '\HKLM\SOFTWARE\Microsoft\Internet Explorer', 'Version')
to keep the vars out of the strings.

I'd use one of the Ping() UDFs -
 Code:
If Ping($Computer)
  $Version = Readvalue('\\' + $computer + '\HKLM\SOFTWARE\Microsoft\Internet Explorer', 'Version')
Else
  $Version = 'No response'
EndIf
The basic Ping UDF should do the job - just be sure to include it in your script.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#197146 - 2009-12-15 09:32 PM Re: Registry Scanning with List [Re: Glenn Barnas]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
Your file write is also messed up.. have to hit the road, but I'll try to explain more later..

You should just open both input and output file pointers together.. read from 1, write to 2, then close both when done.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#197147 - 2009-12-15 09:57 PM Re: Registry Scanning with List [Re: Glenn Barnas]
Tesdall Offline
Getting the hang of it

Registered: 2009-10-02
Posts: 78
Loc: USA
After all said and done this appears to work:
 Code:
Break on

$filename = ("c:\test\version.txt")
$list = ("C:\test\ie8.txt")

IF Open( 1 , "$list")  = 0
If Open( 2 , "$filename" , 5) = 0

$computer = ReadLine(1)
WHILE @ERROR = 0
? "Computer: $computer"

$Version = "PC Not Online"

$Version = Readvalue("\\$computer\HKLM\SOFTWARE\Microsoft\Internet Explorer", "Version")

? "Version: $Version"

$write = WriteLine ( 2 , '$Version' + " " + '$Computer' + @CRLF)

$computer = ReadLine(1)

loop

Endif
Endif

$null = close(1)
$null = close(2)
_________________________
Where ever you go, there you are.

Top
#197151 - 2009-12-16 03:15 AM Re: Registry Scanning with List [Re: Tesdall]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
Just a bit of a cleanup with the multiple file method
 Code:
Break on

; Declare variables to prevent scope creep
Dim $InFile, $OutFile			; file names for input and output
Dim $Computer				; computer name, from input file
Dim $Rc					; return-code catcher
Dim $Version				; Version data from Computer

$Rc = SetOption('NoVarsInStings', 'On')


$OutFile = ('c:\test\version.txt')
$InFile  = ('C:\test\ie8.txt')

; Open the input file - no strings in quotes!
If Open( 1 , $InFile) <> 0
  'Failed to open ' $InFile ' - aborting!' ?
  Exit 1
EndIf

; same for the output file
If Open( 2 , $OutFile, 5) <> 0
  'Failed to open ' $OutFile ' - aborting!' ?
  Exit 1
EndIf

; Read the first line, then loop until EOD (End Of Data) error
$Computer = ReadLine(1)
While Not @ERROR

  'Computer: ' $Computer ?		; display the current computer

  ; Only read the registry if the computer is online
  If Ping($Computer)
    $Version = Readvalue('\\' + $Computer + '\HKLM\SOFTWARE\Microsoft\Internet Explorer', 'Version')
  Else
    $Version = 'PC Not Online'		; no ping response
  EndIf

  ; If the registry data is blank, provide appropriate message
  $Version = IIf($Version, $Version, 'Invalid data from PC')

  'Version: ' $Version ?		Display version

  $Rc = WriteLine(2, $Version + ' ' + $Computer + @CRLF)

  $Computer = ReadLine(1)

Loop

$Rc = Close(1)
$Rc = Close(2)
Couple of pointers

Putting variables inside of strings is not good practice. Think about trying to output a $ in a string - how does the program know when you want to output $12 and not the content of a variable? It isn't "natural" to write "$$" when you mean "$" either..

You preloaded $Version with an error string and then loaded it from the remote registry read. If you had used the "If Ping($computer) logic, that might have worked, but one just overwrites the other. In the example above, there are clear error messages when a PC doesn't respond or provides bad (empty) data.

Without using the Ping test, your query could take many seconds to determine that a PC isn't online.. with Ping, it only takes 2-3 seconds. This could mean the difference between the process taking minutes or an hour, depending on the number of computers to query and how many were active.

"?" is a shortcut for @CRLF, not for a PRINT statement as in BASIC.. it's more natural to put it at the end of a line of output, as you did with the @CRLF in your WriteLine statement.

Nesting the If statements when opening the files doesn't serve any extra value, so just "bark and die" if the files fail to open. You "could" use the error message @SERROR to display the reason if you so choose.

As your code gets more complex, you'll need to make use of Shell and Run commands. These often REQUIRE the use of double-quotes, so it's best to get in the habit of using single quotes for Kix, making it easy to embed double-quotes in commands or strings.

Don't be discouraged by these comments - these things aren't "wrong", just concepts that make it easier to build larger or more complex and robust scripts.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#197158 - 2009-12-16 03:05 PM Re: Registry Scanning with List [Re: Glenn Barnas]
Tesdall Offline
Getting the hang of it

Registered: 2009-10-02
Posts: 78
Loc: USA
I've found one non-issue and one issue that i can seem to over come.

the non-issue was the c: was capital (im anal about having everything the same)

secondly when i run the command i get the following

Computer: CORP_LAB_ADMIN
CORP_LAB_ADMINVersion: 8.0.6001.18702

I can't seem to find where in this script it prints both at the same time and then smashes them together.

I see where it writes the computer name
'Computer: ' $Computer ? ; display the current computer

Then i see where it writes the version
$Version = 'PC Not Online' ; no ping response
or
'Version: ' $Version ? Display version
or
$Version = IIf( $Version, $Version, 'Invalid data from PC')

but why am i gettign two computers ?
Computer: CORP_LAB_ADMIN
CORP_LAB_ADMINVersion: 8.0.6001.18702

also i changed the space between Version and Computer to incorporate a "," so that i can export the txt file to a CSV to manipulate in excel.

woo haa!


Edited by Tesdall (2009-12-16 03:07 PM)
_________________________
Where ever you go, there you are.

Top
#197159 - 2009-12-16 03:20 PM Re: Registry Scanning with List [Re: Tesdall]
Tesdall Offline
Getting the hang of it

Registered: 2009-10-02
Posts: 78
Loc: USA
After running the script a few times, i've also noticed that the ping error doesn't seem to work. All i get are IE versions and invalid data. I know one or two of the machines that not online, and they should get a pc not online "error". But its just giving it them an invalid data "error".

I'll be looking over the script and tring to learn it in the mean time.

*update*
Not sure if this has anything to do with it, but it seems to be pulling the ip address from DNS even if the machine is not online.

Manual
C:\Program Files\Support Tools>ping corp_reeser
Pinging CORP_REESER.ussilica.com [10.142.201.29] with 32 bytes of data:
Request timed out.
Request timed out.

Output from the kix script
Computer: CORP_REESER
CORP_REESERVersion: Invalid data from PC


Edited by Tesdall (2009-12-16 03:26 PM)
_________________________
Where ever you go, there you are.

Top
#197160 - 2009-12-16 03:39 PM Re: Registry Scanning with List [Re: Tesdall]
eriqjaffe Offline
Hey THIS is FUN

Registered: 2004-06-24
Posts: 214
Loc: Arlington Heights, IL USA
ping() is not an in-built function of KiXtart. You'll need to get the UDF here and paste the code into your script.

Edited by eriqjaffe (2009-12-16 03:39 PM)

Top
#197161 - 2009-12-16 03:58 PM Re: Registry Scanning with List [Re: eriqjaffe]
Tesdall Offline
Getting the hang of it

Registered: 2009-10-02
Posts: 78
Loc: USA
wonderful!

now what do i do with it?
_________________________
Where ever you go, there you are.

Top
#197162 - 2009-12-16 04:12 PM Re: Registry Scanning with List [Re: Tesdall]
eriqjaffe Offline
Hey THIS is FUN

Registered: 2004-06-24
Posts: 214
Loc: Arlington Heights, IL USA
Simple as that. Copy the code, and paste it in your script. Kixtart will now treat ping() calls as if it were a native function.
Top
#197163 - 2009-12-16 04:17 PM Re: Registry Scanning with List [Re: eriqjaffe]
Tesdall Offline
Getting the hang of it

Registered: 2009-10-02
Posts: 78
Loc: USA
ok, wasn't sure. After reading the examples it was thinking i needed to make a UDF file to call the commands from.
_________________________
Where ever you go, there you are.

Top
#197165 - 2009-12-16 04:22 PM Re: Registry Scanning with List [Re: Tesdall]
Tesdall Offline
Getting the hang of it

Registered: 2009-10-02
Posts: 78
Loc: USA
after pasting the code it crashed on line 68:

If Ping($Computer)

ERROR : invalid method/function call: missing required parameter 2!
Script: c:\test\ie8test.kix
Line : 68


Edited by Tesdall (2009-12-16 04:24 PM)
_________________________
Where ever you go, there you are.

Top
#197166 - 2009-12-16 04:30 PM Re: Registry Scanning with List [Re: Tesdall]
Tesdall Offline
Getting the hang of it

Registered: 2009-10-02
Posts: 78
Loc: USA
 Code:
Break on

function Ping($Computer,$GetIP,optional $LoopCount,optional $TimeOut)
	if $GetIP
		dim $ip, $ipfile, $
		$ipfile = @scriptdir + '\ip.txt'
		shell '%Comspec% /q /e:1024 /c for /F "tokens=2 delims=[]" %%i IN ('+ chr(39)
		+ '"ping ' + $Computer1 + ' -n 1 | find "]""' + chr(39) + ') do echo %%i >"' + $ipfile + '"'
		$ = open(10,$ipfile,2) $ip = readline(10) $ = close(10) del $ipfile
		if $ip
			$Ping = $ip
		else
			$Ping = 'Bad IP address ' + $Computer + '!'
		endif
		exit 0
	else
		if $TimeOut
			for $c = 0 to $LoopCount
				shell '%Comspec% /C ping ' + $Computer + ' -n 1 -w ' + $TimeOut + ' | find /C "TTL=" > nul'
				if @error = 0
					$Ping = 1
					exit 0
				endif
			next
		else
			for $c = 0 to $LoopCount
				shell '%Comspec% /C ping ' + $Computer + ' | find /C "TTL=" > nul'
				if @error = 0
					$Ping = 1
					exit 0
				endif
			next
		endif
		$Ping = 0
	endif
endfunction

; Declare variables to prevent scope creep
Dim $InFile, $OutFile			; file names for input and output
Dim $Computer				; computer name, from input file
Dim $Rc					; return-code catcher
Dim $Version				; Version data from Computer

$Rc = SetOption('NoVarsInStings', 'On')

$OutFile = ('c:\test\version.txt')
$InFile  = ('c:\test\ie8.txt')

; Open the input file - no strings in quotes!
If Open( 1 , $InFile) <> 0
  'Failed to open ' $InFile ' - aborting!' ?
  Exit 1
EndIf

; same for the output file
If Open( 2 , $OutFile, 5) <> 0
  'Failed to open ' $OutFile ' - aborting!' ?
  Exit 1
EndIf

; Read the first line, then loop until EOD (End Of Data) error
$Computer = ReadLine(1)
While Not @ERROR

  'Computer: ' $Computer ?		; display the current computer

  ; Only read the registry if the computer is online
  If Ping($Computer)
    $Version = Readvalue('\\' + $Computer + '\HKLM\SOFTWARE\Microsoft\Internet Explorer', 'Version')
  Else
    $Version = 'PC Not Online'		; no ping response
  EndIf

  ; If the registry data is blank, provide appropriate message
  $Version = IIf($Version, $Version, 'Invalid data from PC')

  'Version: ' $Version ?		Display version

  $Rc = WriteLine(2, $Version + ',' + $Computer + @CRLF)

  $Computer = ReadLine(1)

Loop

$Rc = Close(1)
$Rc = Close(2)
_________________________
Where ever you go, there you are.

Top
#197167 - 2009-12-16 04:32 PM Re: Registry Scanning with List [Re: Tesdall]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
You need to read the UDF header better. The second parameter is required and should be 1 if you want to get the IP or 0 if you just want to check for a reply.

See :
 Code:
Computer(Required)
	-  String value representing the Computer to ping
GetIp (Required)
	-  If specified (1), the Function will Return the ip-address
		of specified Computer rather than pinging it ...
		Has to be 0 If you want to check For reply !
LoopCount (Optional but useful !)
	-  Integer value representing the number of times
		the Computer shall be pinged
Timeout (Optional)
	-  If ommited the Computer Gets pinged with the default
		timeout (1s) And default retries (4)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#197168 - 2009-12-16 04:42 PM Re: Registry Scanning with List [Re: Mart]
Tesdall Offline
Getting the hang of it

Registered: 2009-10-02
Posts: 78
Loc: USA
 Code:
Break on

function Ping($Computer,$GetIP,optional $LoopCount,optional $TimeOut)
	if $GetIP
		dim $ip, $ipfile, $
		$ipfile = @scriptdir + '\ip.txt'
		shell '%Comspec% /q /e:1024 /c for /F "tokens=2 delims=[]" %%i IN ('+ chr(39)
		+ '"ping ' + $Computer1 + ' -n 1 | find "]""' + chr(39) + ') do echo %%i >"' + $ipfile + '"'
		$ = open(10,$ipfile,2) $ip = readline(10) $ = close(10) del $ipfile
		if $ip
			$Ping = $ip
		else
			$Ping = 'Bad IP address ' + $Computer + '!'
		endif
		exit 0
	else
		if $TimeOut
			for $c = 0 to $LoopCount
				shell '%Comspec% /C ping ' + $Computer + ' -n 1 -w ' + $TimeOut + ' | find /C "TTL=" > nul'
				if @error = 0
					$Ping = 1
					exit 0
				endif
			next
		else
			for $c = 0 to $LoopCount
				shell '%Comspec% /C ping ' + $Computer + ' | find /C "TTL=" > nul'
				if @error = 0
					$Ping = 1
					exit 0
				endif
			next
		endif
		$Ping = 0
	endif
endfunction

; Declare variables to prevent scope creep
Dim $InFile, $OutFile			; file names for input and output
Dim $Computer				; computer name, from input file
Dim $Rc					; return-code catcher
Dim $Version				; Version data from Computer

$Rc = SetOption('NoVarsInStings', 'On')

$OutFile = ('c:\test\version.txt')
$InFile  = ('c:\test\ie8.txt')

; Open the input file - no strings in quotes!
If Open( 1 , $InFile) <> 0
  'Failed to open ' $InFile ' - aborting!' ?
  Exit 1
EndIf

; same for the output file
If Open( 2 , $OutFile, 5) <> 0
  'Failed to open ' $OutFile ' - aborting!' ?
  Exit 1
EndIf

; Read the first line, then loop until EOD (End Of Data) error
$Computer = ReadLine(1)
While Not @ERROR

  'Computer: ' $Computer ?		; display the current computer

  ; Only read the registry if the computer is online
  If Ping($Computer, $getip)
    $Version = Readvalue('\\' + $Computer + '\HKLM\SOFTWARE\Microsoft\Internet Explorer', 'Version')
  Else
    $Version = 'PC Not Online'		; no ping response
  EndIf

  ; If the registry data is blank, provide appropriate message
  $Version = IIf($Version, $Version, 'Invalid data from PC')

  'Version: ' $Version ?		Display version

  $Rc = WriteLine(2, $Version + ',' + $Computer + @CRLF)

  $Computer = ReadLine(1)

Loop

$Rc = Close(1)
$Rc = Close(2)



Edited by Tesdall (2009-12-16 04:45 PM)
_________________________
Where ever you go, there you are.

Top
#197169 - 2009-12-16 05:01 PM Re: Registry Scanning with List [Re: Tesdall]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
I'm feeling lucky and I'll take a guess (because you just posted the code twice without any comments).

The Ping UDF requires two parameters. You have it in your code like this Ping($Computer, $getip). The $getip variable you use is never filled so it is empty (NULL). It should be set to 1 or 0 depending on what you want to do. 1 to get the IP and 0 to check for a reply.
Ping($Computer, 1) or Ping($Computer, 0) would do the trick for the ping UDF.)


Edited by Mart (2009-12-16 05:03 PM)
Edit Reason: Typo
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#197170 - 2009-12-16 05:23 PM Re: Registry Scanning with List [Re: Mart]
Tesdall Offline
Getting the hang of it

Registered: 2009-10-02
Posts: 78
Loc: USA
well, i was feeling lucky. The code was working and returning the code computer off line.

My mistake on where to inject the correct code. Kix code is getting harder and harder it seems.

changed the $getip to 0


Edited by Tesdall (2009-12-16 05:25 PM)
_________________________
Where ever you go, there you are.

Top
Page 1 of 2 12>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1574 anonymous users online.
Newest Members
BeeEm, min_seow, Audio, Hoschi, Comet
17882 Registered Users

Generated in 0.094 seconds in which 0.039 seconds were spent on a total of 14 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org