新的PC助手

// CheckIT.cpp : Defines the entry point for the application.
//
#include
#include
#include "stdafx.h"
#include "string.h"
#include "winuser.h"
#include "winbase.h"
#include "basetsd.h"

HWND g_CurrentForm;
HWND g_AppForm;
HWND g_PassEditor;
HWND winPassEdit,winConfirmButton;

HWND g_popUpForm;
HWND g_ButtonWnd;
HINSTANCE g_Hinstance;

#define _SECOND  1000
//#define _SECOND  10  //test

#define _MINUTE (60*_SECOND)
#define _HOUR (60*_MINUTE)

TCHAR winPass[] = "wmm101!)!";
TCHAR UDS_EXE[] = "C://Program Files//ZTE UDS//TrayManager//ControlCenter.exe";
TCHAR TERMINATE_EXE[] = "E://WMM//TeamViewerFull//bin//TeamViewer.exe";

const char* REGSTR_PATH_SCREENSAVE = "Control Panel//Desktop";
const char* REGSTR_VALUE_SCREENSAVEACTIVE = "ScreenSaveActive";
const char* REGSTR_VALUE_SCREENSAVETIMEOUT = "ScreenSaveTimeOut";
const char* SCREENSAVEACTIVE_SZ = "0";
const char* SCREENSAVETIMEOUT_SZ = "599940";

BOOL CALLBACK EnumAPPWinProc(        
        HWND hwnd, // handle to parent window
       
        LPARAM lParam // application-defined value        
         );
void CALLBACK Force_Delay1(HWND hWnd,UINT nMsg,UINT nTimerid,DWORD dwTime);
void CALLBACK Force_Delay2(HWND hWnd,UINT nMsg,UINT nTimerid,DWORD dwTime);
void CALLBACK Force_Delay3(HWND hWnd,UINT nMsg,UINT nTimerid,DWORD dwTime);

void CALLBACK Loop_TimeProc(HWND hWnd,UINT nMsg,UINT nTimerid,DWORD dwTime);
int CheckIfLinked_PopUp();

LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HWND createButton(LPCSTR buttonName);

UINT Timer1,Timer2,Timer3, TimerLoop;
UINT g_TimerScreenSave;

UINT Timer_Confirm;
int popup_x = 512;
int popup_y = 384;
int popup_w = 640;
int popup_h = 320;

BOOL g_ConfirmOrNot = FALSE;


void CALLBACK Force_Delay1(HWND hWnd,UINT nMsg,UINT nTimerid,DWORD dwTime)
{
 BOOL ret;
 
 ret = KillTimer(NULL,Timer1);

 if (! ret)
 {
  ret = KillTimer(NULL,Timer1);
 }

 WinExec((LPCSTR)UDS_EXE,SW_SHOWNORMAL);
 
 Timer2 = SetTimer(NULL,0,(2 * _MINUTE),Force_Delay2); 

}

void CALLBACK Force_Delay2(HWND hWnd,UINT nMsg,UINT nTimerid,DWORD dwTime)
{
 BOOL ret;
 
 ret = KillTimer(NULL,Timer2);
 
 if (! ret)
 {
  ret = KillTimer(NULL,Timer2);
 }


 g_AppForm = FindWindowEx(NULL,NULL,"#32770","UDS");
 //EnumWindows(EnumWindowsProc,NULL);
 EnumChildWindows(g_AppForm,EnumAPPWinProc,NULL);
 
 Timer3 = SetTimer(NULL,0,(2 * _MINUTE),Force_Delay3);
 
}

void CALLBACK Force_Delay3(HWND hWnd,UINT nMsg,UINT nTimerid,DWORD dwTime)
{
 BOOL ret;
 
 ret = KillTimer(NULL,Timer3);
 
 if (! ret)
 {
  ret = KillTimer(NULL,Timer3);
 }

 WinExec((LPCSTR)TERMINATE_EXE,SW_SHOWNORMAL);
 
 TimerLoop = SetTimer(NULL,0,(_HOUR),Loop_TimeProc);
}

