Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 28th, 2005, 9:14 PM   #1
maure5
Newbie
 
Join Date: Mar 2005
Posts: 1
Rep Power: 0 maure5 is on a distinguished road
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.
maure5 is offline   Reply With Quote
Old Apr 1st, 2005, 8:47 AM   #2
mackenga
Professional Programmer
 
Join Date: Mar 2005
Location: Glasgow, Scotland
Posts: 317
Rep Power: 4 mackenga is on a distinguished road
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.
mackenga is offline   Reply With Quote
Old Apr 1st, 2005, 9:57 AM   #3
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Old Apr 1st, 2005, 2:40 PM   #4
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
system("ipconfig /release");

Does the same thing as IR's code but a little simpler.
tempest is offline   Reply With Quote
Old Apr 3rd, 2005, 9:03 AM   #5
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:11 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC