Skip to main content

Google Search

Custom Search

Live Search

Yahoo Search

Search the web Search this site
Retrieving MAC Address in Compact Framework

Recently I have seen that getting the MAC address of a Pocket PC network card using the .Net Compact Framework requires calling to the API 'iphlpapi.dll'. This is because the Windows Management Instrumentation (WMI) classes are not in Compact Framework. Otherwise you should have used WMI to get the MAC address.
But believe me that the process involved in Compact Framework to get the MAC address is complex. So as a suggestion I would say to use the OpenNETCF class libraries. You have to use OpenNETCF.Net and OpenNETCF to successfully get the MAC address. If you want to know what is happening underneath you also can download the OpenNETCF source code too.

OpenNETCF web site is, visit them and see.

The code for getting the MAC address of the first adapter using OpenNETCF would be,

' Creating a variable to hold all the retrieved adapters.
Dim adpcol As OpenNETCF.Net.AdapterCollection = OpenNETCF.Net.Networking.GetAdapters
If adpcol.Count = 1 Then
' adpcol.Item(0).MacAddress will be returning in Byte stream, you have to use Bit Converter to convert the stream to string.
GetDeviceMAC = BitConverter.ToString(adpcol.Item(0).MacAddress)
GetDeviceMAC = "No Adapters Fetched"
End If

(You have to refer OpenNETCF.Net and OpenNETCF to make this code run.)


Popular posts from this blog

"Login failed. The login is from an untrusted domain and cannot be used with Windows authentication."

If you are getting the above error while trying to connect to a database, the reason is you are using Windows Authentication to login to the SQL Server while being in another untrusted domain. For example if the SQL Server machine is a member of the CompanyDomain and if you are in MyDomain or if you are in a Workgroup the you will face the above issue while trying to connect to the SQL Server. The connection string used in the web.config while the above error is generated is as follows. < connectionStrings >   < add name = " cnnStr " connectionString = " Data Source=BI-SVR;Initial Catalog=BBIDatabase;Integrated Security=True " /> </ connectionStrings >   There are three ways to fix this problem. 1. Use the SQL Authentication to login to the SQL Server. You can get this done by changing the connection string to use SQL authentication while connecting. But you need to know the credentials of an account which is having permi

Enabling Hibernate in Windows

Some server versions of Windows are having the hibernate feature disabled by default. So if you need to change the hibernation do the following simple steps. 1. Click start and type “ cmd ” or type command in the search box. 2. Then in the search results, right click the Command Prompt and click on Run as Administrator . 3. If you are prompted by the user account control click continue. 4. Then, To turn hibernation on in your machine type - “ powercfg.exe /h on ” or “ powercfg.exe /hibernate on ” To turn hibernation off in your machine type - “ powercfg.exe /h off ” or “ powercfg.exe /hibernate off ” 5. Lastly you can exit the command prompt by typing “ exit ”.   Sometimes you might get an error similar to the following while trying to enable hibernation. Hibernation failed with the following error: The request is not supported. The following items are preventing hibernation on this system.         An inte

Enable Hibernation and Sleep in Windows Server 2008 R2

Normally when you install Hyper-V role in your server, it will disable sleep and hibernate facilities provided by Windows. But you can avoid this by doing some alterations to Windows. Hibernate and seep features are disabled when the Hyper-V service is started, so you can regain hibernate and sleep by changing the start parameter of the Hyper-V service (hvboot). To change, 1. Open the registry editor by typing “ regedit ” in the run window. Locate the key, HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\hvboot and then set the start value of it to 3. Start property can hold the following values. 0 Boot (Not supported by hvboot.) 1 System 2 Auto 3 On Demand 4 Disabled Now you will have the hibernate and sleep facilities until you start the Hyper-V services in your machine. 2. Type the following command in a command prompt window with administrative rights. sc config hvboot start= demand Note that there needs to be a space between the = sign and the word demand.