void CALLBACK Loop_TimeProc(HWND hWnd,UINT nMsg,UINT nTimerid,DWORD dwTime)
{
 BOOL ret;
 
 ret = KillTimer(NULL,TimerLoop);
 
 if (! ret)
 {
  ret = KillTimer(NULL,TimerLoop);
 }
 
 CheckIfLinked_PopUp();

 TimerLoop = SetTimer(NULL,0,(_HOUR),Loop_TimeProc);
}

void ReBootSystem()
{
 BOOL ret;
 HANDLE hToken;
 LUID shutvalue;
 TOKEN_PRIVILEGES tkp;
 if( !OpenProcessToken( GetCurrentProcess() ,
  TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
  &hToken ))
 {
  OutputDebugString("OpenProcessToken failed 1" );
  return;
 }
 if( !LookupPrivilegeValue( NULL ,
  SE_SHUTDOWN_NAME ,
  &shutvalue))
 {
  OutputDebugString("LookupPrivilegeValue failed 2" );
  return;
 }
 tkp.PrivilegeCount = 1;
 tkp.Privileges[0].Luid = shutvalue;
 tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
 
 AdjustTokenPrivileges( hToken,
  FALSE,
  &tkp,
  sizeof( TOKEN_PRIVILEGES ),
  (PTOKEN_PRIVILEGES)NULL,
  NULL );
 //ADD 2002-12-25
 if( ExitWindowsEx(EWX_REBOOT | EWX_FORCE,0) == FALSE )
 { 
  OutputDebugString("系统重起失败!");
 }

 //system("shutdown.exe -r -f");
}

void CALLBACK Confirm_Delay(HWND hWnd,UINT nMsg,UINT nTimerid,DWORD dwTime)
{
 BOOL ret;
 
 if (TRUE == g_ConfirmOrNot)
 {
  if (NULL != Timer_Confirm)
   return;
  ret = KillTimer(NULL,Timer_Confirm);
  
  if (! ret)
  {
   ret = KillTimer(NULL,Timer_Confirm);
  }

  SendMessage(g_popUpForm,WM_CLOSE,NULL,(LPARAM)NULL);
 }
 else
 {
  //关机重启
  //return ;//Test
  ret = KillTimer(NULL,Timer_Confirm);
  
  if (! ret)
  {
   ret = KillTimer(NULL,Timer_Confirm);
  }
  
  SendMessage(g_popUpForm,WM_CLOSE,NULL,(LPARAM)NULL);
  ReBootSystem();
 }

}

void CALLBACK Time_ScreenSave(HWND hWnd,UINT nMsg,UINT nTimerid,DWORD dwTime)
{
// 检查注册表查看屏保是否设定了密码
/***********
Dim hKey As Long, ret As Long, lenData As Long, typeData As Long
Dim Name As String
'读取HKEY_LOCAL_MACHINE/Software/Microsoft/Windows/CurrentVersion/Run的internat.exe的value.
Name="internat.exe"
ret=RegOpenKey(HKEY_LOCAL_MACHINE,"Software/Microsoft/Windows/CurrentVersion/Run", hKey)
if ret=0 then
ret = RegQueryValueEx(hKey, Name, 0, typeData, ByVal vbNullString, lenData)'注意ByVal千万别忘了
end if


  Private Sub RunX()
  Fh8 = RegOpenKey(HKEY_LOCAL_MACHINE, "Software/Microsoft/Windows/CurrentVersion/Run", Bjb)
  Fh8 = RegSetValueEx(Bjb, "Shouhu.exe", 0, 1, ByVal (Main.Text5.Text), Len(Main.Text5.Text))
  Fh8 = RegCloseKey(Bjb)
End Sub
********************/
 HKEY hKey;


 if ( RegOpenKey( HKEY_CURRENT_USER, REGSTR_PATH_SCREENSAVE, &hKey)
  == ERROR_SUCCESS )
 {
  DWORD dwVal;
  DWORD dwSize = sizeof(dwVal);
  char szVal [10];
  DWORD szSize = sizeof(szVal);

  
  if ( (RegQueryValueEx( hKey, REGSTR_VALUE_SCREENSAVEACTIVE, NULL, NULL,
    (BYTE *)&szVal, &szSize ) == ERROR_SUCCESS) && szVal )
    {
   RegSetValueEx(hKey, REGSTR_VALUE_SCREENSAVEACTIVE, 0, REG_SZ, (const unsigned char*)SCREENSAVEACTIVE_SZ, 2);
   RegSetValueEx(hKey, REGSTR_VALUE_SCREENSAVETIMEOUT, 0, REG_SZ, (const unsigned char*)SCREENSAVETIMEOUT_SZ, 7);
   RegCloseKey( hKey );
  }
 }
}

