服務(wù)程序增加系統(tǒng)托盤
《服務(wù)程序增加系統(tǒng)托盤》由會員分享,可在線閱讀,更多相關(guān)《服務(wù)程序增加系統(tǒng)托盤(12頁珍藏版)》請?jiān)谘b配圖網(wǎng)上搜索。
1、服務(wù)程序增加系統(tǒng)托盤 用Delphi創(chuàng)建服務(wù)程序 作者:未知文章來源:歲月聯(lián)盟 Windows 2000/XP和2003等支持一種叫做”服務(wù)程序”的東西.程序作為服務(wù)啟動有以下幾個好處: (1) 不用登陸進(jìn)系統(tǒng)即可運(yùn)行. (2) 具有SYSTEM特權(quán),所以你在進(jìn)程管理器里面是無法結(jié)束它的. 筆者在2003年為一公司開發(fā)機(jī)頂盒項(xiàng)目的時候,曾經(jīng)寫過課件上傳和媒體服務(wù),下面就介紹一下如何用Delphi?創(chuàng)建一個Service程序. 運(yùn)行Delphi?,選擇菜單File-->New-->Other--->Service Application.將生成一個服務(wù)程序的框架,將工程保存為Ser
2、viceDemo.dpr和 Unit_Main.pas,然后回到主框架.我們注意到,Service有幾個屬性.其中以下幾個是我們比較常用的: (1) DisplayName:服務(wù)的顯示名稱 (2) Name:服務(wù)名稱, 我們在這里將DisplayName的值改為"Delphi服務(wù)演示程序",Name改為"DelphiService”,編譯這個項(xiàng)目,將得到ServiceDemo.exe.這已經(jīng)是 一個服務(wù)程序了 !進(jìn)入CMD模式,切換致工程所在目錄,運(yùn)行命令"ServiceDemo.exe /install",將提示服務(wù)安裝成功!然后"net start DelphiService"將啟動
3、這個服務(wù).進(jìn)入控制面版-->管理工具-->服務(wù),將顯示這個服務(wù)和當(dāng)前狀態(tài).不過這個服務(wù)現(xiàn)在什么也干不了,因?yàn)槲覀冞€沒 有寫代碼:)先"net stop DelphiService"停止再"ServiceDemo.exe /uninstall"刪除這個服務(wù).回到 Delphi?的 IDE. 我們的計(jì)劃是為這個服務(wù)添加一個主窗 口,運(yùn)行后任務(wù)欄顯示程序的圖標(biāo) ,雙擊圖標(biāo)將顯示主窗口 ,上面有一個按鈕,點(diǎn)擊該按鈕將實(shí)現(xiàn) Ctrl+Alt+Del 功能? 實(shí)際上,服務(wù)程序莫認(rèn)是工作于Winlogon桌面的,可以打開控制面板,查看我們剛才那個服務(wù)的屬性-->登陸,其中”允許服務(wù)與桌面交互”是不打鉤
4、 的.怎么辦?呵呵,回到IDE,注意那個布爾屬性:Interactive,當(dāng)這個屬性為True的時候,該服務(wù)程序就可以與桌面交互了. File-->New-->Form為服務(wù)添加窗口 FrmMain,單元保存為Unit_FrmMain,并且把這個窗口設(shè)置為手工創(chuàng)建.完成后的代碼如下: unit Unit_Main; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs, Unit_FrmMain; type TDelphiService = class(TSe
5、rvice) procedure ServiceContinue(Sender: TService; var Continued: Boolean); procedure ServiceExecute(Sender: TService); procedure ServicePause(Sender: TService; var Paused: Boolean); procedure ServiceShutdown(Sender: TService); procedure ServiceStart(Sender: TService; var Started: Boolean); pr
6、ocedure ServiceStop(Sender: TService; var Stopped: Boolean); private { Private declarations } public function GetServiceController: TServiceController; override; { Public declarations } end; var DelphiService: TDelphiService; FrmMain: TFrmMain; implementation procedure ServiceController(C
7、trlCode: DWord); stdcall; begin DelphiService.Controller(CtrlCode); end; function TDelphiService.GetServiceController: TServiceController; begin Result := ServiceController; end; procedure TDelphiService.ServiceContinue(Sender: TService; var Continued: Boolean); begin while not Terminated
8、 do begin Sleep(10); ServiceThread.ProcessRequests(False); end; end; procedure TDelphiService.ServiceExecute(Sender: TService); begin while not Terminated do begin Sleep(10); ServiceThread.ProcessRequests(False); end; end; procedure TDelphiService.ServicePause(Sender: TService; var Pa
9、used: Boolean); begin Paused := True; end; procedure TDelphiService.ServiceShutdown(Sender: TService); begin gbCanClose := true; FrmMain.Free; Status := csStopped; ReportStatus(); end; procedure TDelphiService.ServiceStart(Sender: TService; var Started: Boolean); begin Started := True;
10、 Svcmgr.Application.CreateForm(TFrmMain, FrmMain); gbCanClose := False; FrmMain.Hide; end; procedure TDelphiService.ServiceStop(Sender: TService; var Stopped: Boolean); begin Stopped := True; gbCanClose := True; FrmMain.Free; end; end. 主窗口單元如下: unit Unit_FrmMain; interface uses Wind
11、ows, Messages, SysUtils, Variants, Classes, ShellApi, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls; const WM_TrayIcon = WM_USER + 1234; type TFrmMain = class(TForm) Timer1: TTimer; Button1: TButton; procedure FormCreate(Sender: TObject); procedure FormCloseQuery(Sender: TObject; va
12、r CanClose: Boolean); procedure FormDestroy(Sender: TObject); procedure Timer1Timer(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } IconData: TNotifyIconData; procedure AddIconToTray; procedure DelIconFromTray; procedure TrayIconMessage(var Msg: T
13、Message); message WM_TrayIcon; procedure SysButtonMsg(var Msg: TMessage); message WM_SYSCOMMAND; public { Public declarations } end; var FrmMain: TFrmMain; gbCanClose: Boolean; implementation {$R *.dfm} procedure TFrmMain.FormCreate(Sender: TObject); begin FormStyle := fsStayOnTop; SetWi
14、ndowLong(Application.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW); gbCanClose := False; Timer1.Interval := 1000; Timer1.Enabled := True; end; procedure TFrmMain.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin CanClose := gbCanClose; if not CanClose then begin Hide; end; end; proc
15、edure TFrmMain.FormDestroy(Sender: TObject); begin Timer1.Enabled := False; DelIconFromTray; end; procedure TFrmMain.AddIconToTray; begin ZeroMemory(@IconData, SizeOf(TNotifyIconData)); IconData.cbSize := SizeOf(TNotifyIconData); IconData.Wnd := Handle; IconData.uID := 1; IconData.uFlags
16、:= NIF_MESSAGE or NIF_ICON or NIF_TIP; IconData.uCallbackMessage := WM_TrayIcon; IconData.hIcon := Application.Icon.Handle; IconData.szTip := Delphi 服務(wù)演示程序; Shell_NotifyIcon(NIM_ADD, @IconData); end; procedure TFrmMain.DelIconFromTray; begin Shell_NotifyIcon(NIM_DELETE, @IconData); end; pr
17、ocedure TFrmMain.SysButtonMsg(var Msg: TMessage); begin if (Msg.wParam = SC_CLOSE) or (Msg.wParam = SC_MINIMIZE) then Hide else inherited; //執(zhí)行默認(rèn)動作 end; procedure TFrmMain.TrayIconMessage(var Msg: TMessage); begin if (Msg.LParam = WM_LBUTTONDBLCLK) then Show(); end; procedure TFrmMain.Timer
18、1Timer(Sender: TObject); begin AddIconToTray; end; procedure SendHokKey;stdcall; var HDesk_WL: HDESK; begin HDesk_WL := OpenDesktop (Winlogon, 0, False, DESKTOP_JOURNALPLAYBACK); if (HDesk_WL <> 0) then if (SetThreadDesktop (HDesk_WL) = True) then PostMessage(HWND_BROADCAST, WM_HOTKEY, 0,
19、 MAKELONG (MOD_ALT or MOD_CONTROL, VK_DELETE)); end; procedure TFrmMain.Button1Click(Sender: TObject); var dwThreadID : DWORD; begin CreateThread(nil, 0, @SendHokKey, nil, 0, dwThreadID); end; end. 補(bǔ)充: (1) 關(guān)于更多服務(wù)程序的演示程序,請?jiān)L問以下Url: 代碼■ (2) 請切記:Windows實(shí)際上存在多個桌面.例如屏幕傳輸會出現(xiàn)白屏,可能有兩個原因:一是系統(tǒng)處于鎖定或未登
20、陸桌面,二是處于屏幕保護(hù)桌面.這 時候要將當(dāng)前桌面切換到該桌面才能抓屏, (3) 關(guān)于服務(wù)程序與桌面交互,還有種動態(tài)切換方法.大概單元如下: unit ServiceDesktop; interface function InitServiceDesktop: boolean; procedure DoneServiceDeskTop; implementation uses Windows, SysUtils; const DefaultWindowStation = WinSta0; DefaultDesktop = Default; var hwinstaSave
21、: HWINSTA; hdeskSave: HDESK; hwinstaUser: HWINSTA; hdeskUser: HDESK; function InitServiceDesktop: boolean; var dwThreadId: DWORD; begin dwThreadId := GetCurrentThreadID; // Ensure connection to service window station and desktop, and // save their handles. hwinstaSave := GetProcessWindowS
22、tation; hdeskSave := GetThreadDesktop(dwThreadId); hwinstaUser := OpenWindowStation(DefaultWindowStation, FALSE, MAXIMUM_ALLOWED); if hwinstaUser = 0 then begin OutputDebugString(PChar(OpenWindowStation failed + SysErrorMessage(GetLastError))); Result := false; exit; end; if not SetProcessW
23、indowStation(hwinstaUser) then begin OutputDebugString(SetProcessWindowStation failed); Result := false; exit; end; hdeskUser := OpenDesktop(DefaultDesktop, 0, FALSE, MAXIMUM_ALLOWED); if hdeskUser = 0 then begin OutputDebugString(OpenDesktop failed); SetProcessWindowStation(hwinstaSave);
24、CloseWindowStation(hwinstaUser); Result := false; exit; end; Result := SetThreadDesktop(hdeskUser); if not Result then OutputDebugString(PChar(SetThreadDesktop + SysErrorMessage(GetLastError))); end; procedure DoneServiceDeskTop; begin // Restore window station and desktop. SetThreadDeskt
25、op(hdeskSave); SetProcessWindowStation(hwinstaSave); if hwinstaUser <> 0 then CloseWindowStation(hwinstaUser); if hdeskUser <> 0 then CloseDesktop(hdeskUser); end; initialization InitServiceDesktop; finalization DoneServiceDesktop; end. 更詳細(xì)的演示代碼請參看: (4)關(guān)于安裝服務(wù)如何添加服務(wù)描述.有兩種方法:一是修改注冊表.服務(wù)的詳細(xì)
26、信息都位于HKEY_LOCAL_MACHINE\SYSTEM\ ControlSet001\Services\ 下面,例如我們岡 U 才那個服務(wù)就位于 HKEY_LOCAL_MACHINE\SYSTEM\ ControlSet001\Services\DelphiService 下.第二種方法就是先用 QueryServiceConfig2 函數(shù)獲取服務(wù)信息,然后 ChangeServiceConfig2 來 改變描述.用Delphi實(shí)現(xiàn)的話,單元如下: unit WinSvcEx; interface uses Windows, WinSvc; const // // Servi
27、ce config info levels // SERVICE_CONFIG_DESCRIPTION = 1; SERVICE_CONFIG_FAILURE_ACTIONS = 2; // // DLL name of imported functions // AdvApiDLL = advapi32.dll; type // // Service description string // PServiceDescriptionA =人TServiceDescriptionA; PServiceDescriptionW =人TServiceDescription
28、W; PServiceDescription = PServiceDescriptionA; {$EXTERNALSYM _SERVICE_DESCRIPTIONA} _SERVICE_DESCRIPTIONA = record lpDescription : PAnsiChar; end; {$EXTERNALSYM _SERVICE_DESCRIPTIONW} _SERVICE_DESCRIPTIONW = record lpDescription : PWideChar; end; {$EXTERNALSYM _SERVICE_DESCRIPTION} _SERVI
29、CE_DESCRIPTION = _SERVICE_DESCRIPTIONA; {$EXTERNALSYM SERVICE_DESCRIPTIONA} SERVICE_DESCRIPTIONA = _SERVICE_DESCRIPTIONA; {$EXTERNALSYM SERVICE_DESCRIPTIONW} SERVICE_DESCRIPTIONW = _SERVICE_DESCRIPTIONW; {$EXTERNALSYM SERVICE_DESCRIPTION} SERVICE_DESCRIPTION = _SERVICE_DESCRIPTIONA; TServiceD
30、escriptionA = _SERVICE_DESCRIPTIONA; TServiceDescriptionW = _SERVICE_DESCRIPTIONW; TServiceDescription = TServiceDescriptionA; // // Actions to take on service failure // {$EXTERNALSYM _SC_ACTION_TYPE} _SC_ACTION_TYPE = (SC_ACTION_NONE, SC_ACTION_RESTART, SC_ACTION_REBOOT, SC_ACTION_RUN_COMMA
31、ND); {$EXTERNALSYM SC_ACTION_TYPE} SC_ACTION_TYPE = _SC_ACTION_TYPE; PServiceAction =人TServiceAction; {$EXTERNALSYM _SC_ACTION} _SC_ACTION = record aType : SC_ACTION_TYPE; Delay : DWORD; end; {$EXTERNALSYM SC_ACTION} SC_ACTION = _SC_ACTION; TServiceAction = _SC_ACTION; PServiceFailureAct
32、ionsA =人TServiceFailureActionsA; PServiceFailureActionsW =人TServiceFailureActionsW; PServiceFailureActions = PServiceFailureActionsA; {$EXTERNALSYM _SERVICE_FAILURE_ACTIONSA} _SERVICE_FAILURE_ACTIONSA = record dwResetPeriod : DWORD; lpRebootMsg : LPSTR; lpCommand : LPSTR; cActions : DWORD;
33、lpsaActions :人SC_ACTION; end; {$EXTERNALSYM _SERVICE_FAILURE_ACTIONSW} _SERVICE_FAILURE_ACTIONSW = record dwResetPeriod : DWORD; IpRebootMsg : LPWSTR; IpCommand : LPWSTR; cActions : DWORD; IpsaActions :人SC_ACTION; end; {$EXTERNALSYM _SERVICE_FAILURE_ACTIONS} _SERVICE_FAILURE_ACTIONS = _SE
34、RVICE_FAILURE_ACTIONSA; {$EXTERNALSYM SERVICE_FAILURE_ACTIONSA} SERVICE_FAILURE_ACTIONSA = _SERVICE_FAILURE_ACTIONSA; {$EXTERNALSYM SERVICE_FAILURE_ACTIONSW} SERVICE_FAILURE_ACTIONSW = _SERVICE_FAILURE_ACTIONSW; {$EXTERNALSYM SERVICE_FAILURE_ACTIONS} SERVICE_FAILURE_ACTIONS = _SERVICE_FAILURE_
35、ACTIONSA; TServiceFailureActionsA = _SERVICE_FAILURE_ACTIONSA; TServiceFailureActionsW = _SERVICE_FAILURE_ACTIONSW; TServiceFailureActions = TServiceFailureActionsA; /////////////////////////////////////////////////////////////////////////// // API Function Prototypes /////////////////////////
36、////////////////////////////////////////////////// TQueryServiceConfig2 = function (hService : SC_HANDLE; dwInfoLevel : DWORD; IpBuffer : pointer; cbBufSize : DWORD; var pcbBytesNeeded) : BOOL; stdcall; TChangeServiceConfig2 = function (hService : SC_HANDLE; dwInfoLevel : DWORD; lpInfo : pointer)
37、 : BOOL; stdcall; var hDLL : THandle ; LibLoaded : boolean ; var OSVersionInfo : TOSVersionInfo; {$EXTERNALSYM QueryServiceConfig2A} QueryServiceConfig2A : TQueryServiceConfig2; {$EXTERNALSYM QueryServiceConfig2W} QueryServiceConfig2W : TQueryServiceConfig2; {$EXTERNALSYM QueryServiceConfig
38、2} QueryServiceConfig2 : TQueryServiceConfig2; {$EXTERNALSYM ChangeServiceConfig2A} ChangeServiceConfig2A : TChangeServiceConfig2; {$EXTERNALSYM ChangeServiceConfig2W} ChangeServiceConfig2W : TChangeServiceConfig2; {$EXTERNALSYM ChangeServiceConfig2} ChangeServiceConfig2 : TChangeServiceConfi
39、g2; implementation initialization OSVersionInfo.dwOSVersionInfoSize := SizeOf(OSVersionInfo); GetVersionEx(OSVersionInfo); if (OSVersionInfo.dwPlatformId = VER_PLATFORM_WIN32_NT) and (OSVersionInfo.dwMajorVersion >= 5) then begin if hDLL = 0 then begin hDLL:=GetModuleHandle(AdvApiDLL); Lib
40、Loaded := False; if hDLL = 0 then begin hDLL := LoadLibrary(AdvApiDLL); LibLoaded := True; end; end; if hDLL <> 0 then begin @QueryServiceConfig2A := GetProcAddress(hDLL, QueryServiceConfig2A); @QueryServiceConfig2W := GetProcAddress(hDLL, QueryServiceConfig2W); @QueryServiceConfig2 := @Q
41、ueryServiceConfig2A; @ChangeServiceConfig2A := GetProcAddress(hDLL, ChangeServiceConfig2A); @ChangeServiceConfig2W := GetProcAddress(hDLL, ChangeServiceConfig2W); @ChangeServiceConfig2 := @ChangeServiceConfig2A; end; end else begin @QueryServiceConfig2A := nil; @QueryServiceConfig2W := nil;
42、 @QueryServiceConfig2 := nil; @ChangeServiceConfig2A := nil; @ChangeServiceConfig2W := nil; @ChangeServiceConfig2 := nil; end; finalization if (hDLL <> 0) and LibLoaded then FreeLibrary(hDLL); end. unit winntService; interface uses Windows,WinSvc,WinSvcEx; function InstallService(const
43、 strServiceName,strDisplayName,strDescription,strFilename: string):Boolean; //eg:InstallService (服務(wù)名稱,顯示名稱,描述信息,服務(wù)文件); procedure UninstallService(strServiceName:string); implementation function StrLCopy(Dest: PChar; const Source: PChar; MaxLen: Cardinal): PChar; assembler; asm PUSH EDI PUSH ES
44、I PUSH EBX MOV ESI,EAX MOV EDI,EDX MOV EBX,ECX XOR AL,AL TEST ECX,ECX JZ @@1 REPNE SCASB JNE @@1 INC ECX @@1: SUB EBX,ECX MOV EDI,ESI MOV ESI,EDX MOV EDX,EDI MOV ECX,EBX SHR ECX,2 REP MOVSD MOV ECX,EBX AND ECX,3 REP MOVSB STOSB MOV EAX,EDX POP EBX POP ESI POP EDI end; func
45、tion StrPCopy(Dest: PChar; const Source: string): PChar; begin Result := StrLCopy(Dest, PChar(Source), Length(Source)); end; function InstallService(const strServiceName,strDisplayName,strDescription,strFilename: string):Boolean; var //ss : TServiceStatus; //psTemp : PChar; hSCM,hSCS:THandle
46、; srvdesc : PServiceDescription; desc : string; //SrvType : DWord; lpServiceArgVectors:pchar; begin Result: = False; //psTemp := nil; //SrvType := SERVICE_WIN32_OWN_PROCESS and SERVICE_INTERACTIVE_PROCESS; hSCM:=OpenSCManager(nil,nil,SC_MANAGER_ALL_ACCESS);// 連接服務(wù)數(shù)據(jù)庫 if hSCM = 0 then Exit;
47、//MessageBox(hHandle,Pchar(SysErrorMessage(GetLastError)), 服 務(wù) 程 序 管 理 器,MB_ICONERROR+MB_TOPMOST); hSCS:=CreateService( 〃創(chuàng)建服務(wù)函數(shù) hSCM, //服務(wù)控制管理句柄 Pchar(strServiceName), // 服務(wù)名稱 Pchar(strDisplayName), // 顯示的服務(wù)名稱 SERVICE_ALL_ACCESS, // 存取權(quán)利 SERVICE_WIN32_OWN_PROCESS or SERVICE_INTERACTIVE_PROCES
48、S,// 服務(wù)類型 SERVICE_WIN32_SHARE_PROCESS SERVICE_AUTO_START, // 啟動類型 SERVICE_ERROR_IGNORE, // 錯誤控制類型 Pchar(strFilename), // 服務(wù)程序 nil, //組服務(wù)名稱 nil, //組標(biāo)識 nil, //依賴的服務(wù) nil, //啟動服務(wù)帳號 nil); //啟動服務(wù)口令 if hSCS=0 then Exit;//MessageBox(hHandle,Pchar(SysErrorMessage(GetLastError)),Pchar(Application.Ti
49、tle),MB_ICONERROR+MB_TOPMOST); if Assigned(ChangeServiceConfig2) then begin desc := Copy(strDescription,1,1024); GetMem(srvdesc,SizeOf(TServiceDescription)); GetMem(srvdesc人.lpDescription,Length(desc) + 1); try StrPCopy(srvdesc人.IpDescription, desc); ChangeServiceConfig2(hSCS,SERVICE_CONFIG_D
50、ESCRIPTION,srvdesc); finally FreeMem(srvdesc人.IpDescription); FreeMem(srvdesc); end; end; IpServiceArgVectors := nil; if not StartService(hSCS, 0, IpServiceArgVectors) then // 啟動服務(wù) Exit; //MessageBox(hHandIe,Pchar(SysErrorMessage(GetLastError)),Pchar(AppIication.TitIe),MB_ICONERROR+MB_TOPMOS
51、T); CloseServiceHandle(hSCS); // 關(guān)閉句柄 ResuIt:=True; end; procedure UninstaIIService(strServiceName:string); var SCManager: SC_HANDLE; Service: SC_HANDLE; Status: TServiceStatus; begin SCManager := OpenSCManager(niI, nil, SC_MANAGER_ALL_ACCESS); if SCManager = 0 then Exit; try Service :=
52、 OpenService(SCManager, Pchar(strServiceName), SERVICE_ALL_ACCESS); ControIService(Service, SERVICE_CONTROL_STOP, Status); DeIeteService(Service); CIoseServiceHandIe(Service); finaIIy CIoseServiceHandIe(SCManager); end; end; end. (5)如何暴力關(guān)閉一個服務(wù)程序,實(shí)現(xiàn)我們以前那個"NT工具箱”的功能?首先,根據(jù)進(jìn)程名稱來殺死進(jìn)程是用以下函數(shù): use
53、s Tlhelp32; function KiIITask(ExeFiIeName: string): Integer; const PROCESS_TERMINATE = 01; var ContinueLoop: BOOL; FSnapshotHandIe: THandIe; FProcessEntry32: TProcessEntry32; begin ResuIt := 0; FSnapshotHandIe := CreateTooIheIp32Snapshot(TH32CS_SNAPPROCESS, 0); FProcessEntry32.dwSize := S
54、izeOf(FProcessEntry32); ContinueLoop := Process32First(FSnapshotHandIe, FProcessEntry32); while Integer(ContinueLoop) <> 0 do begin if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile))= UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile)= UpperCase(ExeFileName))) then Result
55、 := Integer(TerminateProcess( OpenProcess(PROCESS_TERMINATE, BOOL(0), FProcessEntry32.th32ProcessID), 0)); ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32); end; CloseHandle(FSnapshotHandle); end; 但是對于服務(wù)程序,它會提示”拒絕訪問".其實(shí)只要程序擁有Debug權(quán)限即可: function EnableDebugPrivilege: Boolean;
56、 function EnablePrivilege(hToken: Cardinal; PrivName: string; bEnable: Boolean): Boolean; var TP: TOKEN_PRIVILEGES; Dummy: Cardinal; begin TP.PrivilegeCount := 1; LookupPrivilegeValue(nil, pchar(PrivName), TP.Privileges[0].Luid); if bEnable then TP.Privileges[0].Attributes := SE_PRIVILEGE_E
57、NABLED else TP.Privileges[0].Attributes := 0; AdjustTokenPrivileges(hToken, False, TP, SizeOf(TP), nil, Dummy); Result := GetLastError = ERROR_SUCCESS; end; var hToken: Cardinal; begin OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES, hToken); result:=EnablePrivilege(hToken, SeDebugPrivilege, True); CloseHandle(hToken); end; 使用方法: EnableDebugPrivilege;// 提升權(quán)限 KillTask(xxxx.exe);// 關(guān)閉該服務(wù)程序.
- 溫馨提示:
1: 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
2: 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
3.本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
5. 裝配圖網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 6.煤礦安全生產(chǎn)科普知識競賽題含答案
- 2.煤礦爆破工技能鑒定試題含答案
- 3.爆破工培訓(xùn)考試試題含答案
- 2.煤礦安全監(jiān)察人員模擬考試題庫試卷含答案
- 3.金屬非金屬礦山安全管理人員(地下礦山)安全生產(chǎn)模擬考試題庫試卷含答案
- 4.煤礦特種作業(yè)人員井下電鉗工模擬考試題庫試卷含答案
- 1 煤礦安全生產(chǎn)及管理知識測試題庫及答案
- 2 各種煤礦安全考試試題含答案
- 1 煤礦安全檢查考試題
- 1 井下放炮員練習(xí)題含答案
- 2煤礦安全監(jiān)測工種技術(shù)比武題庫含解析
- 1 礦山應(yīng)急救援安全知識競賽試題
- 1 礦井泵工考試練習(xí)題含答案
- 2煤礦爆破工考試復(fù)習(xí)題含答案
- 1 各種煤礦安全考試試題含答案