Programmatically enabling/disabling hardware device [duplicate] - c#

This question already has answers here:
Closed 12 years ago.
Possible Duplicates:
[.NET] How do I disable a system device?
Win32 API function to programatically enable/disable device
Is there a way, in C#, to programmatically disable and re-enable a device? I'm looking for essentially the same functionality that occurs when you go into device manager and right click on a device and disable or enable it. How can I do this in C#?

Take a look at net-how-do-i-disable-a-system-device.

According to this link: http://bytes.com/topic/c-sharp/answers/513855-can-i-use-wmi-c-disable-enable-device
You need to interface with CfgMgr32
(Win32 API) to do this.
My first thought was to look at WMI but it's not there.
DevCon, which comes with the Device Drive Toolkit, provides a CLI to do this.
http://msdn.microsoft.com/en-us/library/ff541193(VS.85).aspx

Related

How is the NetworkAdapter.NetworkAdapterID generated in UWP? [duplicate]

This question already has answers here:
C# - Get mac address in Universal Apps
(3 answers)
Closed 3 years ago.
I wanted to use the MAC Address of the device as a unique identifier, but this isn't exposed in the UWP API. The closest thing I can find is:
hostname.IPInformation.NetworkAdapter.NetworkAdapterId;
It seems to be the same value (after app restart and PC restart) but I don't know if it's robustly persistent. The docs don't seem to say, does anyone know what this ID actually consists of? Is it safe to use this as a reliable means of device identification?
If not, can someone recommend something?
Many thanks,
Peter
How is the NetworkAdapter.NetworkAdapterID generated in UWP
Derive from this case,
No, the NetworkAdapterId value is a GUID and has nothing to do with the machine MAC address. You cannot get the MAC adress of the computer through WinRT APIs exposed for the Windows Store application type.

How to simulate android back button press programmatically in Unity with C# [duplicate]

This question already has an answer here:
How to access mobiles back button in unity for android applications
(1 answer)
Closed 4 years ago.
I have done the same thing in android natively by simply calling onBackPressed().
I've been trying to do the same thing in Unity with c#. there are classes like Input that handles inputs but does not have access to android's back button.
I've also seen touch simulators and whatnots but I'm looking for something as simple as calling this.onBackPressed().
Please note that I'm not looking to capture back button press, I want to press back button from my code.
I've been using this.
if(Input.GetKeyDown(KeyCode.Escape))

How to turn wireless radio on/off in Windows? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm looking for an API to programmatically toggle a wireless radio on and off in Windows, just like the following Windows 10 UI element does:
Need to toggle on/off Wi-Fi, Bluetooth, or mobile broadband
For Windows 7, 8 and 10
This is NOT a phone
C#/.NET4.5 would be ideal, but C++/Win32 would work too
For Windows 10, you can use the Radio Manager APIs to control different radio states. You can find the full sample apps here (both C# and C++).
First you need to get access to all of the system radios. This must be called in a UI thread:
var accessLevel = await Radio.RequestAccessAsync();
Then, you can find all radios on the system (the sample describes other ways to access the radios):
var radios = await Radio.GetRadiosAsync();
Given a radio object, you can then change state by the following:
Radio radio = SOME_RADIO;
radio.StateChanged = Radio_StateChangedCallback; // Called when the radio state completes the change
radio.SetStateAsync(RadioState.On); // Or RadioState.Off
So in general what you need to do is to enumerate the network adapters (filter out Wireless, Bluetooth and Mobile Broadband) and toggle their state?
No wonders that there are 3 close votes since SO is full of related questions and answers:
This demonstrates C# + WMI
This demonstrates C++ + WINAPI Device Installation API
One of those should be a fair starting point to put together what you need.
Well I know you can manipulate the wireless connection with
netsh interface set interface name="Local Area Connection" via cmd line.
So maybe in c# you could do a Process.Start("netsh", "set name=\"Local Area Connection\""); to change the wifi settings. I'm sure you could download a bluetooth cmd line utility and do something similar with that.
I'll be able to test later when I get on my windows machine, but I can't right now, hopefully this helps.

Windows phone 8 - Application getting event fired from incoming call [duplicate]

This question already has answers here:
Windows Phone 8 support to capture SMS or a incoming call?
(3 answers)
Closed 8 years ago.
After looking at those links:
control-information-on-call-windows-phone-8
call-history-for-windows-phone-8
it seems that there is no way to do drop a call or to get calls history from an application using Windows Phone.
I would need to get a notification when an incoming call is starting/ending on Windows Phone 8.
Is is possible to do that even if I am not an OEM? If yes, what is the API to use?
For security reasons microsoft do not want to allow the apps to get incomming calls info, call history or message data. so a straight no on that.
No.
Reason: Security and Privacy of customer.

How to use a FileSystemWatcher for monitoring new drives [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Looking for C# code for detecting removable drive (usb flash)
How could the System.IO.FileSystemWatcher class be used to detect drives (e.g. F:) being connected/disconnected under windows? If this is not possible, what other event driven ways are possible (other than polling DriveInfo.GetDrives())?
Thanks in advance.
Take a look at this:
http://www.codeproject.com/KB/system/DriveDetector.aspx
I wrote a powershell module that uses a System.Management.ManagementEventWatcher and the WMI class Win32_VolumeChangedEvent to surface new events that you may register for within powershell covering device removal, addition etc. You should be able to figure out the relevant plumbing from this blog post of mine:
http://www.nivot.org/nivot2/post/2008/08/16/AutoMountunmountNewPSDrivesForRemovableDrivesAndNetworkSharesInPowerShellV2.aspx
You should be able to wire up an event for new drives in less than ten lines of C# using the methods I use in the above script.
Hope this helps.

Categories