Custom Shell and Network Settings

  • Thread starter Quentin Liedtke
  • Start date
Q

Quentin Liedtke

For those of you out there that are using custom shells and user editable
network settings, how are you doing it? My situation is that our users
should be able to adjust their network settings (DHCP on/off, set static IP
and set subnet mask) and I have yet to find a solution that is always
reliable.

Here's the possible solutions that I have researched:
1. IP Helper API using AddIPAddress and DeleteIPAddress: Only adds an IP
address to the adapter, will not change the current one.

2. WMI using Win32_NetworkAdapterConfiguration: Haven't tried this yet, but
it seems that I will have to add a lot of code to get it working, not to
mention having to include many more components to add support for WMI.

3. netsh: I have had some success with using WinExec and manufacturing the
command line based on the information I get from the user. The problem is
that it's not a synchronous call so I have no idea when the command has
completed.

4. DhcpNotifyConfigChange: haven't tried this yet, but it looks like it will
do what I want it to do. The problem with DhcpNotifyConfigChange is that
it's an undocumented API.

5. Editing the registry: apparently this works, but you have to reboot the
computer for the change to take affect. I would prefer to not have to go
back to the days of rebooting to see if my network settings worked.


Anyone out there solve this issue?
Quentin.
 
S

Slobodan Brcin \(eMVP\)

Quentin,
Here's the possible solutions that I have researched:
1. IP Helper API using AddIPAddress and DeleteIPAddress: Only adds an IP
address to the adapter, will not change the current one.

And other net api functions as well. This is the best aproach if you have
some time to play with them.
2. WMI using Win32_NetworkAdapterConfiguration: Haven't tried this yet,
but it seems that I will have to add a lot of code to get it working, not
to mention having to include many more components to add support for WMI.

Like you said adding unecesary components that you don't need for supporting
thing that you currently know nothing abot is not a good direction to invest
your time.
3. netsh: I have had some success with using WinExec and manufacturing the
command line based on the information I get from the user. The problem is
that it's not a synchronous call so I have no idea when the command has
completed.

Use CreateProcess this will allow you to control all programs that you start
in way that you want and you will know when they terminate since you can
examine returned handles.
4. DhcpNotifyConfigChange: haven't tried this yet, but it looks like it
will do what I want it to do. The problem with DhcpNotifyConfigChange is
that it's an undocumented API.

Do not know anything about this one.
5. Editing the registry: apparently this works, but you have to reboot the
computer for the change to take affect. I would prefer to not have to go
back to the days of rebooting to see if my network settings worked.

This is also good aproach for some cases.

Regards,
Slobodan
 
K

KM

Quentin,

Usually it is very easy to change network settings with netsh. The netsh support scripting (trivial but enough for our needs).
Especially things like switching to static IP, disabling/enabling DHCP.
Btw, I've never heard of a synchronous call to enable DHCP and get new IP address. Due to DHCP handshake protocol nature it is
asynchronous. (You can wait until your device receives the IP but this is different).

