开发者

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 P开发者_StackOverflow社区ort / USB Port / Ethernet Port via our application's gui.

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


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.


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