Maciek
Maciek

Reputation: 19893

Is it possible to programatically enable/disable hardware?

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#?

Upvotes: 2

Views: 863

Answers (2)

Robert
Robert

Reputation: 265

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!

Upvotes: -1

dthorpe
dthorpe

Reputation: 36092

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.

Upvotes: 3

Related Questions