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

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.

Related

Getting Wifi RSSI or signal strength using WlanAPI and IpHlpAPI [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 24 days ago.
Improve this question
I'm trying to recreate the functionality of the wifi icon inside the Windows task bar using this library and C#.
https://github.com/dahall/Vanara
To get the current network interface I am calling GetBestInterface from IpHlpAPI and it seems to be returning the right index. However I'm struggling on how to get the RSSI or signal strength value of the wifi network that's attached to this interface. Using this data I could recreate the wifi icon with 1 bars, 2 bars, 3 bars, ect..
Using WlanAPI I can call WlanGetAvailableNetworkList which returns a list that has the signal strength value for each network. There doesn't seem to be any data to connect these two things, so obviously I'm missing something.
Anyone have any ideas on the approach I should take?
You could try to use WlanQueryInterface function with wlan_intf_opcode_current_connection to query various parameters of a specified interface. You could get a percentage value that represents the signal quality of the network from WLAN_ASSOCIATION_ATTRIBUTES structure.

How to get number of cores of VM in azure [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am trying to find an api or Microsoft inbuilt functions which can help me retrieve the number of cores in a particular VM
Unfortunately there's no straight forward way to get this information.
As far as REST API go, you would need to make 2 API calls:
Get Virtual Machine: First API you would need to call is get the details about your VM using Virtual Machines - Get. The properties that are of interest to you are the location of the VM and VM Size Type.
Get Resource SKU: This is the next API you would need to call using Resource Skus - List. This will give you the details about all the VM SKUs. Now this is going to be a very long list and unfortunately very limited filtering capability is available (at least at the time of answering this question). Only filtering capability available is that by location (that's why getting location information in the 1st step is important).
Once you get the list of all available SKUs, you will need to first filter out by resourceTypes where the value is virtualMachines and name where the value is the VM Size Type obtained in the 1st step.
Once you do that, the number of cores can be obtained in vCPUs attribute under capabilities property.
Here you go:
GET https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/vmSizes?api-version=2019-07-01
edit: if you need it for the running VM you need to get the hardware profile of the VM and use that first call to determine the number of cores. But its kinda static, so you might as well hardcore the results

How to determine on which monitor will my applications run? c# [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
On my computer I have two monitors(regular one and usb elo display) and I wont my application only opens on usb display...any idea?
You have to use Screen class. It provides information about number of screens, which one is a primary screen etc. It also has the following method Screen.FromControl. It returns information about the screen that contains the largest part of the application. You can run it on the startup. If the method returns usb display then you should move the application to the second screen. See also this question.
Here is an example that verifies if the current screen is the primary one. If not it finds it and changes the location of the application based on the bounds of the found primary screen. You can also use DeviceName to determine if the current screen is the correct one.
var current = Screen.FromControl(this);
if (!current.Primary) //you can also use device name e.g." s.DeviceName.Contains("...")
{
var primary = Screen.AllScreens.Single(s => s.Primary);
SetBounds(primary.Bounds.Left, primary.Bounds.Top, Width, Height);
}
You should get the rectangle of required monitor first:
Rectangle rect = Screen.AllScreens[n].WorkingArea; //n stands for the index of monitor you'd like to use
Then you should invoke the Windows API SetWindowPos to move it via Process.MainWindowHandle.

how to make real time code in C# [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 8 years ago.
Improve this question
I want to read sms from my GSM modem.
I wrote C# code.
This code run when I click start button.
I want to my program read sms when received, not click button.
thanks.
Your program is keyed to activate when you press a button, some method is called. You need to call this method when SMS data is received instead. This could be done using threads (SMS thread and main thread showing data) although it could just as easily be done using a cycle. In pseudo code:
while (don't quit) {
display page;
check for sms data;
sleep for small time to allow other OS programs to run also;
}
This is a "tight loop" and can use excessive amounts of CPU time depending on the code of the actual steps. For a tight program loop one simple method is to apply some sort of sleep method.
There are other ways to do the same thing, visitor pattern could probably be used, threads, etc...
It seems that you are only lacking the cycle. Your programs is probably more like:
while (don't quit) {
display page.
wait for button press.
}
although that flow wouldn't be obviously apparent at first glance without studying your program flow.
If you are using triggers (the button press is probably a trigger) you can trigger on a timer that fires as often as you want (100ms, 1 second, whatever) that checks for SMS data when fired, if there is SMS data it updates the form.
Many, many ways to do this. A quick Google for "program flow" doesn't find any useful links at first glance that would explain the many ways you could do this. Perhaps looking at other's code would help. I've often searched open source repositories for code I could look at to see how someone else did something.

Programmatically enabling/disabling hardware device [duplicate]

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

Categories