Getting unique device ID in VS2012 Windows 8 Store Apps - c#

I am new to Windows 8 Store Apps, and need to fetch device ID in one of my XAML project. And this device ID should be unique. I searched the internet and came across 2 different ways.
First way in C# code,
private string GetHardwareId()
{
var token = HardwareIdentification.GetPackageSpecificToken(null);
var hardwareId = token.Id;
var dataReader = Windows.Storage.Streams.DataReader.FromBuffer(hardwareId);
byte[] bytes = new byte[hardwareId.Length];
dataReader.ReadBytes(bytes);
return BitConverter.ToString(bytes);
}
Second way in C# code,
var easClientDeviceInformation = new Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation()
GUID deviceId = easClientDeviceInformation.Id;
The first one gives in bits format whereas second one gives GUID. I am not getting any idea that which is correct one.
I referred this blog
And MSDN link too.
Can any one guide me regarding which can be used as Device ID?

I had same confusion, but finally used HardwareIdentification.GetPackageSpecificToken.
Because I find no information about uniqueness of EasClientDeviceInformation.ID
However, you can't use ID returned by HardwareIdentification.GetPackageSpecificToken as it is, because it depends upon many hardware components. And if any one of them changed, a different id will be returned.
There is more information at this link.

In VS2013, Microsoft uses the following method to retrieve the unique "installation id" or "device id" for the current device when uploading a channel URI retrieved from the Microsoft Push Notification Server (MPNS) to implement Push Notification:
var token = Windows.System.Profile.HardwareIdentification.GetPackageSpecificToken(null);
string installationId = Windows.Security.Cryptography.CryptographicBuffer.EncodeToBase64String(token.Id);

Related

Is PNPDeviceID of video card adapter unique?

I need to get a unique id of video card adapter. When searching in the properties of the device (using Device Manager of Windows), I notice that there is a property named Hardware Ids as shown in image bellow.
I tried to get these Ids in my winform application. I found this method:
string VideoCardInfoID()
{
ManagementObjectSearcher objvide = new ManagementObjectSearcher("select * from Win32_VideoController");
string output = string.Empty;
foreach (ManagementObject obj in objvide.Get())
{
output += (obj["PNPDeviceID"] + "\n");
}
return output;
}
The output of this code is:
PCI\VEN_10DE&DEV_1055&SUBSYS_908A104D&REV_A1\4&F7451F8&0&0008
I have two questions:
Is PNPDeviceID of video card adapter unique across all machines? does it change when new fresh Windows installed? I know there some similar questions in stack overflow, but they does not contain a clear answers, such as this question and this question.
Why there is additional characters in the output of the c# function (\4&F7451F8&0&0008)?
Update: I try install new fresh Windows and the Hardware Ids and PNPDeviceID still the same, But I still don't know if PNPDeviceID unique across all machines (I mean the same as MAC address).
Is PNPDeviceID of video card adapter unique across all machines?
No. Essentially what this string is comprised of is
<Bus>\<Device ID>\<Instance ID>
The Instance ID is only unique within the context of the current system, and it may not even be unique for the whole system, only for the device's bus.
That is, if you have two identical video cards installed in the computer, they will have the same Device ID, but different Instance ID.
A graphics card driver might use its own serial number in the Instance ID. So it is possible that Instance ID is globally unique, but WMI cannot make that guarantee for all PNP devices.
At this point you will likely have to use a per-vendor documented way to determine the device's serial number, if at all possible.

Reading device serial number and/or IMEI from UWP app

I am working on an app that will obtain an X.509 certificate for a device that will be used to encrypt various configuration data. Ideally, this certificate would contain information that can be correlated with procurement records. Is there any way to read the device serial number or IMEI from a universal windows app?
As for UWP in general, to get a system unique id (not IMEI), you might want to check out these classes:
Windows.System.Profile.SystemIdentification
and
Windows.System.Profile.HardwareIdentification
E.g.: you can query a unique device id with:
var buffer = SystemIdentification.GetSystemIdForPublisher();
Which has the following remarks according to msdn:
The ID has the following characteristics:
Unique for every system
Can be created offline
Persists across rebooting, OS upgrades/reinstalls, and so on
Persists across hardware modifications
Available in OneCore
Available on the factory floor for licensing purposes
https://msdn.microsoft.com/en-us/library/windows/apps/windows.system.profile.systemidentification.getsystemidforpublisher.aspx
Be aware that the return type is an IBuffer and produces some raw (non-string-like-readable) bytes so you might need to serialize that.
More info
https://msdn.microsoft.com/en-us/library/windows/apps/windows.system.profile.systemidentification.aspx
and
https://msdn.microsoft.com/en-us/library/windows/apps/windows.system.profile.hardwareidentification.aspx
It is not possible to get IMEI of another phone with phone number information, however you can get the device unique Id.
using Microsoft.Phone.Info;
object uniqueId;
var hexString = string.Empty;
if (DeviceExtendedProperties.TryGetValue("DeviceUniqueId", out uniqueId))
hexString = BitConverter.ToString((byte[])uniqueId).Replace("-", string.Empty);
MessageBox.Show("myDeviceID:" + hexString);
Reference

Is it possible to launch system/third party app using an NDEFLaunchApp record to get the URI and by using LaunchUriAsync without NFC Tags?

