libbysharf
asked on
A componnent to shutdown Windows NT
Hello,
Does anyone knows about a componnent for Delphi 4 to shutdown Windows NT?
Thanks a lot in advance, Libby
Does anyone knows about a componnent for Delphi 4 to shutdown Windows NT?
Thanks a lot in advance, Libby
ASKER
Thanks inthe, I'm sure it works, but it doesn't work on my computer.... People sent me some programs which are supposed to work on NT but it doesn't work when I try it .
Maybe it has something to do with the version? I have a
NT 4 Service Package 6 (workstation).
Regards, Libby
Maybe it has something to do with the version? I have a
NT 4 Service Package 6 (workstation).
Regards, Libby
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
note,
build the project save and close it and delphi then try running the exe .
(was just thinking that delphi may stop it from running if you run from inside the ide)
build the project save and close it and delphi then try running the exe .
(was just thinking that delphi may stop it from running if you run from inside the ide)
ASKER
In the end I just used a program someone wrote me in C++, and called it within my application. Thanks anyway for the effort..
just stick unit in lib or your project dir so delphi cna find it and add unit name to uses and call
ExitWindowsF(flags)
//same flags as exitwindowsex see win32.hlp for details
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.