using System.Runtime.InteropServices;
private const int HW_PROFILE_GUIDLEN = 39;
private const int MAX_PROFILE_LEN = 80;
private const int DOCKINFO_UNDOCKED = 0x1;
private const int DOCKINFO_DOCKED = 0x2;
private const int DOCKINFO_USER_SUPPLIED = 0x4;
private const int DOCKINFO_USER_UNDOCKED = DOCKINFO_USER_SUPPLIED |
DOCKINFO_UNDOCKED;
private const int DOCKINFO_USER_DOCKED = DOCKINFO_USER_SUPPLIED |
DOCKINFO_DOCKED;
public struct HW_PROFILE_INFO
{
public uint dwDockInfo;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = HW_PROFILE_GUIDLEN)]
public string szHwProfileGuid;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_PROFILE_LEN)]
public string szHwProfileName;
};
[DllImport("advapi32.dll")]
public static extern bool GetCurrentHwProfile(ref HW_PROFILE_INFO
lpHwProfileInfo);
private void button1_Click(object sender, EventArgs e)
{
HW_PROFILE_INFO vHW_PROFILE_INFO = new HW_PROFILE_INFO();
if (GetCurrentHwProfile(ref vHW_PROFILE_INFO))
{
if ((vHW_PROFILE_INFO.dwDockInfo & (DOCKINFO_UNDOCKED |
DOCKINFO_DOCKED)) ==
(DOCKINFO_UNDOCKED | DOCKINFO_DOCKED))
{
Text = "筆記本";
}
else Text = "台式電腦";
}
}