473,320 Members | 1,947 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Setting default gateway

Below is a snippet of code I am using. I want to set the IP, subnet
and default gateway of my local computer via code. However, when I do
it, I get a "not found" (error number 5) error on the default gateway
line.

Dim GateArray() As String = {"99.99.99.1"} 'Array

Dim inPar As ManagementBaseObject = Nothing
Dim outPar As ManagementBaseObject = Nothing
Dim blah As ManagementBaseObject()

inPar = mo.GetMethodParameters("EnableStatic")
inPar("IPAddress") = New String() {"99.99.99.2"}
inPar("SubnetMask") = New String() {"255.255.255.0"}
inPar("DefaultIPGateway") = LBound(GateArray) 'New String()
{"99.99.99.1"}

outPar = mo.InvokeMethod("EnableStatic", inPar, Nothing)

Any ideas what is wrong? I read that the default gateway is an array
so I am trying to find it the value that way but I get the same error
if I just use a string.

Thanks

Nov 21 '05 #1
8 4333
Correct me if I am wrong, but is are the number here not supposed to be Base
8 ( Where 99 would be illegal ? )

<go************@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Below is a snippet of code I am using. I want to set the IP, subnet
and default gateway of my local computer via code. However, when I do
it, I get a "not found" (error number 5) error on the default gateway
line.

Dim GateArray() As String = {"99.99.99.1"} 'Array

Dim inPar As ManagementBaseObject = Nothing
Dim outPar As ManagementBaseObject = Nothing
Dim blah As ManagementBaseObject()

inPar = mo.GetMethodParameters("EnableStatic")
inPar("IPAddress") = New String() {"99.99.99.2"}
inPar("SubnetMask") = New String() {"255.255.255.0"}
inPar("DefaultIPGateway") = LBound(GateArray) 'New String()
{"99.99.99.1"}

outPar = mo.InvokeMethod("EnableStatic", inPar, Nothing)

Any ideas what is wrong? I read that the default gateway is an array
so I am trying to find it the value that way but I get the same error
if I just use a string.

Thanks

Nov 21 '05 #2
If I try it with the IP 1.1.1.1 it gives the same error.

Nov 21 '05 #3
OK, silly question here. Does this IP address exists ?, if not are you
suprised at the error ?
<go************@hotmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
If I try it with the IP 1.1.1.1 it gives the same error.

Nov 21 '05 #4
Thanks for responding.

That won't matter. When setting a static IP you can add whatever you
want. As far as I can tell this has to be a problem with the code.

Nov 21 '05 #5
what does this method do and is this the actual line which returns the
error?

inPar("DefaultIPGateway") = LBound(GateArray) 'New String()

<go************@hotmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
Thanks for responding.

That won't matter. When setting a static IP you can add whatever you
want. As far as I can tell this has to be a problem with the code.

Nov 21 '05 #6

Mr Newbie wrote:
what does this method do and is this the actual line which returns the
error?

inPar("DefaultIPGateway") = LBound(GateArray) 'New String()

<go************@hotmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
Thanks for responding.

That won't matter. When setting a static IP you can add whatever you
want. As far as I can tell this has to be a problem with the code.


This line changes (or should) the default gateway. This is where i get
the "not found" error. If i comment out this line then my IP and
subnet mask is changed by the code. So, either "DefaultIPGateway" is
incorrect, or something is wrong elsewhere.

Now, using the following code, i can expose all the property names:

For Each moa As ManagementBaseObject In objCollection
MsgBox(moa.GetText(TextFormat.Mof))
Next

And, DefaultIPGateway is one of them. So I have no idea what is wrong.
Has anyone else beenable to change their gateway via code?????

Nov 21 '05 #7
Well, have you tried setting the IP address to 127.0.0.0 ( Your local
machine ) just to see if it is looking for a valip IP address ??

<go************@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...

Mr Newbie wrote:
what does this method do and is this the actual line which returns the
error?

inPar("DefaultIPGateway") = LBound(GateArray) 'New String()

<go************@hotmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
> Thanks for responding.
>
> That won't matter. When setting a static IP you can add whatever you
> want. As far as I can tell this has to be a problem with the code.
>


This line changes (or should) the default gateway. This is where i get
the "not found" error. If i comment out this line then my IP and
subnet mask is changed by the code. So, either "DefaultIPGateway" is
incorrect, or something is wrong elsewhere.

Now, using the following code, i can expose all the property names:

For Each moa As ManagementBaseObject In objCollection
MsgBox(moa.GetText(TextFormat.Mof))
Next

And, DefaultIPGateway is one of them. So I have no idea what is wrong.
Has anyone else beenable to change their gateway via code?????

Nov 21 '05 #8
This works. My code only works if I comment out the Default Gateway
line. As far as I can tell, this is a big in the WMI/VB connection.
So I guess it is just not going to be possible.

Nov 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Nick Gage | last post by:
Hello, I am trying to set the IP Address, Default Gateway and Subnet mask of my WinXp systems programatically in VB/VB.NET. I cannot figure out how to do it. Can anyone assist? Thanks! ...
0
by: jonhrs | last post by:
Hi, I am trying to find/write some vb.net code which will attain the default gateway of a server. This app will access a cross section of server platforms from NT4.0 server to Windows 2003 and...
0
by: J | last post by:
Hi, Is there a simple method to attain the default gateway on a server with VB.net without using WMI? Bearing in mind that the servers the application will be run on will have different makes of...
0
by: pmclinn | last post by:
How do you grab a users default gateway? Connection-specific DNS Suffix . : ksde.local IP Address. . . . . . . . . . . . : 10.117.161.108 Subnet Mask . . . . . . . . . . . : 255.255.248.0...
0
by: Rocky | last post by:
How can I set a static ip address, subnet mask, default gateway, dns servers, and dns suffix via a asp.net webform using vb.net code on a local machine?
1
by: Ezz | last post by:
I have an interesting problem...and its one of those where I know what I want but don't know how to ask it =) I have an eCommerce application that uses Paypal for its payment gateway. It is an...
4
by: mitymouse | last post by:
I am fairly familiar with scripting dos commands and that's about it. I remember some syntax and whatnot from a few programming classes I've taken but I don't remember any of the modules or functions...
18
by: Grant Edwards | last post by:
Could whoever is responsible for the gateway that is grabbing my postings off of Usenet and e-mailing them out please fix the headers in the mail messages so that I don't get the bounce messages?...
0
by: siddhartha92k | last post by:
sir , i know very well that how can we give ip address & dns address to a syatem . but i want to know how can we give default gateway by a command in windows xp. please tell me.
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.