#26028 - 2002-07-26 09:52 PM
WMI in KIX
|
Urooj
Fresh Scripter
Registered: 2002-07-19
Posts: 15
Loc: New York
|
Afternoon Anyone know how I can modify the following WMI script so it can be used in KIX
strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colNetAdapters = objWMIService.ExecQuery _ ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE") strGateway = Array("192.168.1.100") strGatewayMetric = Array(1) For Each objNetAdapter in colNetAdapters errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric) Next
From what I read on the board here does this sound right
$strComputer = "." $ObjWMIservice = GetObject("winmgmts:\\"+$strComputer+"\root\cimv2") $colNetAdapters = $objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE") $Gateway = ("$NDG") $GatewayMetric = (1) For Each $objNetAdapter in $colNetAdapters errGateways = objNetAdapter.SetGateways($Gateway, $Gatewaymetric) Next
Exit1
I don't want to use the array function in the above script I would rather use a kix Variable to update the Default gateway instead. Will that work ?
|
|
Top
|
|
|
|
#26029 - 2002-07-26 10:27 PM
Re: WMI in KIX
|
Chris S.
MM club member
   
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
When translating from WSH/VBScript to KiX don't forget your $'s for your variables. You forgot some...
code:
$strComputer = "." $ObjWMIservice = GetObject("winmgmts:\\"+$strComputer+"\root\cimv2") $colNetAdapters = $objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE") $Gateway = $NDG $GatewayMetric = 1 For Each $objNetAdapter in $colNetAdapters $errGateways = $objNetAdapter.SetGateways($Gateway, $Gatewaymetric) Next
Exit1
Not sure what you're doing with $Gateway and $GatewayMetric, but putting parens and "" around vars isn't KiX syntax.
|
|
Top
|
|
|
|
#26031 - 2002-07-29 04:54 PM
Re: WMI in KIX
|
Urooj
Fresh Scripter
Registered: 2002-07-19
Posts: 15
Loc: New York
|
Thanks for the translation. Lonkero is correct I was thinking of using Wmi on NT 4 And W2k As well as Winxp to make the desired changes. I removed the two variables that Chris stated didn't make sense. Here is what I think my final script would look like. code:
Break On $hklm='HKEY_LOCAL_MACHINE' Select Case InStr(@PRODUCTTYPE,'Windows NT') $OS_SHORT='WinNT' Case InStr(@PRODUCTTYPE,'Windows 2000') $OS_SHORT='Win2K' Case InStr(@PRODUCTTYPE,'Windows XP') $OS_SHORT='WinXP' Case 1 Return EndSelect $tempfile = "%temp%\ipconfig.tmp"
Shell '%comspec% /c ipconfig /all | find /i "Subnet Mask" >"$tempfile" 2>nul'
If Open(1,$tempfile) = 0 $line = ReadLine(1) $SBNM = Ltrim(SubStr($line,InStr($line,":")+1)) ?"Subnet Mask=" $SBNM EndIf
$IpPart1 = Ltrim(SubStr(@IPADDRESS0, 1, 4)) $IpPart2 = Ltrim(SubStr(@IPADDRESS0, 5, 4)) $IpPart3 = Ltrim(SubStr(@IPADDRESS0, 9, 4)) $IpPart4 = Ltrim(SubStr(@IPADDRESS0, 13, 3)) $IPAddressComplete = $IpPart1 + $IpPart2 + $IpPart3 + $IpPart4 $IPSUBN=$IpPart1 + $IpPart2 + $IpPart3 $Octet = Val(SubStr(@ipaddress0,13,3))
If $SBNM Select Case $SBNM='255.255.255.0' $NDG=$IPSUBN + '252' $NDG1=$IPSUBN + '251' Case $SBNM='255.255.255.128' Select Case $Octet<=126 $NDG=$IPSUBN + '124' $NDG1=$IPSUBN + '123' Case $Octet<=254 $NDG=$IPSUBN + '251' $NDG1=$IPSUBN + '252' EndSelect Case $SBNM='255.255.255.192' Select Case $Octet<=62 $NDG=$IPSUBN + '60' $NDG1=$IPSUBN + '59' Case $Octet<=126 $NDG=$IPSUBN + '124' $NDG1=$IPSUBN + '123' Case $Octet<=190 $NDG=$IPSUBN + '188' $NDG1=$IPSUBN + '187' Case $Octet<=254 $NDG=$IPSUBN + '251' $NDG1=$IPSUBN + '252' EndSelect Case $SBNM='255.255.255.224' ; nothing EndSelectEndif
?" Your default gateway is address is "$NDG ?" Your default gateway is address is "$NDG1 ? " Your Os is "@PRODUCTTYPE Select
Case $OS_SHORT='WinNT'
Case $OS_SHORT='Win2K' ;netsh interface ip Set adrress "@ipaddress0" "$SBNM" "$NDG" Case $OS_SHORT='WinXP' ;netsh interface ip Set adrress "@ipaddress0" "$SBNM $NDG"
$strComputer = "." $ObjWMIservice = GetObject("winmgmts:\\"+$strComputer+"\root\cimv2") $colNetAdapters = $objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE") For Each $objNetAdapter in $colNetAdapters $errGateways = $objNetAdapter.SetGateways($NDG, 1) Next Exit1
I put in the netsh command maybe if the WMI didn't work I could use the netsh command to set the desired gateways. Would the above script make the desired changes on the machines. Please let me know thanks
|
|
Top
|
|
|
|
#26033 - 2002-07-29 06:47 PM
Re: WMI in KIX
|
Urooj
Fresh Scripter
Registered: 2002-07-19
Posts: 15
Loc: New York
|
Yeah I know because I don't know how to set multiple gateways using WMI would you repeat the command or would you separate the gateways with some symnbol , : " " | how would you set one interface to have 2 gatways. I don't know WMI that well Sorry .
|
|
Top
|
|
|
|
#26035 - 2002-07-30 10:57 PM
Re: WMI in KIX
|
Urooj
Fresh Scripter
Registered: 2002-07-19
Posts: 15
Loc: New York
|
I tried the updated script and the WMI part causes a Error. The application just ends with the machine stating that there was a serious problem. Seems like the last part which sets the default gateway needs some work. Instead of WMI anyone have any quick ways to set the gateways . Thanks
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 823 anonymous users online.
|
|
|