Page 1 of 2 12>
Topic Options
#152360 - 2005-11-28 07:21 PM Change MTU?
JTestman Offline
Fresh Scripter

Registered: 2005-11-28
Posts: 26
Hello.. I need assistance converting this to KiX, I’m not a programmer.
I’ve looked over a few post concerning Enumerating Network Connections and I’m confused.

http://www.kixtart.org/ubbthreads/showfl...true#Post150371

The platform is Windows 2000 Professional SP4
Heres the VB code I wish to convert.

' ----------------------------------------'
' Modify MTU values for remote sites.
' ----------------------------------------'

Option Explicit

Dim strComputer, objReg, i, arrAllInterfaces, strKeyPath

Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."
strKeyPath = "SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces"

Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\default:StdRegProv")

'Obtain array of all interfaces.
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrAllInterfaces

For i = 0 To UBound(arrAllInterfaces)
'Create the "MTU" value entry.
objReg.SetDWORDValue HKEY_LOCAL_MACHINE, strKeyPath _
& "\" & arrAllInterfaces(i), "MTU", 1400

Top
#152361 - 2005-11-28 10:47 PM Re: Change MTU?
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Basically, the Microsoft WMI developers are a bunch of dough-heads. This syntax here:

objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrAllInterfaces

causes us much grief. That last parameter (arrAllInterfaces) is what is termed "an [OUT] parameter" and Kixtart does't support this.

How about checking-out the native Kixtart EnumKeys / EnumValue functions - prolly be a lot faster anyways, WMI can be a pig.

Top
#152362 - 2005-11-29 12:50 AM Re: Change MTU?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Personally speaking, unless you have documented or verified confirmation that the MTU settings are not functioning correctly I would not modify them. In many instances I've seen there is little change or improvement seen by such modifications. If you're having packet fragmentation issues then you may need to review drivers/settings on the router.

What application are you running or what are you doing that you feel this change is worth while?
 

Top
#152363 - 2005-11-29 01:24 AM Re: Change MTU?
JTestman Offline
Fresh Scripter

Registered: 2005-11-28
Posts: 26
Thanks for the tip, I’m changing our MTU values so SSL connections can pass through our encryption devices. I’m not the network guy but this works for our offsites.
Top
#152364 - 2005-11-29 01:29 AM Re: Change MTU?
JTestman Offline
Fresh Scripter

Registered: 2005-11-28
Posts: 26
I'll look into EnumKeys / EnumValue functions, do you have a example of this function being used?
Top
#152365 - 2005-11-29 01:31 AM Re: Change MTU?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Look in the Example Scripts forum where it is used. Then go and download the latest versions of the UDF scripts.

You could write your own, but these UDFs make it much simpler.

Top
#152366 - 2005-11-29 01:36 AM Re: Change MTU?
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
ja its pretty basic, here's a quick example using your situation:

Code:

break on

$index = 0

$key = enumkey("HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces", $index)

while $key

?"key=" $key

$index = $index + 1

$key = enumkey("HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces", $index)

loop

exit 0


Top
#152367 - 2005-11-29 01:37 AM Re: Change MTU?
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
once you get the loop working, check-out WriteValue in the manual.
Top
#152368 - 2005-11-29 08:28 AM Re: Change MTU?
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Another way to use this is to get Dr. Tcp from - http://www.dslreports.com/drtcp ..

Then, do a RegSnap from - Registry Tools

HTH,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#152369 - 2005-11-30 01:26 AM Re: Change MTU?
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Also, thare are the canned ArrayEnumKey() and ArrayEnumValue() UDFs, that allow you to pull a set of keys/values into an array.
_________________________
There are two types of vessels, submarines and targets.

Top
#152370 - 2005-11-30 07:30 PM Re: Change MTU?
JTestman Offline
Fresh Scripter

Registered: 2005-11-28
Posts: 26
I found an example that uses the EnumKeys/EnumValue functions, I have looked at he WriteValue function and I need help tying these together. A non working example is below. I need to identify the MTU Value Data to a 1400 decimal value.

How do I tie EnumValue and WriteValue togther?
Code:
  
; EnumKeys.KIX
;
; Enumerates a (registry) key and all its subkeys
;
; Note : This code sample is provided for demonstration purposes only.
; Microsoft makes no warranty, either express or implied,
; as to its usability in any given situation.
;
; Copyright (C) 2001 Ruud van Velsen.
; All rights reserved.
;
BREAK ON

IF $Key = 0
$Key = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces"
ENDIF


;
; first enumerate all subkeys of current key
;
DIM $Index, $SaveKey

$Index = 0
$SubKey = EnumKey( $Key , $Index )

WHILE @ERROR = 0

$SaveKey = $Key

$Key = $Key + "\" + $SubKey

? $Key

CALL EnumKeys

$Key = $SaveKey
IF @ERROR = 0

; try for next subkey

$Index = $Index + 1
$SubKey = EnumKey( $Key , $Index )
ENDIF

LOOP

;
; Lastly, enumerate all values of current key
;
$Index = 0
$Value = EnumValue( $Key , $Index )

