I have an application that is calling NetworkOperatorTetheringManager.GetTetheringCapabilityFromConnectionProfile() but it's not returning what I believe it should.
According to Microsoft's site this method should give me a TetheringCapability enum
to indicate the tethering capabilities of a network account.
This, I assume, ties in with the "Windows Mobile Hotspot" functionality in Windows 10.
However if I run this on one computer, I get a result of TetheringCapability.Enabled but on this computer, I believe it should be disabled, because on the Mobile Hotspot screen, everything is greyed out and there is a message at the top saying
Some of these settings are hidden or managed by your organisation.
... and a call to StartTetheringAsync() fails. (TetheringOperationStatus is "Unknown" and AdditionalErrorMessage is blank)
But then on another computer, I get a result of TetheringCapability.DisabledByHardwareLimitation even though on this computer, the Windows mobile hotspot screen allows turning on and off and StartTetheringAsync() successfully turns it on!
Am I misinterpreting the purpose of this function (GetTetheringCapabilityFromConnectionProfile()) and if not, why is it giving the wrong result?
var profile = NetworkInformation.GetInternetConnectionProfile();
if (profile == null)
{
Console.WriteLine("No Internet connection found");
return false;
}
var capability = NetworkOperatorTetheringManager.GetTetheringCapabilityFromConnectionProfile(profile);
Console.WriteLine("Tethering Capability: {0}", capability.ToString());
Related
I am struggling with finding a way to get a list of shares on a Remote Server. The server is a Linux based videoserver that I have no access to what so ever in terms of changing settings etc.
My issue is that after starting the servers client manager software on my local computer, I can list all Shares in a normal file explorer window by just entering \\MyServerName as the path
But all tries to access the list of shares via net view or C# DirectoryInfo(..) returns Error 53.
I have tried all ideas I have found on line:
Adding the login in the local machine user account vault
net use \\MyServerName /user:MyID MyPassword
PowerShell Get-WmiObject Win32_MappedLogicalDisk -computer | select name, providername (returns RPC-server not available)
The weird thing is that File Explorer has no problem listing the shares!
If I create a DirectoryInfo with one of the existing shares on the server, then it works fine:
var d = new DirectoryInfo(#"\\MyServerName\OneOfTheShares");
I am aware that DirectoryInfo cannot use a servername only. It needs a folder. But what I can't understand is why File Explorer can list the shares, but net view \\MyServerName can't!
Can anyone please help me with some thoughts?
Ok, so being teased by Anton Anpilogov ;-) to take a WinApi aproach to this issue, I found a 16 year old CodeProject by Rob Manderson https://www.codeproject.com/Articles/6235/Enumerating-Network-Resources
that put me on the right track :-)
By using WNetEnumResource to enumerate connected server resources filtering them with my known Server name, I can return a list of all shares on that server!
result = WNetOpenEnum(scope, type, usage, pRsrc, out handle);
if (result == ErrorCodes.NO_ERROR)
{
do
{
result = WNetEnumResource(handle, ref cEntries, buffer, ref bufferSize);
if (result == ErrorCodes.NO_ERROR)
{
Marshal.PtrToStructure(buffer, pRsrc);
if(pRsrc.lpRemoteName.StartsWith(<MyServerName>))
{
Shares.Add(pRsrc.lpRemoteName);
}
}
else if (result != ErrorCodes.ERROR_NO_MORE_ITEMS)
break;
} while (result != ErrorCodes.ERROR_NO_MORE_ITEMS);
WNetCloseEnum(handle);
}
The code obviously needs some tidying up, but it works!
Thanx!
I am simply trying to recover if a process is running but impossible, an error is repeated for whatever reason...
I don’t understand, after research I thought I understood that it was not possible but I can’t believe it, there is necessarily a way to recover if a program is running.
I already used Process.GetProcessesByName on WinForm and no problem... But this time with UWP i have an error... I just try to check is TeamSpeak is running
public bool isTSOpen()
{
Process[] processesx64ts = Process.GetProcessesByName("ts3client_win64");
Process[] processesx32ts = Process.GetProcessesByName("ts3client_win32");
if(processesx32ts.Length == 0 && processesx64ts.Length == 0)
{
return true;
}
else
{
return false;
}
}
Retrieving information about local processes is not supported on this platform.
At System.Diagnostics.NtProcessInfoHelper.GetProcessInfos(Predicate'1 machineName)
at System.Diagnostics.Process.GetProcesses(String machineName)
at System.Diagnostics.Process.GetProcessesByName(String processName, String machineName)
You need to run with App Diagnostics capability
You can use appdiagnosticinfo. I think you need to request user permission the first time.
https://learn.microsoft.com/en-us/uwp/api/windows.system.appdiagnosticinfo
https://www.google.com/amp/s/blogs.windows.com/buildingapps/2017/06/28/uwp-app-diagnostics/amp/
#Andy's suggestions was on the right direction. The UWP has diagnostic APIs to allow an app to enumerate a list of running apps, including UWP apps, Win32 apps, system services and so on.
To make the APIs work successfully, you need to declare the appDiagnostics capability in your manifest.
<Package xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap mp rescap">
...
<Capabilities>
<rescap:Capability Name="appDiagnostics" />
</Capabilities>
</Package>
Please note:
This is a restricted capability: If you submit an app with this capability to the Windows Store, this will trigger closer scrutiny. The app must be in the Developer Tools category, and we will examine your app to make sure that it is indeed a developer tool before approving the submission.
At run time, the capability also triggers a user-consent prompt the first time any of the diagnostic APIs are called.
The user is always in control: If permission is denied, then the APIs will only return information about the current app. The prompt is only shown on first use, but the user can change his or her mind any time via the privacy pages in Settings.
More information, please see UWP App Diagnostics
Back to your original question, you want to find the specific process.
You first need to request permission to access diagnostics for other apps by calling AppDiagnosticInfo.RequestAccessAsync method and then, you could ProcessDiagnosticInfo.GetForProcesses method to get all running processes. At the end, you could get the specific process by its ExecutableFileName property.
I made a simple code demo for your reference:
DiagnosticAccessStatus diagnosticAccessStatus =
await AppDiagnosticInfo.RequestAccessAsync();
switch (diagnosticAccessStatus)
{
case DiagnosticAccessStatus.Allowed:
IReadOnlyList<ProcessDiagnosticInfo> processes = ProcessDiagnosticInfo.GetForProcesses();
var p = processes.Where(x => x.ExecutableFileName == "ts3client_win64.exe"||x.ExecutableFileName == "ts3client_win32.exe").FirstOrDefault();
if (p!= null)
{
//TODO:...
}
break;
case DiagnosticAccessStatus.Limited:
break;
}
I would like to use a barcode scanner with Windows 10 (Build 15063) via the Windows.Devices.PointOfService namespace. The scanner is a Datalogic Quickscan QD2430 and I tried with all RS-232 and Keyboard mode.
I used the official sample application https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/BarcodeScanner with no luck. It can detect a device but it's definitely the in-built webcam (HP laptop).
I tried to modify the source, the DeviceHelpers's GetFirstDeviceAsync function https://github.com/Microsoft/Windows-universal-samples/blob/master/SharedContent/cs/DeviceHelpers.cs.
The DeviceInformation.FindAllAsync also returns only the camera's info as result.
string selector = BarcodeScanner.GetDeviceSelector(PosConnectionTypes.All);
DeviceInformation.FindAllAsync(selector);
It returns nothing.
DeviceInformation.FindAllAsync(DeviceClass.ImageScanner);
It returns every connected and I think the previously connected but currently offline devices too. I tried to filter the scanner by name. There was a lot filterd result too, but the convertAsync function returned null for all excepts one, it thrown an Exception "A device attached to the system is not functioning. (Exception from HRESULT: 0x8007001F)".
DeviceInformationCollection infos = await DeviceInformation.FindAllAsync(DeviceClass.All);
foreach(DeviceInformation info in infos)
{
if (info.Name.ToUpper().Contains("BARCODE"))
{
T scanner = await convertAsync(info.Id);
if (scanner != null)
{
return scanner;
}
}
}
Datalogic Quickscan QD2430 is not in the list of devices supported by Windows.Devices.PointOfService.
Ask Datalogic to provide a device driver that supports Windows.Devices.PointOfService, or change the scanner to the one described in the supported list.
Alternatively, create your own device driver according to the Point of Service (POS) of Windows Driver Kit.
How can I check for 3G, wifi, EDGE, Cellular Networks in Windows Phone 7 using C#?
If you can use the Mango (7.1) SDK, and if your scenario involves using sockets, there's a trivial way to get the NetworkInterfaceType/SubType information for the connection you just made:
NetworkInterfaceInfo netInterfaceInfo = socket.GetCurrentNetworkInterface();
var type = netInterfaceInfo.InterfaceType;
var subType = netInterfaceInfo.InterfaceSubtype;
No need to use the NetworkInterface.NetworkInterfaceType property (which notoriously takes up to 30sec to return); no need to trigger a hostname resolution just to determine the network type; no need to listen to network change events.
Of course, this works best in conjunction with DeviceNetworkInformation.IsNetworkAvailable or NetworkInterface.GetIsNetworkAvailable() - those calls return immediately whether you're on a network or not. If you are, you connect the socket first and ask questions when it's connected :-)
A final note: beware of Mango's DeviceNetworkInformation.IsWiFiEnabled - I thought it would return whether I was on a wifi network, but instead it returns whether wifi is turned on or off in the phone settings... not super useful.
take a look at phoney tools, they have class PhoneNetworking for this:
http://wildermuth.com/2011/03/05/Phoney_Tools_Updated_(WP7_Open_Source_Library)
its open source you can check the source code
As of the Mango release (beta 2 and RC), this information is now available but it requires you to actually make a connection, presumably because it doesn't check until something needs it.
You can either perform a DNS resolution (see below) or use the GetCurrentNetworkInterface WebRequest extension method, which will throw an InvalidOperationException if the request hasn't connected yet.
There are also some events to follow in the Microsoft.Phone.Net.NetworkInformation namespace, but I wouldn't be surprised if those events didn't fire until a connection was made.
Interestingly, it seems you can also prefer or require on a per-connection basis using the SetNetworkPreference and SetNetworkRequirement extension methods, though it doesn't go beyond wifi vs cellular.
DeviceNetworkInformation.ResolveHostNameAsync(
new DnsEndPoint("microsoft.com", 80),
new NameResolutionCallback(nrr =>
{
var info = nrr.NetworkInterface;
var type = info.InterfaceType;
var subType = info.InterfaceSubtype;
}), null);
The enumeration values for NetworkInterfaceType (wifi/gsm) and NetworkInterfaceSubType (edge/3g) are available on MSDN.
Without socket:
var currentList = new NetworkInterfaceList().Where(i => i.InterfaceState == ConnectState.Connected).Select(i => i.InterfaceSubtype);
if (currentList.Contains(NetworkInterfaceSubType.WiFi))
Debug.WriteLine("WiFi");
if (currentList.Intersect(new NetworkInterfaceSubType[]
{
NetworkInterfaceSubType.Cellular_EVDO,
NetworkInterfaceSubType.Cellular_3G,
NetworkInterfaceSubType.Cellular_HSPA,
NetworkInterfaceSubType.Cellular_EVDV,
}).Any())
Debug.WriteLine("3G");
if (currentList.Intersect(new NetworkInterfaceSubType[]
{
NetworkInterfaceSubType.Cellular_GPRS,
NetworkInterfaceSubType.Cellular_1XRTT,
NetworkInterfaceSubType.Cellular_EDGE,
}).Any())
Debug.WriteLine("2G");
Unfortunately the api's don't provide very limited information about the kind of network connection you have. You can tell if you are on 3G, Cellular or Ethernet (i.e. USB connection to PC) but that is all the information you get.
Check out this for more info Better way to check for an network connection on WP7
To get Network Data for windows phone app i.e it is connected to a ethernet, wifi or cellular network also getting the subtype i.e 2G or 3g network following program can be used.
Using Microsoft.Phone.Net.NetworkInformation
Using Microsoft.Phone.net.NetworkInfromation
var Newlist = new NetworkInterfaceList();
foreach (NetworkInterfaceInfo x in Newlist)
{
if(x.InterfaceState==ConnectState.Connected)
{
if(x.InterfaceSubtype.Equals(NetworkInterfaceSubType.WiFi))
{
Interface = x.InterfaceType.ToString();
SubInterface = x.InterfaceSubtype.ToString();
break;
}
else if(x.InterfaceSubtype.Equals(NetworkInterfaceSubType.Cellular_EVDO) || x.InterfaceSubtype.Equals(NetworkInterfaceSubType.Cellular_3G) || x.InterfaceSubtype.Equals(NetworkInterfaceSubType.Cellular_HSPA) || x.InterfaceSubtype.Equals(NetworkInterfaceSubType.Cellular_EVDV))
{
Interface = x.InterfaceType.ToString();
SubInterface= “3G Network”;
break;
}
else if(x.InterfaceSubtype.Equals(NetworkInterfaceSubType.Cellular_GPRS) || x.InterfaceSubtype.Equals(NetworkInterfaceSubType.Cellular_1XRTT) || x.InterfaceSubtype.Equals(NetworkInterfaceSubType.Cellular_EDGE))
{
Interface = x.InterfaceType.ToString();
SubInterface= “2G Network”;
break;
}
else
{
Interface = “Ethernet”;
SubInterface= “Unknown” ;
break;
}
}
else
{
Interface=”not connected”;
SubInterface=”unknown”;
}
Here, Interface and SubInterface gives the network information.
How to check current machine type? laptop or desktop ?
I got this from http://blog.csdn.net/antimatterworld/archive/2007/11/11/1878710.aspx ,it works well on my home machine(Win2003 on laptop), it returns "Portable", but failed on my work machine(Vista on laptop), it returns "Other".
here is the code:
public enum ChassisTypes
{
Other = 1,
Unknown,
Desktop,
LowProfileDesktop,
PizzaBox,
MiniTower,
Tower,
Portable,
Laptop,
Notebook,
Handheld,
DockingStation,
AllInOne,
SubNotebook,
SpaceSaving,
LunchBox,
MainSystemChassis,
ExpansionChassis,
SubChassis,
BusExpansionChassis,
PeripheralChassis,
StorageChassis,
RackMountChassis,
SealedCasePC
}
public static ChassisTypes GetCurrentChassisType()
{
ManagementClass systemEnclosures = new ManagementClass("Win32_SystemEnclosure");
foreach (ManagementObject obj in systemEnclosures.GetInstances())
{
foreach (int i in (UInt16[ ])(obj["ChassisTypes"]))
{
if (i > 0 && i < 25)
{
return (ChassisTypes)i;
}
}
}
return ChassisTypes.Unknown;
}
Here's a good Microsoft article that suggests looking at a few other WMI classes to get a better idea of whether the computer is a laptop or desktop:
http://technet.microsoft.com/en-us/library/cc180825.aspx
Win32_SystemEnclosure, ChassisTypes(1)=10
Win32_Battery or Win32_PortableBattery
Win32_PCMCIAController
Win32_DriverVXD.Name = "pccard"
Win32_ComputerSystem.Manufacturer
Win32_ComputerSystem.Model
And it also suggests to look in the registry for the Power scheme.
Well, I may be attempting to raise the dead here, but I would suggest that the most reliable method of determining a laptop would be the present of a lid status switch.
See GetPwrCapabilities and System_power_Capabilities
There is no need for both Other and Unknown check.
Change the condition to i > 1 && i < 25 and remember ChassisTypes is an array where OS returns what ever he thinks your system is.
It is possible to match more than single type. Your code only returns the first match.
See http://www.microsoft.com/technet/scriptcenter/resources/qanda/sept04/hey0921.mspx and http://msdn.microsoft.com/en-us/library/aa387204(VS.85).aspx which states that:
This documentation is derived from the CIM class descriptions published by the DMTF.
Presumably, that means the manufacturer had to provide some information for Windows to be able to discover it.
I don't think there is a definitive right answer for this and I've found WMI unreliable for it but I have been using the Win32 function GetSystemPowerStatus() to determine if there is a system battery, obviously system battery == portable computer.
I've never tried this on a desktop with a UPS though?!
I am pretty sure that this will depend on whether the manufacturer has bothered to provide that data on the current chipset. If they have not, then "Other" is the best you can do.
Check out this somewhat related article, which also suggests querying the BIOS directly.
In order to check if machine is laptop or desktop you can try to check battery status, using SystemPowerCapabilites.LidPresent or both of them.
Battery:
if(SystemInformation.PowerStatus.BatteryChargeStatus ==BatteryChargeStatus.NoSystemBattery){
//desktop
}
else{
//laptop
}
SystemPowerCapabilites.LidPresent:
public SYSTEM_POWER_CAPABILITIES getSystemPowerCapabilites(){
{
SYSTEM_POWER_CAPABILITIES systemPowerCapabilites;
GetPwrCapabilities(out systemPowerCapabilites);
return systemPowerCapabilites;
}
getSystemPowerCapabilites().LidPresent;
GetPwrCapabilities definition: http://www.pinvoke.net/default.aspx/powrprof/GetPwrCapabilities.html
read registry key from HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\pcmcia, the ‘Start’ value, it's laptop if start =0, otherwise it's desktop machine if start doesn't exist or start != 0.