Category > Technology

Detecting Storage of Modern Smartphones

» 05 May 2013 » In C#, Programming, Technology » No Comments

I got my Nexus 4 few weeks ago. It has no micro-SD card slot, but this is not a rant about the lack of storage scalability. When you plug modern smartphones into a Windows machine, you’ll get a Portable Device label. What does it mean? It’s technically not a Removable Device.

Drives and Devices

Display of drives and devices connected to the computer

Please do note that this is not only a case for modern smartphones. Same applies for different devices such as portable media players (MP3 players, etc.)

The problem with this is, the device is not treated as a drive, so codes like this won’t show information about such devices.

foreach (DriveInfo dinfo in DriveInfo.GetDrives())
{
    Console.WriteLine(dinfo.RootDirectory);
}

Based on the above image, this code will only output:

C:\
D:\
E:\
F:\
G:\
H:\

It would be so much pain if I will be writing an automated process application that does something with the smartphone’s storage. But there must be a way, right?

If you are using VS, this will help you, open up your reference manager, and add these COM references.

Portable Device API

Portable Device API

But there’s another problem. This will only detect one device. Luckily we can edit the assembly, but first set Embed Interop Assembly on both interops to False

Embed Interop Assemblies

Embed Interop Assemblies

Now, go to your project’s folder, and navigate to \obj\Debug. Make sure the assemblies are inside that folder. Copy the full path, and open up Developer Command Prompt for VSXXXX where XXXX is your VS version.

Developer Command Prompt

Developer Command Prompt

Change the working directory to the path you copied earlier, and using ildasm, disassemble Interop.PortableDeviceApiLib.dll.

ildasm Interop.PortableDeviceApiLib.dll /out:papi.il

The MSIL Disassembler is a companion tool to the MSIL Assembler (Ilasm.exe). Ildasm.exe takes a portable executable (PE) file that contains Microsoft intermediate language (MSIL) code and creates a text file suitable as input to Ilasm.exe.

We’ve just disassembled Interop.PortableDeviceApiLib.dll, and now you can edit it with your favorite text editor. This is the line we’re looking for:

GetDevices([in][out] string&  marshal( lpwstr)

We need to change every occurrence of that to:

GetDevices([in][out] string[]  marshal(lpwstr[])

Short Explanation: We just changed the first parameter’s data type from a string reference, to an array of strings. This way, we can retrieve many devices.

Lastly, re-assemble the interop:

ilasm papi.il /dll /output="<obj Path>\Interop.PortableDeviceApiLib.dll"

For the code:

uint devNum = 1;
PortableDeviceManagerClass devM = new PortableDeviceManagerClass();
devM.GetDevices(null, ref devNum);
if (devNum > 0)
{
    string[] dId = new string[devNum];
    devM.GetDevices(dId, ref devNum);

    for (int dx = 0; dx < devNum; dx++)
    {
        Console.WriteLine("Device " + dx + 1 + " : " + dId[dx]);
    }
}

It will output lines like:

Device 1 : \\?\usb#vid_18d1&pid_4ee2&mi_00#6&68a019c&1&0000#{6ac27878-a6fa-4155-ba85-f98f491d4f33}

You can then use \\?\usb#vid_18d1&pid_4ee2&mi_00#6&68a019c&1&0000#{6ac27878-a6fa-4155-ba85-f98f491d4f33}, copy it and paste it on explorer’s address bar. Works like charm!

Continue reading...

Tags: , , , , , , , ,

Welcome, New Generation

» 12 January 2011 » In Life, Technology » 2 Comments

I feel so old. Actually, one of the most interesting questions I have ever seen was posted in superuser. I can’t believe that this kind of question will come this early. Well if you’re wondering what that question is..

What are the Windows A: and B: drives used for?

I was like, seriously? I got this from the Hacker News. And it’s very surprising that a question (like I said earlier) like this will be this early. And this was asked 2 days ago, January 10, 2011. I’ll remember that date, and I’m pretty sure there are a lot more people with questions like this.

Floppy Drives

I can remember using floppy disks when I was in the sixth grade. And my uncle, have loads of floppy disks to store their thesis material. I even encountered my first virus alert when I inserted a neighbor’s floppy disk! It made me panic, and that afternoon I was about to cry. Don’t blame me, blame Norton (Yes, I use norton back then).

Drives A: and B: is obsolete in modern computer packages these days. And who would even need one? Average USB thumb drives has gigabytes of storage capacity, and don’t you just love that?

New Generation

I’m afraid this marks the new generation. They’re maybe too young but learning doesn’t choose an age bracket. And honestly, I wish to read more questions like this. Got a link to one? Comment it here!

Continue reading...

Tags: , , , ,

Collaborative Desktop Sharing

» 14 December 2010 » In Internet, Life, Technology » No Comments

I’m currently using my father’s laptop, and using my desktop computer at the same time. Wait, does that make sense to you? Actually I installed a Virtual Network Computing (VNC) server on my desktop computer, I went to my parents’ room and borrowed my father’s laptop, downloaded a VNC viewer and accessed my computer. Pretty simple.

Why am I Doing This?

Personally I like to work on something comfortable, though the interaction between the VNC viewer and the server is not that smooth, compared to a remote desktop connection. My desktop computer is in the living room, and without VNC, I’m sitting there all day working on my stuff. Actually I’m thinking of just buying a long VGA cable and plug it in our HDTV, then all I need is wireless mouse and keyboard.

Well actually, I’m currently testing VNC because of our school group project on friday night. I’m planning to have one PC plugged in to the HDTV and all of us will be connecting to that PC via VNC and work out the Data Flow Diagram of our project together. And since we’re on a local area network, the speed is not much of a problem.

Downsides

In my current VNC connection, I’ve been having display issues. My desktop resolution is 1280×1024 and the laptop’s resolution is 1280×800. It’s pain scrolling up and down to get a full page. This is fixed by changing my desktop’s resolution to 1280×800, which I considered as a downside as well. Why? I don’t really want to change the server’s resolution, as it may affect other users connecting to it. As for our collaborative project, I’m hoping this will not be a big issue. Otherwise, we’ll be voting for the best resolution.

My desktop in 1280x800

My desktop in 1280x800

Overall, I love this method. And I prefer this over Teamviewer. If you have reactions or comments, feel free to type them below.

Continue reading...

Tags: , , ,