WHILE @ERROR = 0
? $Key + "|" + $Value
$Index = $Index + 1
$Value = EnumValue( $Key , $Index )
LOOP

WriteValue( $Key , $Value "MTU", "1400", "REG_DWORD")
If @ERROR = 0
? "Value written to the registry"
Endif


EXIT 0



Edited by JTestman (2005-11-30 08:28 PM)

Top
#152371 - 2005-11-30 08:22 PM Re: Change MTU?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Please use code tags when posting code to preserve indenting.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#152372 - 2005-11-30 11:27 PM Re: Change MTU?
JTestman Offline
Fresh Scripter

Registered: 2005-11-28
Posts: 26
Sorry about that!
Top
#152373 - 2005-12-01 01:03 AM Re: Change MTU?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Sorry, I'm not following the intended logic.
What is the 'CALL EnumKeys' line about? CALL is for calling external script files.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#152374 - 2005-12-01 01:45 AM Re: Change MTU?
JTestman Offline
Fresh Scripter

Registered: 2005-11-28
Posts: 26
Honestly I have no idea the bulk of this script is from a sample scrip included with KIX version 4.51. I added the nonfuncting WriteValue part.
Top
#152375 - 2005-12-01 02:29 AM Re: Change MTU?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I hate writing code when there are ready made UDFs that can do it just as well. Go get yourself ArrayEnumKey() and ArrayEnumValue() and give this a shot. It doesn't do anything more than enum and display all the values but should give you an idea of nesting loops.

I don't suggest this is the best way, it is just an example. I would probably use AScan() to look for the specific value.
Code:
Break On
Dim $BaseKey, $Key, $Value
$BaseKey = 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces'
For each $Key in ArrayEnumKey($BaseKey)
For each $Value in ArrayEnumValue($BaseKey+'\'+$Key)
'Value ['+$Value+'] in Key ['+$Key+']' ?
Next
Next

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#152376 - 2005-12-01 02:33 AM Re: Change MTU?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Comes back blank for me...
Top
#152377 - 2005-12-01 02:52 AM Re: Change MTU?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Guess you will have to do some debugging then
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#152378 - 2005-12-01 02:56 AM Re: Change MTU?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
OK, feeling bored so elaborated a tad. Here's what I meant about AScan().
Code:
Break On
Dim $BaseKey, $Key, $Value
$BaseKey = 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces'
For each $Key in ArrayEnumKey($BaseKey)
If AScan(ArrayEnumValue($BaseKey+'\'+$Key),'MTU')<>-1
'Value ['+ReadValue($BaseKey+'\'+$Key,'MTU')+'] in Key ['+$Key+']' ?
EndIf
Next


Don't forget to grab the UDFs.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#152379 - 2005-12-01 03:57 AM Re: Change MTU?
JTestman Offline
Fresh Scripter

Registered: 2005-11-28
Posts: 26
Thanks for the information!
I added the UDF's and attempted to use the WriteValue function. But when I run in debug mode I see that it identifies the MTU value in 2 of 4 keys and I get an error about a missing comma? It scrolls extremely fast so I might have missed something.



Code:
  

Break On
Dim $BaseKey, $Key, $Value
$BaseKey = 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces'
For each $Key in ArrayEnumKey($BaseKey)
If AScan(ArrayEnumValue($BaseKey+'\'+$Key),'MTU')<>-1
'Value ['+ReadValue($BaseKey+'\'+$Key,'MTU')+'] in Key ['+$Key+']' ?
EndIf
Next

WriteValue( $BaseKey , $Key , $Value "MTU", "1400", "REG_DWORD")
If @ERROR = 0
? "Value written to the registry"
Endif

;UDF Function ArrayEnumKey

function arrayenumkey($regsubkey)
dim $retcode, $subkeycounter, $currentsubkey, $subkeyarray

if not keyexist($regsubkey)
$arrayenumkey=''
return
endif

$subkeycounter=0
do
$currentsubkey=enumkey($regsubkey,$subkeycounter)
if $currentsubkey<>259 and @ERROR=0
redim preserve $subkeyarray[$subkeycounter]
$subkeyarray[$subkeycounter]=$currentsubkey
$subkeycounter=$subkeycounter+1
endif
until $currentsubkey=259 or @ERROR

$arrayenumkey=$subkeyarray
endfunction

;UDF Function ArrayEnumValue

function arrayenumvalue($regsubkey)
dim $retcode, $valuecounter, $currentvalue, $valuearray

if not keyexist($regsubkey)
$arrayenumvalue=''
return
endif

$valuecounter=0
do
$currentvalue=enumvalue($regsubkey,$valuecounter)
if $currentvalue<>259 and @ERROR=0
redim preserve $valuearray[$valuecounter]
$valuearray[$valuecounter]=$currentvalue
$valuecounter=$valuecounter+1
endif
until $currentvalue=259 or @ERROR

$arrayenumvalue=$valuearray
endfunction



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 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.09 seconds in which 0.045 seconds were spent on a total of 12 queries. Zlib compression enabled.

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