#197136 - 2009-12-15 06:54 PM
Registry Scanning with List
|
Tesdall
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]
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]
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?
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
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
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:
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
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:
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
Getting the hang of it
Registered: 2009-10-02
Posts: 78
Loc: USA
|
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
|
|
|
|
#197147 - 2009-12-15 09:57 PM
Re: Registry Scanning with List
[Re: Glenn Barnas]
|
Tesdall
Getting the hang of it
Registered: 2009-10-02
Posts: 78
Loc: USA
|
After all said and done this appears to work:
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
KiX Supporter
   
Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
|
Just a bit of a cleanup with the multiple file methodBreak 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!
|
Top
|
|
|
|
#197158 - 2009-12-16 03:05 PM
Re: Registry Scanning with List
[Re: Glenn Barnas]
|
Tesdall
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
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
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
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
|
|
|
|
#197163 - 2009-12-16 04:17 PM
Re: Registry Scanning with List
[Re: eriqjaffe]
|
Tesdall
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
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
Getting the hang of it
Registered: 2009-10-02
Posts: 78
Loc: USA
|
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
|
|
|
|
#197168 - 2009-12-16 04:42 PM
Re: Registry Scanning with List
[Re: Mart]
|
Tesdall
Getting the hang of it
Registered: 2009-10-02
Posts: 78
Loc: USA
|
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
|
|
|
|
#197170 - 2009-12-16 05:23 PM
Re: Registry Scanning with List
[Re: Mart]
|
Tesdall
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
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1574 anonymous users online.
|
|
|