![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Mar 2005
Posts: 1
Rep Power: 0
![]() |
Help disabling network interface from code
Hello,
I've been trying to disable the network interface card from within the code in C using Windows. Something like: ifconfig eth0 down, in linux. Is there a way to do this from code in Windows? Thanks a lot. |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: Mar 2005
Location: Glasgow, Scotland
Posts: 317
Rep Power: 4
![]() |
Seems nobody here's picking this one up, so although I don't have much to contribute (since I'm an ardent Unix man), I'll say the most helpful thing I know: if there's a way to do this conveniently from code (and I wouldn't be surprised if there wasn't; I fear programming for Windows, I truly do), I suspect it's a Win32 API thing. If not, I'm not sure, and this might be a wrong turn, but maybe doing something with rundll (calling it with system()) is the answer; I don't really know, but I remember this does allow you to shut down Windows machines with:
rundll user,exitwindows or something similar. I hope this has been at least a little helpful, but like I say, I'm really not a Windows man so I'm not sure and I apologise if I've sent you down any blind alleys. ![]() |
|
|
|
|
|
#3 |
|
Programming Guru
![]() ![]() ![]() |
not sure about C++ (may want to Google for it)...
Although in WMI ... You cannot enable/disable the NIC, but you can disable the network connection. (haven't tested) strComputer = "." Set objWMIService = GetObject( _ "winmgmts:\\" & strComputer & "\root\cimv2") Set colNetCards = objWMIService.ExecQuery _ ("Select * From Win32_NetworkAdapterConfiguration " _ & "Where IPEnabled = True") For Each objNetCard in colNetCards objNetCard.ReleaseDHCPLease() Next An extensive list of WMI scripts are available here: http://msdn.microsoft.com/library/de...asp?frame=true
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#4 |
|
Programming Guru
![]() |
system("ipconfig /release");
Does the same thing as IR's code but a little simpler. |
|
|
|
|
|
#5 |
|
Programming Guru
![]() ![]() ![]() |
Now where is the fun in simplicity?
j/k
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|