Click here to Skip to main content
15,879,348 members
Articles / Programming Languages / C++

Spying on computer usage via keyboard hooks

Rate me:
Please Sign up or sign in to vote.
4.22/5 (8 votes)
22 Sep 20012 min read 103.2K   2.6K   49  
This program can be used to find out how your computer is being used while you are away.
//Thanks to Gilas Novik


////   RAS Connect status function
////
////   Written by Gilad Novik
////   For any questions or comments, gilad@bmidas.com


#ifndef _RASSTATUS
#define _RASSTATUS
#include <ras.h>


// We need to declare the functions type
typedef DWORD (WINAPI *RasEnumConnectionsType)(LPRASCONN lprasconn,LPDWORD lpcb,LPDWORD lpcConnections);
typedef DWORD (WINAPI *RasGetConnectStatusType)(HRASCONN hrasconn,LPRASCONNSTATUS lprasconnstatus);

#ifdef _UNICODE
#define RasFileName L"RASAPI32.DLL"
#define RasEnumConnectionsName L"RasEnumConnectionsW"
#define RasGetConnectStatusName L"RasGetConnectStatusW"
#else
#define RasFileName "RASAPI32.DLL"
#define RasEnumConnectionsName "RasEnumConnectionsA"
#define RasGetConnectStatusName "RasGetConnectStatusA"
#endif

BOOL IsRasConnected()
{
	
	HINSTANCE hLib = LoadLibrary(RasFileName);	// Try to load the library
	if (hLib == NULL){
		return FALSE;}	// Return FALSE if we can't find it

	// Get functions address
	RasEnumConnectionsType _RasEnumConnections = (RasEnumConnectionsType)GetProcAddress(hLib,RasEnumConnectionsName);
	RasGetConnectStatusType _RasGetConnectStatus = (RasGetConnectStatusType)GetProcAddress(hLib,RasGetConnectStatusName);
	BOOL bResult = FALSE;
	if (_RasEnumConnections && _RasGetConnectStatus)	// Check if it is valid pointer
	{
		RASCONN RasConn;
		RASCONNSTATUS RasConnStatus;
		RasConnStatus.dwSize = sizeof(RASCONNSTATUS);	// We need to set the size of the structure
		DWORD dwConnSize = sizeof(RASCONN);
		DWORD dwRasCount = 1;	// We only retrieve one connection
		RasConn.dwSize = dwConnSize;	// We need to set the size of the structure
		bResult =	// Let's check it out !!!
			(((*_RasEnumConnections)(&RasConn,&dwConnSize,&dwRasCount)) == 0)
				&& (((*_RasGetConnectStatus)(RasConn.hrasconn,&RasConnStatus)) == 0) 
				&& (RasConnStatus.rasconnstate == RASCS_Connected);
	}
	FreeLibrary(hLib);	// Don't forget to unload the library from memory
	return bResult;
}
#endif // _RASSTATUS

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions