views:

77

answers:

2

Hello,

In our project, we've received a requirement where the the user is to be capable of enabling/disabling a COM Port / USB Port / Ethernet Port via our application's gui.

Is it possible to manipulate harware's enabled/disabled state programatically in C#?

+2  A: 

According to responses in this discussion thread, USB ports can be disabled by modifying a registry key. You can certainly do that in C#.

In general, this is really a Windows hardware question more than a C# question. C# does not have any special access or control of hardware - anything you want to do in C# will have to be done using the Windows OS APIs or configuration tools. Just about any unmanaged Windows API can be called from managed .NET code (C# or otherwise) using .NET's PInvoke.

dthorpe
A: 

Shot in the freaking dark here, if you can write a separate *.exe file or something to do it, you can call the *.exe file in C# code.

Checkout System.Diagnostics.Process API.

System.Diagnostics.Processp = new Systems.Diagnostics.Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.FileName = "cmd";
p.StartInfo.Arguments = "..."; // Your command and args here
p.StartInfo.RedirectStandartOutput = true;

p.Start();
p.WaitForExit();

Good Luck!

Robert