///--获取计算机名;
char pcName[MAX_PATH];
WSADATA wsData = {0};
int iRes =WSAStartup(MAKEWORD(2,2),&wsData);
if(iRes!=0)
iRes = gethostname(pcName,MAX_PATH);
if(iRes!=SOCKET_ERROR)
{
AfxMessageBox(pcName);
}
////--获取计算机描述(通过注册表);
HKEY hKey;
LPCTSTR data_set = _T("SYSTEM\\CurrentControlSet\\Services\\LanmanServer\\Parameters\\");
LONG res = (::RegOpenKeyEx(HKEY_LOCAL_MACHINE,data_set,0,KEY_READ,&hKey));
if(res!=ERROR_SUCCESS) return "";
LPBYTE ownGet = new BYTE[80];
DWORD type = REG_SZ;
DWORD nSize = 80;
LONG res2 = (::RegQueryValueEx(hKey,_T("srvcomment"),NULL,&type,ownGet,&nSize));
if(res2!=ERROR_SUCCESS) return "";
CString strDescp = CString(ownGet);
delete[] ownGet;
::RegCloseKey(hKey);
AfxMessageBox(strDescp.GetBuffer());
//////
////--获取计算机描述;
CString strDescp = _T("");//计算机描述;
HKEY hKey;
LPCTSTR data_set = _T("SYSTEM\\CurrentControlSet\\Services\\LanmanServer\\Parameters\\");
LONG res = (::RegOpenKeyEx(HKEY_LOCAL_MACHINE,data_set,0,KEY_READ,&hKey));
if(res!=ERROR_SUCCESS)
strDescp = _T("");
else
{
LPBYTE ownGet = new BYTE[80];
DWORD type = REG_SZ;
DWORD nSize = 80;
LONG res2 = (::RegQueryValueEx(hKey,_T("srvcomment"),NULL,&type,ownGet,&nSize));
if(res2!=ERROR_SUCCESS)
strDescp = _T("");
else
strDescp = CString(ownGet);
delete[] ownGet;
}
::RegCloseKey(hKey);
////---
评论