I have a serial device connected via Bluetooth. It shows up nicely on COM4. I can communicate with it without a problem.
I want to make it simpler for the user to locate (ideally, I'll auto-detect it), so I want to find it by name. In the "Devices and Printers" list, I get a valid name, which is perfect. However, I can't seem to find that value programatically. I've tried a ton of stuff using the "ManagementObjectSearcher" class, including listing out all the Properties and SystemProperties, but no values match the name displayed in "Devices and Printers".
If I look in the "Device Manager" list, it just shows "Standard Serial over Bluetooth link (COM4)", which is not useful for identifying it, obviously.
So how the heck to I get the displayed name in the "Devices and Printers" list?
is this what you're looking for?
http://msdn.microsoft.com/en-us/library/system.drawing.printing.printersettings.installedprinters(v=vs.110).aspx
So, I found a solution. I grabbed the library from these guys:
http://32feet.codeplex.com/
Using that library, added these 2 lines:
BluetoothClient client = new BluetoothClient();
BluetoothDeviceInfo[] devices = client.DiscoverDevices();
That gave me the device "DeviceName" (the name I was after) and "DeviceAddress" (a chunk of the device id, basically).
I then queried the system using the "ManagementObjectSearcher", which gave me a list of COM ports and device IDs (System.Management namespace).
ConnectionOptions options = ProcessConnection.ProcessConnectionOptions();
ManagementScope connectionScope = ProcessConnection.ConnectionScope(Environment.MachineName, options, #"\root\CIMV2");
ObjectQuery objectQuery = new ObjectQuery("SELECT * FROM Win32_PnPEntity");
ManagementObjectSearcher comPortSearcher = new ManagementObjectSearcher(connectionScope, objectQuery);
...etc as I looped over the results, pulled out the COM ports, and so on
I mapped the device IDs from the "ManagementObject" values back to the "devices" list, merged the results, and ended up with something that had the name, device id, a flag indicating if it was a bluetooth device, and the "human readable" name from the bluetooth device, if it existed.
Painful, but it works fairly well. It's slow (client.DiscoverDevices() takes awhile), but that's survivable in my case.
Related
(Cross posted from https://forums.xamarin.com/discussion/116840/android-bluetooth-device-list-friendly-names)
I have this C# method for Android to get a list of paired Bluetooth devices:
public List<string> PairedDevices()
{
var adapter = BluetoothAdapter.DefaultAdapter;
var devices = new List<string>();
foreach (var bd in adapter.BondedDevices)
{
devices.Add(bd.Name);
}
return devices;
}
Which works fine, except I need the list to show the same name as what shows on the list of devices that is displayed to users in the Android Bluetooth settings. If the user has renamed a device, the new name is not listed in the "Name" property. Name still contains the original name of the device before the user renamed it.
I'm new to Android development. I'm seeing some references to ExtraDevice and ExtraName but am not sure if this is what I need or how to obtain it. Help?
PS: am using a Xamarin Forms PCL solution, and the above method is part of a Dependency class borrowed from here: https://acaliaro.wordpress.com/2017/02/07/connect-a-barcode-reader-to-a-xamarin-forms-app-via-bluetooth/.
#Salman-Nasseem basically answered this in their comment. It turns out my question is misguided. If the user renamed a bluetooth device, the actual device name has not changed.
I searched a lot but did not find any working codes getting SPD tables information via C#. Out there there are lots of softwares which get this info but HOW?
as shown in the image, for RAM devices, you can see Manufacture's name which can not be retrieve at all by WMI etc
If there is a DLL for using in C# will be perfect also
After some Research found this:
https://github.com/sapozhnikovay/SMBIOS
but it can not read table 17 to get memory device information.
Once I was researching about this, you need to get this information through SMBUS (not SMBIOS). But you need to create a driver (WDM in C/C++) to access this information.
Make sure you have added System.Management as a reference.
Here is a string that will return almost any information you want from the component :
private string getComponent(string hwClass, string syntax)
{
ManagementObjectSearcher mos = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM " + hwClass);
foreach (ManagementObject mj in mos.Get())
{
return Convert.ToString(mj[syntax]);
}
return null;
}
Using the string would look like this, say on a button click :
label1.Text = getComponent("Win32_PhysicalMemory", "SerialNumber");
I tested it and it returned a serial number, you can also look at the list of things you can put in like manufacturer, name, capacity etc.
I got all of this information from this YouTube video.
You can find all of the devices and their properties here (CPU, GPU, etc.)
In Windows Control Panel, you can find a list of network interfaces/connections which displays the following:
In the .NET framework these are represented in the NetworkInterface class (and found via NetworkInterface.GetAllNetworkInterfaces).
For reference, say I'm reading properties from the Ethernet interface - the NetworkInterface.Name property returns "Ethernet", the NetworkInterface.Description property returns "Realtek PCIe FE Family Controller".
However, nothing in the class seems to be able to get me the name of the network it's connected to (in this case "BELL024"). How would I go about getting that string? I have to know what network the interface is associated with, not just a list of the networks that exist.
It turns out information about each network is stored as a 'network profile' by Windows, storing it's name and other info like whether it's public or not. The name can be changed by users in the control panel, but in my situation that's not a problem.
The Windows API Code Pack from Microsoft contains the APIs necessary to get the collection of network profiles. As it contains a lot of bloat that I don't need, the bare minimum code to wrap the Windows API can be found here.
A collection of the network profiles can then be found like so:
//Get the networks that are currently connected to
var networks = NetworkListManager.GetNetworks(NetworkConnectivityLevels.Connected);
Each object in the collection represents a network profile and contains a collection of NetworkConnection objects. Each NetworkConnection object appears to be info about an interface's connection to the base network.
foreach(Network network in networks)
{
//Name property corresponds to the name I originally asked about
Console.WriteLine("[" + network.Name + "]");
Console.WriteLine("\t[NetworkConnections]");
foreach(NetworkConnection conn in network.Connections)
{
//Print network interface's GUID
Console.WriteLine("\t\t" + conn.AdapterId.ToString());
}
}
The NetworkConnection.AdapterId property is the same network interface GUID that the NetworkInterface.Id property knows.
So, you can determine what network an interface is connected to, by checking if one of the network's connections have the same ID as the interface. Note that they're represented differently, so you'll have to do a bit more work:
Both my Wi-Fi and Ethernet interfaces are connected to the BELL024 network in the above example.
On Windows 8 and Windows 2012 and higher you can query WMI class MSFT_NetConnectionProfile from root/StandardCimv2 namespace.
It shouldn't be too hard to convert this to C#.
Get-WmiObject -Namespace root/StandardCimv2 -Class MSFT_NetConnectionProfile | Format-Table InterfaceAlias, Name
You can use WMI to query for your network name. You can use this code as a sample:
ManagementScope oMs = new ManagementScope();
ObjectQuery oQuery =
new ObjectQuery("Select * From Win32_NetworkAdapter");
ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oMs, oQuery);
ManagementObjectCollection oReturnCollection = oSearcher.Get();
foreach (ManagementObject oReturn in oReturnCollection)
{
if (oReturn.Properties["NetConnectionID"].Value != null)
{
Console.WriteLine("Name : " + oReturn.Properties["NetConnectionID"].Value);
}
}
I want to use C# to retrieve the USB headset devices connected to PC. I tried the below solutions but didn't work:
Solution 1:
How to enumerate audio out devices in c#
I tried this but the device name appears as "(Generic USB Audio)" and not the actual name.
Solution 2:
How to get the default audio device?
Solution 3:
Detecting Audio Input & output devices connected to system
Solution 2 and Solution 3 gave me the below result:
The device name is truncated to 31 characters.
Eg: "Microphone (Sennheiser VOICE 689"
****Question: Is there any way I can get the complete name of the device?****
If you know it's an USB audio device, and assuming the driver is correctly written for the device, you could do:
foreach (ManagementObject drive in
new ManagementObjectSearcher(
"select Name from Win32_USBDevice where Service='usbaudio'").Get())
{
{
string s = drive["Name"].ToString();
// Continue
}
}
Addition
You're only getting 31 characters (technically 32) because the PInvoke to the native .DLLs use a char[32], so it can't return more than that; you won't get what you need from solution 1 & 2.
Also, I don't know why you can't use Win32_USBDevice, as I'm also using Win7 x64 and I'm having no problems. This link might help you.
Possible Alternate
You might be able to use the Win32_PnPEntity class:
foreach (ManagementObject drive in
new ManagementObjectSearcher(
"select Name from Win32_PnPEntity where Service='usbaudio'").Get())
{
{
string s = drive["Name"].ToString();
// Continue. Can look at Description, Caption, etc. too
}
}
Hi I am creating a desktop based application in windows using C#.
I have to show list of all available audio & video devices in 2 different combo boxes.
Selecting any device from combo box will set that particular device as the default one
I am using WMI.
Code to get list of available audio devices:
ManagementObjectSearcher mo =
new ManagementObjectSearcher("select * from Win32_SoundDevice");
foreach (ManagementObject soundDevice in mo.Get())
{
String deviceId = soundDevice.GetPropertyValue("DeviceId").ToString();
String name = soundDevice.GetPropertyValue("Name").ToString();
//saving the name and device id in array
}
if i try to set the device like this:
using (RegistryKey audioDeviceKey =
Registry.LocalMachine.OpenSubKey(audioDevicesReg
+ #"\" + audioDeviceList.SelectedText.ToString(), true)){}
i get exception :
System.Security.SecurityException occurred in mscorlib.dll
Now I have few questions:
1) How to set the selected device as the default audio device?
2) The array contains device name as : "High Definition audio device"
even when I have attached a headset.
3) I want the list as speaker,headset etc...How to get that?
can anybody point me in the right direction?
There is no documented mechanism for changing the default audio device.
That's because you're enumerating the physical audio devices, not the audio endpoints.
You want to use the IMMDeviceEnumerator API to enumerate the audio endpoints (speakers, etc).
Unfortunately there is no managed interop published by Microsoft for the IMMDeviceEnumerator API, you'll need to define your own (there are several definitions available on the internet).
I am answering too late to this question.. but it may be helpful for others.
Lync 2013 SDK provides DeviceManager class which list all the audio and video devices in collections
LyncClient.GetClient().DeviceManager.AudioDevices enumerates all the audio devices on the system
LyncClient.GetClient().DeviceManager.VideoDevices enumerates all the video devices on the system
So, one can set the device as:
LyncClient client = LyncClient.GetClient();
DeviceManager dm = client.DeviceManager;
dm.ActiveAudioDevice = (AudioDevice)dm.AudioDevices[0]; //or any other found after foreach
dm.ActiveVideoDevice = (VideoDevice)dm.VideoDevices[0]; //or any other found after foreach
HTH.