Roger Pace
Roger Pace

Reputation: 1

C++ example to disable a network adapter in Windows server 2008 r2

On Windows Server 2008 R2 we have multiple network adapters. We have a legacy program that has to bind with a particular network adapter. It does not always select the correct one. I need to disable the incorrect network adapters, then start the program and then enable the network adapters again. I am having trouble disabling the adapters. Could someone provide a C++ example? The compiler is Embarcadero C++ XE2.

Upvotes: 0

Views: 2824

Answers (3)

King Tyson
King Tyson

Reputation: 1

You can use c++ to run a script Like a ps1 script

Upvotes: -1

Entretoize
Entretoize

Reputation: 2251

Thanks to Pablo, this is the c++ command:

HINSTANCE retVal = ShellExecute(NULL, "open", "cmd", "/c netsh interface set interface \"Local Area Connection\" ENABLED", NULL, SW_NORMAL);

Upvotes: -1

titer1_on_the_way
titer1_on_the_way

Reputation: 9

I think it is not necessary to use c++. Batch file can do it.

The file is as below:

To disable the interface run:

netsh interface set interface “Local Area Connection” DISABLED

To enable the interface run:

netsh interface set interface “Local Area Connection” ENABLED

Upvotes: 0

Related Questions