Raf's laboratory Abstracts Feed Raffaele Rialdi personal website

I am Raf logo

GetComputerName on Windows CE / Windows Mobile (VC++)

July 21, 2010
http://iamraf.net/Samples/GetComputerName-on-Windows-CE-Windows-Mobile-(VC2b2b)

There is no GetComputerName API on Windows CE and I could not find any Compact Framework class to obtain this functionality.

On these devices you can find the computer (pda) name in the registry at HKEY_LOCAL_MACHINE\Ident\Name

If you want to take a look at the registry on your devices/emulators, you can use the free PHM registry editor:
http://www.pocketpcfreeware.com/files/regedit.Mrln_ARM.CAB

The C++ code to obtain the name of the device is the following:

#include <iostream>
#include <string>
using namespace std;
 
wstring GetComputerName()
{
    HKEY hKey;
    if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Ident", 0, NULL, &hKey) != ERROR_SUCCESS)
        return wstring();
 
    DWORD dwLen = MAX_PATH;
    wchar_t Buffer[MAX_PATH];
    if(RegQueryValueEx(hKey, L"Name", NULL, NULL, (LPBYTE)Buffer, &dwLen) != ERROR_SUCCESS)
    {
        RegCloseKey(hKey);
        return wstring();
    }
    Buffer[dwLen] = NULL;
 
    RegCloseKey(hKey);
    return wstring(Buffer);
}

The wstring class comes from the STL (Standard Template Library). To show the PDA name in a MessageBox, you can use this code:

wstring name = GetComputerName();
MessageBox(NULL, name.c_str(), L"PDA Name is ...", MB_OK);

If you need to get it using C#, just use the Microsoft.Win32.Registry class.



rated by 0 users



Share this page on Twitter


Privacy | Legal Copyright © Raffaele Rialdi 2009, Senior Software Developer, Consultant, p.iva IT01741850992, hosted by Vevy Europe Advanced Technologies Division. Site created by Raffaele Rialdi, 2009 - 2015 Hosted by: © 2008-2015 Vevy Europe S.p.A. - via Semeria, 16A - 16131 Genova - Italia - P.IVA 00269300109