So I have spent the whole night looking like a zombie in the morning trying to figure out how the OS handles an NFC tap for an NDEFLaunchApp Record and I have known the following.
I'm pretty sure that there is a workaround which lets you launch a system app / third party app (if you know the product Id / GUID) from your app. As there are apps in the Windows Phone Store which I have somehow figured out what I've been trying to.
I have come up with the following code:
NdefLaunchAppRecord appLaunchRecord = new NdefLaunchAppRecord();
appLaunchRecord.AddPlatformAppId("WindowsPhone", "{App GUID}");
appLaunchRecord.Arguments = "_default";
// Creating a new NdefMessage from the above record.
var message = new NdefMessage { appLaunchRecord };
// Getting the record from the message that we just created
foreach (NdefLaunchAppRecord record in message)
{
var specializedType = record.CheckSpecializedType(false);
if (specializedType == typeof(NdefLaunchAppRecord))
{
var x = String.Join(" ", record.Payload);
// Getting the payload by GetString gets a formatted Uri with args
string result = System.Text.Encoding.UTF8.GetString(record.Payload, 0, record.Payload.Length);
// result = "\0\fWindowsPhone&{5B04B775-356B-4AA0-AAF8-6491FFEA5630}\0\b_default";
// result = "(null)(form feed)WindowsPhone&{App GUID}(null)(backspace)_default
// So this will be sent to the OS and I believe the OS will then launch the specified app by an unknown protocol
// like xxx://result
// and the app will be launched?
// So is it then possible to somehow call the following:
await Windows.System.Launcher.LaunchUriAsync(new Uri("OUR MAGIC RESULT?", UriKind.RelativeOrAbsolute));
If anyone has / can figure out a way for this, it would be a REAL Service to the WP Community as developers are restricted by Microsoft to open certain settings / apps which are actually needed by those apps. For instance (speech settings, audio settings, about settings, alarms, region settings, date+time);
APPS that possibly have a workaround:
Music Hub Tile (Launches the old Music+Videos Hub)
http://www.windowsphone.com/en-gb/store/app/music-hub-tile/3faa2f9e-6b8d-440a-bb60-5dd76a5baec1
Tile for Bing Vision
http://www.windowsphone.com/en-gb/store/app/tile-for-bing-vision/05894022-e18c-40a4-a6cc-992383aa7ee8
There are reserved uri schemes for bing and zune.
See: http://msdn.microsoft.com/en-us/library/windows/apps/jj207065(v=vs.105).aspx
Those two apps propably use these and have found some undocumented use of the scheme.
If there is an uri scheme that launches any app by guid from within your app, it is hidden well.
Currently you can only launch apps that registered for an uri scheme or file association.

Call Navigation/Maps/Drive with an Address in WP8.1 Application

I was wondering if it's possible to call the default navigation application within my Windows Phone 8.1 application. I have an address and I would like for the user to press a button and be able to navigate to that address through the default navigation app. If this is possible, how do I do it?
Thanks for your time,
Johan
You can launch turn-by-turn directions apps using the ms-drive-to and ms-walk-to schemes (depending on the type of directions you want) but you first need to get a geocoordinate for the address that you have. Since you're targeting Windows Phone 8.1, you can use the MapLocationFinder class in the Windows.Services.Maps namespace.
string locationName = "Empire State Building";
string address = "350 5th Avenue, New York City, New York 10018";
var locFinderResult = await MapLocationFinder.FindLocationsAsync(
address, new Geopoint(new BasicGeoposition()));
// add error checking here
var geoPos = locFinderResult.Locations[0].Point.Position;
var driveToUri = new Uri(String.Format(
"ms-drive-to:?destination.latitude={0}&destination.longitude={1}&destination.name={2}",
geoPos.Latitude,
geoPos.Longitude,
locationName));
Launcher.LaunchUriAsync(driveToUri);
the official solution is:
Uri uri = new Uri("ms-drive-to:?destination.latitude=" + latitude.ToString(CultureInfo.InvariantCulture) +
"&destination.longitude=" + longitude.ToString(CultureInfo.InvariantCulture))
var success = await Windows.System.Launcher.LaunchUriAsync(uri);
if (success)
{
// Uri launched.
}
else
{
MessageBox.Show("error");
}
But, there is a problem with this solution.
If you use the nokia programs (HERE), it works fine.
if you want to use waze, you have to add origin.latitude and origin.longitude.
in the MSDN page, They said that it is not necessary, but in fact, you have to write it.
I am already not enable to load moovit but if someone has an issue, it'll help me a lot.

Query printer status on my d-link print server

I have an d-link dp-311p print server which provides the printer status(offline, paper out, etc) on it's interface.
How can i get this oid status ?? i'm trying to find through axence nettools but there is A LOT of keys and the descriptions are not friendly...
Also, i'm trying to use this code(c#) to access the print server status but no success...
please, need a light, i'm completely lost!
Tks everyone
I did it! Here is how:
Search for mib browser because I didn't know the oid of the print server status. Found This one, then, I created a console app like this
OLEPRNLib.SNMP snmp = new OLEPRNLib.SNMP();
int Retries = 1;
int TimeoutInMS = 2000;
string CommunityString = "public";
string IPAddressOfPrinter = "192.168.1.12";
string ALLINEED;
// Open the SNMP connect to the print server
snmp.Open(IPAddressOfPrinter, CommunityString, Retries, TimeoutInMS);
ALLINEED = snmp.Get(".1.3.6.1.4.1.11.2.3.9.1.1.3.0");
snmp.Close();
Console.Write(ALLINEED);
On my machine I made a reference on the COM tab of the Add Reference dialog to “oleprn 1.0 Type Library“ which lived in “c:\Windows\System32\oleprn.dll“
Hope this can help someone.
Tks

Categories