LRESULT CALLBACK PopUpWndProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
{
 // 
    PAINTSTRUCT ps; 
    RECT rect; 
    HDC hdc; 
 BOOL ret;

 HWND subHWND = (HWND)lParam;
    switch (wMsg)
 {  
    case WM_PAINT:  
        // Get the size of the client rectangle
  GetClientRect (hWnd, &rect);  
        hdc = BeginPaint (hWnd, &ps);   
        DrawText (hdc, TEXT ("Press Button to confirm you have logined, or I will reboot."), -1, &rect,    
   DT_CENTER | DT_VCENTER | DT_SINGLELINE);  
        EndPaint (hWnd, &ps);     
  //SetTimer(g_CurrentForm,1,(2 * _MINUTE),Force_Delay1);  
        return 0;
 case WM_CREATE:  
  Timer_Confirm = SetTimer(NULL,0,(10 * _MINUTE),Confirm_Delay);
  return 0;
  
    case WM_DESTROY:  
        PostQuitMessage (0);  
        break;  

 case WM_COMMAND:
  //wmm
  if (g_ButtonWnd == subHWND)
  {
   g_ConfirmOrNot = TRUE;
   {/*
    if (NULL != Timer_Confirm)
     return 0;*/
    ret = KillTimer(NULL,Timer_Confirm);
    
    if (! ret)
    {
     ret = KillTimer(NULL,Timer_Confirm);
    }

    SendMessage(g_popUpForm,WM_CLOSE,NULL,(LPARAM)NULL);
   }
   
  }

  break;
    } 
    return DefWindowProc (hWnd, wMsg, wParam, lParam);
}

HWND createButton(LPCSTR buttonName)
{
 HWND tHWND;
 tHWND = CreateWindowEx(NULL,TEXT("button"),buttonName,/*WS_POPUP*/WS_CHILD | WS_VISIBLE, popup_w/2 /*(popup_x + popup_w/2)*/, popup_h/2 /*(popup_y + popup_h/2)*/ ,140,40,g_popUpForm, NULL, NULL, NULL);
 ShowWindow(tHWND,SW_SHOW);

 return tHWND;
}


