0

Is there a way to access a mobile devices properties through C#. The purpose would be to display the device's serial number and iOS version for USB connected like an iPhone.

Using a WMI query like below access is given to the basic info accessible through the Computer Manager like DeviceID or PnpDeviceID. However I have been unable to find a property that gives the device serial number etc.

ManagementObjectSearcher(@"Select * From Win32_USBHub WHERE Description LIKE 'Apple Mobile Device%'")

or

ManagementObjectSearcher(@"Select * From Win32_PnPEntity")

or

ManagementObjectSearcher("@Select * From Win32_USBControllerDevice")

The device property menu I am referring to is in the picture below accessed by right click on a device and then clicking properties.

enter image description here

ASh
  • 34,632
  • 9
  • 60
  • 82

2 Answers2

4

Placing the code below after lockdown.lockdownd_client_new_with_handshake(deviceHandle, out lockdownHandle, "Quamotion").ThrowOnError(); you will be able to access values like the serial number or iOS version. This is only a crude example:

        string t1;
        string t2;

        PlistHandle tested1;
        PlistHandle tested2;

        //Find serial number in plist
        lockdown.lockdownd_get_value(lockdownHandle, null, "SerialNumber", out 
        tested1);

        //Find IOS version in plist
        lockdown.lockdownd_get_value(lockdownHandle, null, "ProductVersion", out 
         tested2);

        //Get string values from plist
        tested1.Api.Plist.plist_get_string_val(tested1, out t1);
        tested2.Api.Plist.plist_get_string_val(tested2, out t2);

        //Place data in textboxes
        serialTXT.Text = t1.Trim();
        verTXT.Text = t2.Trim();
2

If you want to access properties such as the iOS version, your best bet may be to use imobiledevice-net.

You can install the imobiledevice-net NuGet package and then run a command like this:

ReadOnlyCollection<string> udids;
int count = 0;

var idevice = LibiMobileDevice.Instance.iDevice;
var lockdown = LibiMobileDevice.Instance.Lockdown;

var ret = idevice.idevice_get_device_list(out udids, ref count);

if (ret == iDeviceError.NoDevice)
{
    // Not actually an error in our case
    return;
}

ret.ThrowOnError();

// Get the device name
foreach (var udid in udids)
{
    iDeviceHandle deviceHandle;
    idevice.idevice_new(out deviceHandle, udid).ThrowOnError();

    LockdownClientHandle lockdownHandle;
    lockdown.lockdownd_client_new_with_handshake(deviceHandle, out lockdownHandle, "Quamotion").ThrowOnError();

    string deviceName;
    lockdown.lockdownd_get_device_name(lockdownHandle, out deviceName).ThrowOnError();

    deviceHandle.Dispose();
    lockdownHandle.Dispose();
}

The lockdown class will allow you to access other properties, such as the iOS version, as well.

It does come with a dependency on iTunes, though.

Frederik Carlier
  • 4,606
  • 1
  • 25
  • 36
  • After some research I was able to access the version and serial number there may have been a more direct way. I will put the code in another answer for anyone else. – Salih Yasin Nov 21 '18 at 18:28