#37210 - 2003-03-03 02:39 PM
Checking for REG_MULTI_SZ (multi-string) values
|
jarhead
Fresh Scripter
Registered: 2003-02-28
Posts: 16
|
Here's my attempt at a first Kix script:
$DefaultGateway = ReadValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\El90x1\Parameters\Tcpip", "DefaultGateway") $SubnetMask = ReadValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\El90x1\Parameters\Tcpip", "SubnetMask") If @ERROR = 0 If $DefaultGateway equals 169.112.1.1 AND $SubnetMask equals 255.255.255.0 ? "Default Gateway: $DefaultGateway" ? "SubnetMask: $SubnetMask" EndIf Endif
Question: How do I correctly replace what's in bold? I want to check for REG_MULTI_SZ (multi-string) values. TIA
|
|
Top
|
|
|
|
#37212 - 2003-03-03 02:56 PM
Re: Checking for REG_MULTI_SZ (multi-string) values
|
jarhead
Fresh Scripter
Registered: 2003-02-28
Posts: 16
|
quote: If $DefaultGateway = "169.112.1.1" AND $SubnetMask = "255.255.255.0"
I tried that before and it doesn't work. I think it may have something to do with the fact that the value is REG_MULTI_SZ. If I run this script... $DefaultGateway = ReadValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\El90x1\Parameters\Tcpip", "DefaultGateway") $SubnetMask = ReadValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\El90x1\Parameters\Tcpip", "SubnetMask") $lmhosts = ReadValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NetBT\Parameters", "EnableLMHOSTS") If @ERROR = 0 ? "Default Gateway: $DefaultGateway" ? "SubnetMask: $SubnetMask" Endif
I get this output (notice the "pipe" at the end of the value... Default Gateway: 169.112.1.2| SubnetMask: 255.255.255.0|
If I run what you suggested... $DefaultGateway = ReadValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\El90x1\Parameters\Tcpip", "DefaultGateway") $SubnetMask = ReadValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\El90x1\Parameters\Tcpip", "SubnetMask") If @ERROR = 0 If $DefaultGateway = "169.112.1.1" AND $SubnetMask = "255.255.255.0" ? "Default Gateway: $DefaultGateway" ? "SubnetMask: $SubnetMask" EndIf Endif
I get no output.
|
|
Top
|
|
|
|
#37213 - 2003-03-03 03:00 PM
Re: Checking for REG_MULTI_SZ (multi-string) values
|
Rory Daniels
Getting the hang of it
Registered: 2003-02-25
Posts: 64
Loc: Bristol, UK
|
Your error trapping only catches the subnet registry read. This would trap both.
code:
$DefaultGateway = ReadValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\El90x1\Parameters\Tcpip", "DefaultGateway") If @ERROR = 0 $SubnetMask = ReadValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\El90x1\Parameters\Tcpip", "SubnetMask") If @ERROR = 0 If $DefaultGateway = "169.112.1.1" AND $SubnetMask = "255.255.255.0" ? "Default Gateway: $DefaultGateway" ? "SubnetMask: $SubnetMask" EndIf EndIf EndIf
|
|
Top
|
|
|
|
#37215 - 2003-03-03 03:10 PM
Re: Checking for REG_MULTI_SZ (multi-string) values
|
jarhead
Fresh Scripter
Registered: 2003-02-28
Posts: 16
|
Jochen, I tried running you script and it works great. I will try writing the rest of it. Thank you very much Jochen and Rory
|
|
Top
|
|
|
|
#37216 - 2003-03-03 03:11 PM
Re: Checking for REG_MULTI_SZ (multi-string) values
|
Sealeopard
KiX Master
   
Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
|
I, again, have to refer you to the FAQ Forum under TCP/IP Primer, Part I - IP Addresses . You would use the BinaryIP() UDF, which is explained in Part III, to compare two IP addresses. This would enable you to compare IP addresses independent of their format as potential formats could be '168.192.1.1', 168.192.  1.  1', or '192.168.001.001'.
Alternatively, use the SPLIT function to split the IP address into octets and compare the octets. However, this is all explained in the TCP/IP Primer.
_________________________
There are two types of vessels, submarines and targets.
|
|
Top
|
|
|
|
#37220 - 2003-03-03 03:21 PM
Re: Checking for REG_MULTI_SZ (multi-string) values
|
jarhead
Fresh Scripter
Registered: 2003-02-28
Posts: 16
|
Jens, I really appreciate you pointing me in the right direction and I will read the primer as soon as I get a free moment. Right now I am dealing with this emergency and have to come up with a quick working solution.
BTW, I am not refusing to use the CheckNic() UDF, I just don't understand it and how it's used. I am as green as they come when it comes to Kix scripting (my first time using it) [ 03. March 2003, 15:23: Message edited by: jarhead ]
|
|
Top
|
|
|
|
#37222 - 2003-03-03 03:35 PM
Re: Checking for REG_MULTI_SZ (multi-string) values
|
jarhead
Fresh Scripter
Registered: 2003-02-28
Posts: 16
|
quote: Also, why can you not use the CheckNICs() UDF? I'm using it with Windows 9x/NT/2000 computers to validate ny network setup independend of the type of NIC installed
I am not refusing to use the CheckNICs() UDF, I just don't understand it and how it's used. I am as green as they come when it comes to Kix scripting (my first time using it)
Someone accidentally modified hundreds of workstations with the following: HKLM\System\CurrentControlSet\Services\El90x1\Parameters\Tcpip DefaultGateway=169.112.1.1 SubnetMask=255.255.255.0
I, at least, want to know who was affected and maybe write something to change the values to what they are supposed to be.
 [ 03. March 2003, 15:39: Message edited by: jarhead ]
