Page 1 of 2 12>
Topic Options
#37210 - 2003-03-03 02:39 PM Checking for REG_MULTI_SZ (multi-string) values
jarhead Offline
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
#37211 - 2003-03-03 02:45 PM Re: Checking for REG_MULTI_SZ (multi-string) values
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
1 second please ... (Didn't consider the REG_MULTI_SZ type ... please see reply below for a functioning sample)

[ 03. March 2003, 15:10: Message edited by: jpols ]
_________________________



Top
#37212 - 2003-03-03 02:56 PM Re: Checking for REG_MULTI_SZ (multi-string) values
jarhead Offline
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 Offline
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
#37214 - 2003-03-03 03:00 PM Re: Checking for REG_MULTI_SZ (multi-string) values
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
here u are :



break on

$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"
            ? "Default Gateway: " + $DefaultGateway[0]
            ? "SubnetMask:      " + $SubnetMask[0]
        endif
    endif
endif

get $



ONLY if you are sure there is this 3Com adapter present and DHCP isn't activated [Wink]

[ 03. March 2003, 15:15: Message edited by: jpols ]
_________________________



Top
#37215 - 2003-03-03 03:10 PM Re: Checking for REG_MULTI_SZ (multi-string) values
jarhead Offline
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 Offline
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
#37217 - 2003-03-03 03:14 PM Re: Checking for REG_MULTI_SZ (multi-string) values
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Hmmm ...

Allthough I forgot an endif [Eek!] (edited above) it worked ... however ! I have to second Jens' suggestion as this is
only reliable on a system that has the mentioned prerequisites !

[ 03. March 2003, 15:16: Message edited by: jpols ]
_________________________



Top
#37218 - 2003-03-03 03:17 PM Re: Checking for REG_MULTI_SZ (multi-string) values
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
I also already pointed him to the CheckNICs() UDF which accomplishes the same thing. However, for some reason, he refuses to use it.
_________________________
There are two types of vessels, submarines and targets.

Top
#37219 - 2003-03-03 03:19 PM Re: Checking for REG_MULTI_SZ (multi-string) values
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
You did ? Where ? Earlier topic ???
_________________________



Top
#37220 - 2003-03-03 03:21 PM Re: Checking for REG_MULTI_SZ (multi-string) values
jarhead Offline
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
#37221 - 2003-03-03 03:23 PM Re: Checking for REG_MULTI_SZ (multi-string) values
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
That's why you should read the primer first. I'm sure it'll help you.

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.
_________________________
There are two types of vessels, submarines and targets.

Top
#37222 - 2003-03-03 03:35 PM Re: Checking for REG_MULTI_SZ (multi-string) values
jarhead Offline
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
#37223 - 2003-03-03 03:41 PM Re: Checking for REG_MULTI_SZ (multi-string) values
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Read How to use UDFs in the FAQ Forum. UDFs are canned functions that can be used just like the build-in KiXtart functions.

CheckNICs() is a little bit complicated in order to make it work with most NICs under a variety of operating systems.
_________________________
There are two types of vessels, submarines and targets.

Top
#37224 - 2003-03-03 04:05 PM Re: Checking for REG_MULTI_SZ (multi-string) values
Jochen Administrator Offline
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  [Wink]
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 Offline
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 Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
So ... you now only have to tell us if these are the only values you need to change back to whatever OR give us the values [Wink] , you might then wait a couple of minutes and receive a Script to paste in your logonscript

We (The KiX community) are always tend to help in emergencies [Big Grin]
_________________________



Top
#37227 - 2003-03-03 04:17 PM Re: Checking for REG_MULTI_SZ (multi-string) values
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Example:
code:
$dns='10.10.0.2'
$wins='10.10.0.3'
$gateway='10.10.0.1'
$subnet='255.255.255.0'
$ipmask='10.10.0.0'
$ntdomain='NT-DOMAIN'
$company='COMPANY.COM'

$retcode=checknics($dns,$wins,$gateway,$subnet,$ipmask,$ntdomain,$company)

And include the CheckNICs() UDF and it's dependencies in the script as specified in the FAQ. Execute under an admin account.
_________________________
There are two types of vessels, submarines and targets.

Top
#37228 - 2003-03-03 04:27 PM Re: Checking for REG_MULTI_SZ (multi-string) values
jarhead Offline
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 Administrator Offline
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!]

[ 03. March 2003, 16:37: Message edited by: jpols ]
_________________________



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 302 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.139 seconds in which 0.116 seconds were spent on a total of 13 queries. Zlib compression enabled.

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