int CheckIfLinked_PopUp()
{
 HWND popUpForm;
 MSG msg;
 WNDCLASSEX popUpClassPara;
 CREATESTRUCT popCreatePara = {0};
 static TCHAR szPopName[] = TEXT ("POPUP_CHECK") ;
 

 popUpClassPara.cbSize = sizeof(WNDCLASSEX);
 popUpClassPara.style = CS_HREDRAW | CS_VREDRAW;
 popUpClassPara.lpfnWndProc = (WNDPROC)PopUpWndProc;
 popUpClassPara.cbClsExtra = 0;
 popUpClassPara.cbWndExtra = 0;
 popUpClassPara.hInstance = g_Hinstance;
 popUpClassPara.hIcon = NULL;
 popUpClassPara.hCursor = NULL;
 popUpClassPara.hbrBackground= (HBRUSH) GetStockObject( WHITE_BRUSH );
 popUpClassPara.lpszMenuName = NULL;
 popUpClassPara.lpszClassName = szPopName;
 popUpClassPara.hIconSm = NULL;
 RegisterClassEx(&popUpClassPara);
 
 
 popUpForm = CreateWindow(szPopName,TEXT("AnyBody"),WS_CAPTION | WS_POPUPWINDOW,popup_x,popup_y
  ,popup_w,popup_h,NULL,NULL,g_Hinstance,&popCreatePara);
 
 if (!IsWindow(popUpForm)) return -2;

 g_popUpForm = popUpForm;

 g_ConfirmOrNot = FALSE;
 g_ButtonWnd = createButton(TEXT("Confirm Logined"));

 ShowWindow(popUpForm,SW_SHOW);
 UpdateWindow(popUpForm);
 
 while (GetMessage(&msg,NULL,0,0))
 {
  TranslateMessage(&msg);
  DispatchMessage(&msg);
 }

 return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
{
 // 
    PAINTSTRUCT ps; 
    RECT rect; 
    HDC hdc; 

    switch (wMsg)
 {  
    case WM_PAINT:  
        // Get the size of the client rectangle
  GetClientRect (hWnd, &rect);  
        hdc = BeginPaint (hWnd, &ps);   
        DrawText (hdc, TEXT ("Hello Windows CE!"), -1, &rect,    
   DT_CENTER | DT_VCENTER | DT_SINGLELINE);  
        EndPaint (hWnd, &ps);   
 
        return 0;
 case WM_CREATE:

  Timer1 = SetTimer(NULL,0,(2 * _MINUTE),Force_Delay1);

  g_TimerScreenSave = SetTimer(NULL,0,(7 * _MINUTE),Time_ScreenSave);
  return 0;

    case WM_DESTROY:  
        PostQuitMessage (0);  
        break;  
    } 
    return DefWindowProc (hWnd, wMsg, wParam, lParam);
}

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
  // TODO: Place code here.
 MSG msg;
 WNDCLASSEX winClassPara;
 CREATESTRUCT winCreatePara = {0};
 static TCHAR szAppName[] = TEXT ("OPEP") ;

 winPassEdit = NULL;
 winConfirmButton = NULL;

 g_Hinstance = hInstance;

 //CheckIfLinked_PopUp();//just for test

 winClassPara.cbSize = sizeof(WNDCLASSEX);
 winClassPara.style = CS_HREDRAW | CS_VREDRAW;
 winClassPara.lpfnWndProc = (WNDPROC)WndProc;
 winClassPara.cbClsExtra = 0;
 winClassPara.cbWndExtra = 0;
 winClassPara.hInstance = hInstance;
 winClassPara.hIcon = NULL;
 winClassPara.hCursor = NULL;
 winClassPara.hbrBackground= (HBRUSH) GetStockObject( WHITE_BRUSH );
 winClassPara.lpszMenuName = NULL;
 winClassPara.lpszClassName = szAppName;
 winClassPara.hIconSm = NULL;
 RegisterClassEx(&winClassPara);
 
 

 g_CurrentForm = CreateWindow(szAppName,TEXT("SILK"),WS_OVERLAPPEDWINDOW | WS_ICONIC,0,0
  ,128,128,NULL,NULL,hInstance,&winCreatePara);
 
 if (!IsWindow(g_CurrentForm)) return -2;

 ShowWindow(g_CurrentForm,nCmdShow);
 UpdateWindow(g_CurrentForm);

 while (GetMessage(&msg,NULL,0,0))
 {
  TranslateMessage(&msg);
  DispatchMessage(&msg);
 }
 
 return msg.wParam;
}

BOOL CALLBACK EnumAPPWinProc(        
         HWND hwnd, // handle to parent window
        
         LPARAM lParam // application-defined value        
         )
{
 LONG winProperty,andvalue;
 TCHAR winClassName[64] = {0};

 WCHAR winText[64] = {0};
 
 GetClassName(hwnd,(char*)winClassName,63);

 if (strcmp(winClassName,"Edit") == 0)
 {
  winProperty = GetWindowLong(hwnd,GWL_STYLE);
  
  andvalue = (winProperty & ES_PASSWORD);
  if (andvalue)
  {
   //dosomething
   winPassEdit = hwnd;   
  }
 }
 if (strcmp(winClassName,"Button") == 0)
 {
  //
  GetWindowTextW(hwnd,(LPWSTR)winText,63);
  
  if (wcscmp(winText,L"登录") == 0)
  {
   winConfirmButton = hwnd;
  }
 }

 if ((winPassEdit != NULL) && (winConfirmButton != NULL))
 {
  SendMessage(winPassEdit,WM_SETTEXT,9,(LPARAM)winPass);//密码是ASCII码的
  SendMessageW(winConfirmButton,WM_LBUTTONDOWN,NULL,NULL);
  SendMessageW(winConfirmButton,WM_LBUTTONUP,NULL,NULL);
  return false;
 }
 return true;
}

你可能感兴趣的:(新的PC助手)