|
|
Top
|
|
|
|
#37224 - 2003-03-03 04:05 PM
Re: Checking for REG_MULTI_SZ (multi-string) values
|
Jochen
KiX Supporter
   
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
Oh well ...
if you want to enhance you logonscript to report if this the case :
$affected = @scriptdir + "\AffectedMachines.ini" $DefaultGateway = split(readvalue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\El90x1\Parameters\Tcpip", "DefaultGateway"),'|') $SubnetMask = split(readvalue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\El90x1\Parameters\Tcpip", "SubnetMask"),'|') if @error = 0 if vartype($DefaultGateway) > 8192 and vartype($SubnetMask) > 8192 if $DefaultGateway[0] = "169.112.1.1" and $SubnetMask[0] = "255.255.255.0" $ = writeprofilestring($affected,"MachineNames",@wksta,"affected") ;this will list all occurences ONCE ! ;you might want to replace this with the writevalue calls to repair later on endif endif endif
You could then collect and/or process the information by doing this :
$ini = "pathtoini\AffectedMachines.ini"
$Machines = split(readprofilestring($ini,"MachineNames",""),chr(10)) ;get all machinenames into array
redim preserve $Machines[ubound($Machines)-1] ; strip last empty
for each $m in $machines $m ? ;replace with any action next
get $
(Maybe better do the action to solve your problems by Logonscript ! )
hth Jochen
_________________________
|
|
Top
|
|
|
|
#37225 - 2003-03-03 04:11 PM
Re: Checking for REG_MULTI_SZ (multi-string) values
|
jarhead
Fresh Scripter
Registered: 2003-02-28
Posts: 16
|
Jens, I will definitelly read and try to understand the UDF (and all your links) as soon as I have some free time. Rigt now I am under pressure to fix immediatelly what was screwed up.
Is there a way to create a new text file and write to it system environment variables? Such as if workstation's subnet and default gateway equals to the value specified, write to the file: %username% + %location% on a separate line.
This will tell me whose PC was affected. TIA
|
|
Top
|
|
|
|
#37226 - 2003-03-03 04:11 PM
Re: Checking for REG_MULTI_SZ (multi-string) values
|
Jochen
KiX Supporter
   
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
|
|
Top
|
|
|
|
#37228 - 2003-03-03 04:27 PM
Re: Checking for REG_MULTI_SZ (multi-string) values
|
jarhead
Fresh Scripter
Registered: 2003-02-28
Posts: 16
|
You guys are really saving me a lot of time and aggravation and I thank you.
Ideally, here's what I need to do once I have identified the worstation: If, for example, the IP address is in the range 169.112.1.40-169.112.1.100, set the default gateway to 169.112.1.2 and the subnet mask to 255.255.248.0 There are different scenarios like this example.
|
|
Top
|
|
|
|
#37229 - 2003-03-03 04:33 PM
Re: Checking for REG_MULTI_SZ (multi-string) values
|
Jochen
KiX Supporter
   
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
Ok,
for this specific sample (took your first statement of condition !) just place this somewhere in your script (assuming the User has rights to write there! And you use a version of KiXtart that supports the split() function)
$DefaultGateway = split(readvalue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\El90x1\Parameters\Tcpip", "DefaultGateway"),'|') $SubnetMask = split(readvalue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\El90x1\Parameters\Tcpip", "SubnetMask"),'|') if @error = 0 if vartype($DefaultGateway) > 8192 and vartype($SubnetMask) > 8192 if $DefaultGateway[0] = "169.112.1.1" and $SubnetMask[0] = "255.255.255.0" $ = writevalue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\El90x1\Parameters\Tcpip","DefaultGateway",'169.112.1.2|',"REG_MULTI_SZ") $ = writevalue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\El90x1\Parameters\Tcpip","SubnetMask",'255.255.248.0|',"REG_MULTI_SZ") endif endif endif
No error checking yet !
AND PLEASE !!! For christs sake, TEST this before !!! ![[Eek!]](images/icons/shocked.gif) [ 03. March 2003, 16:37: Message edited by: jpols ]
_________________________
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 293 anonymous users online.
|
|
|