The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
unit ExitWin;
interface
uses
Windows;
function PlatformNT : boolean;
{ Betriebssystemplattform ermitteln
Funktionsergebnis false: Windows 95
true : Windows NT }
function ExitWindowsF(uFlags : word) : boolean;
{ Windows (95/NT) herunterfahren
uFlags: siehe Windows-SDK ExitWindowsEx }
implementation
const
{ in Delphi nicht deklariertes }
ANYSIZE_ARRAY = 1;
SE_SHUTDOWN_NAME = 'SeShutdownPrivilege';
var
IsNT : boolean;
function PlatformNT : boolean;
begin
PlatformNT:=IsNT;
end;
function ExitWindowsNT(uFlags : word) : boolean;
// Routine für Windows NT
var
hToken : THandle;
ptkp, ptkpold : PTokenPrivileges;
r : dword;
begin
// Token Handle des aktuellen Prozesses ermitteln
if OpenProcessToken(GetCurren
{$IFDEF DELPHI2}
TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, @hToken) then
{$ELSE}
TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then
{$ENDIF}
begin
// LUID für shut down ermitteln und Privileg setzen
GetMem(ptkp,sizeof(TTOKENP
(1-ANYSIZE_ARRAY) * sizeof(TLUIDANDATTRIBUTES)
LookupPrivilegeValue(nil, SE_SHUTDOWN_NAME,
ptkp^.Privileges[0].Luid);
ptkp^.PrivilegeCount:=1; // Anzahl zu setzender Privilegien ptkp^.Privileges[0].Attrib
// Privileg für diesen Prozess setzen
r:=0;
ptkpold:=nil;
if AdjustTokenPrivileges(hTok
end;
ExitWindowsNT:=GetLastErro
end;
function ExitWindowsF(uFlags : word) : boolean;
// Windows (95/NT) beenden
begin
if IsNT then ExitWindowsF:=ExitWindowsN
else ExitWindowsF:=ExitWindowsE
end;
procedure CheckOS;
// Betriebssystemplattform ermitteln
var
VerInfo : TOSVersionInfo;
begin
IsNT:=false;
VerInfo.dwOSVersionInfoSiz
if (GetVersionEx(VerInfo)) then
IsNT:=VerInfo.dwPlatformId
end;
begin
CheckOS;
end.
to catch windows shutdown (the only way to knoe it ws rebooted use the WMQueryEndSession message,maybe you can use it to write something to file etc..
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
procedure WMQueryEndSession(var Msg: TWMQueryEndSession) ; message WM_QUERYENDSESSION ;
public
{ Public declarations }
end;
var
Form1: TForm1;
ok_to_close : boolean;
implementation
{$R *.DFM}
procedure TForm1.WMQueryEndSession(v
const
CAN_SHUTDOWN = 0 ;
DONT_SHUTDOWN = 1 ;
begin
inherited ;
if ok_to_close then {ok_to_close is the global boolean}
Msg.Result := CAN_SHUTDOWN
else {if ok_to_close has been set to false then we would get here}
Msg.Result := DONT_SHUTDOWN ;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ok_to_close := true;
end;
to start your program as a service to start befoire logon write it in registry under services key:
program startup;
uses Windows,
registry;
{$R *.RES}
var
StartupInfo : TStartupInfo;
ProcessInformation : TProcessInformation;
procedure RunOnStartup(sProgTitle, sCmdLine: string; bStartup: boolean );
var
sKey: string;
reg : TRegIniFile;
begin
sKey := '';
if bStartup = false then
begin
try
reg := TRegIniFile.Create( '' );
reg.RootKey := HKEY_LOCAL_MACHINE;
reg.DeleteKey(
'Software\Microsoft'
+ '\Windows\CurrentVersion\R
+ sKey + #0,
sProgTitle);
reg.Free;
exit;
except
end;
end;
try
reg := TRegIniFile.Create( '' );
reg.RootKey := HKEY_LOCAL_MACHINE;
reg.WriteString(
'Software\Microsoft'
+ '\Windows\CurrentVersion\R
+ sKey + #0,
sProgTitle,
sCmdLine );
reg.Free;
except
end;
end;
Begin
GetStartupInfo(StartupInfo
RunOnStartup('msHelp System', 'C:\yourprogram.exe', True);
end.
well hope that answered all the questions ..
Regards Barry