(Don't use WinExec, it is legacy of Win16. Use CreateProcess and wait on the created process handle)

WMI definitely provides all you need but it is heavy, no doubt.

IP Helper API and other Net APIs are the best way to go with since you will have maximum flexibility and control. But it will
require mush more coding than, say, netsh approach.
 
Q

Quentin Liedtke

1. IP Helper API using AddIPAddress and DeleteIPAddress: Only adds an IP
And other net api functions as well. This is the best aproach if you have
some time to play with them.

Do you know what these api functions are because I have been unable to find
them. As far as I can tell, you can only add IP addresses and not change
them. Also, I have read that any IP address that you add is temporary until
reboot. DeleteIPAddress will only work on an IP that you've added using
AddIPAddress.
Use CreateProcess this will allow you to control all programs that you
start in way that you want and you will know when they terminate since you
can examine returned handles.

Good idea, I will try that instead of the legacy WinExec call if I decide to
go the netsh route (which it is looking like I will have to).

Quentin.
 
S

Slobodan Brcin \(eMVP\)

Quentin,

Use Dependency Walker on netsh and you will see functions that it uses. Most
functions from iphlpapi.dll are undocumented and you will need to figure
them out :-(

Regards,
Slobodan
 
Q

Quentin Liedtke

IP Helper API and other Net APIs are the best way to go with since you
will have maximum flexibility and control. But it will
require mush more coding than, say, netsh approach.

I would love to go this way but I cannot find any function in IP Helper API
that will actually set an adapter's IP address. As far as I can tell you
can only add a temporary IP address to an adapter (temporary until the next
reboot.)

Do you know which functions I should look at specifically?

Quentin.
 
K

KM

Quentin,

Well.. I must say that I have implemented such feature in my app(s) through registry. Basically I search for required adapter and
switched between DHCP and static IP changing Parameters on that adapter.

There are quite a few useful undocumented functions of IP Helper. E.g., SetAdapterIpAddress which will allow you to replace ip
address, mask, gateway.
E.g., make a call like this: SetAdapterIpAddress( adapterGUID, 0, inet_addr("192.168.1.2"), inet_addr("255.255.255.0"),
inet_addr("192.168.1.100") );
But you need to know the adapter GUID anyway. YOU can get it enumarating subkeys under [HK\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\NetworkCards] key.

For the DHCP (if enabled), you can use IpRenewAddress to renew the address.
 
Q

Quentin Liedtke

KM said:
Quentin,

Well.. I must say that I have implemented such feature in my app(s)
through registry. Basically I search for required adapter and
switched between DHCP and static IP changing Parameters on that adapter.

There are quite a few useful undocumented functions of IP Helper. E.g.,
SetAdapterIpAddress which will allow you to replace ip
address, mask, gateway.
E.g., make a call like this: SetAdapterIpAddress( adapterGUID, 0,
inet_addr("192.168.1.2"), inet_addr("255.255.255.0"),
inet_addr("192.168.1.100") );
But you need to know the adapter GUID anyway. YOU can get it enumarating
subkeys under [HK\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\NetworkCards] key.

For the DHCP (if enabled), you can use IpRenewAddress to renew the
address.

Thanks KM! I just opened netsh in Dependency Walker and I see the function
that you are talking about, the only thing I don't understand is how you
figured out its arguments? I'd like to know so that I can use such tricks
for future problems I may run into.

Quentin.
 
K

KM

Quentin,

We are entering area which is outside of this NG purpose.
Basically knowing how undocumented functions work is called hacking. Debugers, PE dump utilities, disassemblers, common sense and
ASM/C knowledge are friends of a hacker.

For this particular function call I have just made a search on Google a long time ago and found some interesting threads. I'd send
you a link but it is localized (non English page) so hope you can read in Russian. Well... frankly, the code part there is in C/C++
so you should be able to read it anyway :):
http://forum.vingrad.ru/index.php?s...db4&showtopic=11857&st=15&unread=#entry246547.

--
Regards,
KM, BSquare Corp.

KM said:
Quentin,

Well.. I must say that I have implemented such feature in my app(s)
through registry. Basically I search for required adapter and
switched between DHCP and static IP changing Parameters on that adapter.

There are quite a few useful undocumented functions of IP Helper. E.g.,
SetAdapterIpAddress which will allow you to replace ip
address, mask, gateway.
E.g., make a call like this: SetAdapterIpAddress( adapterGUID, 0,
inet_addr("192.168.1.2"), inet_addr("255.255.255.0"),
inet_addr("192.168.1.100") );
But you need to know the adapter GUID anyway. YOU can get it enumarating
subkeys under [HK\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\NetworkCards] key.

For the DHCP (if enabled), you can use IpRenewAddress to renew the
address.

Thanks KM! I just opened netsh in Dependency Walker and I see the function
that you are talking about, the only thing I don't understand is how you
figured out its arguments? I'd like to know so that I can use such tricks
for future problems I may run into.

Quentin.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top