Can hardware be enabled / disabled programmatically?

In our project, we got a requirement that the user should be able to enable / disable the COM port / USB port / Ethernet port through our gui app.

Is it possible to programmatically control the enable / disable status of harware in C #?

+2


source to share


2 answers


As per the answers in this thread of discussion , USB ports can be disabled by modifying a registry key. You can do it in C #.



In general, this is actually a Windows hardware issue, not a C # issue. C # does not have any special access or hardware control - anything you want to do in C # must be done using the Windows API or configuration tools. Almost any unmanaged Windows API can be called from managed .NET code (C # or otherwise) using .NET PInvoke.

+3


source


Snapshot in the dark here, if you can write a separate * .exe file or something like that, 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!

-1


source







All Articles