Here are a few functions, used to get the machine information: 1, get the registry key value: here judge Norton's virus library version void cinfoshowdlg :: getnortonversion () {hkey hkey; long result = regopenkey (HKEY_LOCAL_MACHINE, "Software // Intel // LANDESK // VirusProtect6 // CurrentVersion ", & HKey); if (Result! = 0) {AFXMessageBox (" Unable to open the registry key value! "); Return;} DWORD DATALEN, TYPE; BYTE DATA [80]; Result = RegQueryValueex (HKEY, "PatternfileDate", NULL, & TYPE, DATA, & DATALEN; if (Result! = 0) {AFXMESSAGEBOX ("Unable to read the corresponding value!"); regcloseKey (HKEY); Return;}
CHAR TMP; int years, months, days;
TMP = data [0]; years = TMP% 10;
TMP = DATA [1]; MONTHS = TMP 1;
TMP = DATA [2]; days = TMP;
M_NORTON_VERSION.FORMAT ("200% D.% D.% D", Years, Months, Days); RegcloseKey (HKEY);} 2, Hard Disk Space: CString Cinfoshowdlg :: GetDisk (Char * Disk) {_ularge_integer result_freespace, result_totalspace, Result_g; cstring disk_space; int error = 0; int free_space, total_space; int free_percent;
/ * Get free space * / GetDiskFreeSpaceEx (disk, & result_freespace, & result_totalspace, & result_g); if (error = 0!) {CString t; t.Format ( "GetDiskFreeSpace () error =% d", error); AfxMessageBox (t) }
free_space = result_freespace.QuadPart / 1024/1024; total_space = result_totalspace.QuadPart / 1024/1024; free_percent = (float) free_space / total_space * 100; disk_space.Format ( "% dM /% dM (% d %%)", free_space , total_space, free_percent;
return disk_space;} 3, to obtain machine name, ip address: void CInfoshowDlg :: GetHostName () {WORD wVersionRequested; WSADATA wsaData; char name [255]; CString ip; PHOSTENT hostinfo; wVersionRequested = MAKEWORD (2,0); if ( WSASTARTUP (WVersionRequested, & WSADATA) == 0) {IF (getHostName (Name, SizeOf (Name)) == 0) {IF ((HostInfo = gethostByname (NAME))! = Null) {ip = inet_ntoa (* (struct in_addr *) * Hostinfo-> h_addr_list);}}
WSACLANUP ();} m_ipaddr = ip; m_hostname.format ("% s", name);} 4, network status: Create a socket, ping yourself. Int cinfoshowdlg :: getnetState () {sockaddr_in pingsoscket; int confd, error
m_net_state.format ("OFF"); CreateThread (NULL, 0, CreatePort, NULL, 0, 0); IF (StrCMP (m_ipaddr, "127.0.0.1") == 0) {Updatedata (false); return -1; } Memset (& pingsocket); pingsocket.sin_family = Af_Inet; pingsocket.sin_addr.s_addr = inet_addr (m_ipaddr); pingsocket.sin_port = htons (ping_port);
Confd = Socket (AF_INET, SOCK_STREAM, 0); Error = Connect (Confd, (Struct SockAddr *) & pingsocket, sizeof (SockAddr_in)); error = send (confd, "!", 1, 0); if (error == 0) {/ * * The net is off, but we must send a char to thread this we create * / pingsocket.sin_addr.s_addr = inet_addr ("127.0.0.1"); connection (confd, (struct sockaddr *) & pingsocket, SIZEOF (SOCKADDR_IN)); Send (confd, "!", 1, 0); Updatedata (false); return -1;} m_net_state.format ("on"); Updatedata (false); return 0;}