By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,928 Members | 1,173 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,928 IT Pros & Developers. It's quick & easy.

Setting default gateway

P: n/a
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
Share this Question
Share on Google+
8 Replies


P: n/a
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

P: n/a
If I try it with the IP 1.1.1.1 it gives the same error.

Nov 21 '05 #3

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.