Re:shut down win 98
Quote
mlecal...@nospamhotmail.com wrote in message <news:3df08e31.51166449@news.dial.oleane.com>...
> I've looked in a few places but I can't seem to be able to find the
> answer to : how do i shut down progammitically win 98 (i found for nt)
> thanks
This will handle them all...need ShellAPI in uses clause:
function TformMain.Win9X: Boolean;
var
versionInfo : TOSVersionInfo;
begin
Result := False;
// set the size of the record
VersionInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
Windows.GetVersionEx(VersionInfo);
If (VersionInfo.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS) then
Result := True;
end;
function TformMain.WinExit(flags: integer): boolean;
function SetPrivilege(privilegeName: string; enable: boolean): boolean;
var tpPrev,
tp : TTokenPrivileges;
token : THandle;
dwRetLen : DWord;
begin
result := False;
OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or
TOKEN_QUERY, token);
tp.PrivilegeCount := 1;
if LookupPrivilegeValue(nil, pchar(privilegeName),
tp.Privileges[0].LUID) then
begin
if enable then
tp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED
else
tp.Privileges[0].Attributes := 0;
dwRetLen := 0;
result := AdjustTokenPrivileges(token, False, tp, SizeOf(tpPrev),
tpPrev, dwRetLen);
end;
CloseHandle(token);
end;
begin
if SetPrivilege('SeShutdownPrivilege', true) then
begin
ExitWindowsEx(flags, 0);
SetPrivilege('SeShutdownPrivilege', False)
end;
result := True;
end;
procedure TformMain.btnExitWindowsClick(Sender: TObject);
begin
Close;
If Win9X then ExitWindowsEx(EWX_SHUTDOWN, 0)
else WinExit(EWX_POWEROFF);
end;
HTH,
John