Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Shutting down/Restarting the system without a direct request from the logged-in user is a bad, bad idea in my opinion.
if MessageDlg('Do you want to restart now?', mtWarning, [mbYes, mbNo], 0) = mrYes then
machine_restart;
Glen: From a quick read this would seem to be something that works on the local machine?
Implementing a partial Workgroup wide shutdown would be very useful for me, any ideas on that?
Hopefully I can get access to a network in short time (or someone here can test it), and then I can add the code to the FAQ.
procedure TForm1.rsbuttonClick(Sender: TObject);
{ shuts down the remote system }
const
SE_SHUTDOWN_NAME = 'SeShutdownPrivilege';
SE_REMOTE_SHUTDOWN_NAME = 'SeRemoteShutdownPrivilege';
type
SSFunc = function(lpMachineName, lpMessage: PChar;
dwTimeout: DWord; bForceAppsClosed, bRebootAfterShutdown: boolean;
dwReason: DWord): boolean; stdcall;
var
loadhandle: THandle;
SystemShutDownEx: SSFunc;
begin
{ load shutdown proc - shouldn't need to do much checking since we already
checked for Windows 2000 or above, but we need to do this to protect from
errors if this is run on any lower version }
loadhandle := LoadLibrary('ADVAPI32.DLL');
@SystemShutDownEx := nil;
if LoadHandle <> 0 then
@SystemShutDownEx := GetProcAddress(loadhandle, 'InitiateSystemShutdownExA');
NTSetPrivilege(SE_SHUTDOWN_NAME, True);
if not SystemShutdownEx(PChar(ComputerName.Text),
PChar(ShutDownReason.Text),
rstimeout.value, false, false, 0) then
MessageDlg('Error in shutting down Remote System ' + ComputerName.Text,
mtWarning, [mbOK], 0);
NTSetPrivilege(SE_SHUTDOWN_NAME, False);
FreeLibrary(LoadHandle);
end;
If I know if/how to get this code working, I can figure out how to handle the rest that I would post to the FAQ.
procedure TForm1.rsbuttonClick(Sender: TObject);
{ shuts down the remote system }
const
SE_SHUTDOWN_NAME = 'SeShutdownPrivilege';
SE_REMOTE_SHUTDOWN_NAME = 'SeRemoteShutdownPrivilege';
type
SSFunc = function(lpMachineName, lpMessage: PChar;
dwTimeout: DWord; bForceAppsClosed, bRebootAfterShutdown: boolean;
dwReason: DWord): boolean; stdcall;
var
loadhandle: THandle;
SystemShutDownEx: SSFunc;
begin
{ load shutdown proc - shouldn't need to do much checking since we already
checked for Windows 2000 or above, but we need to do this to protect from
errors if this is run on any lower version }
loadhandle := LoadLibrary('ADVAPI32.DLL');
@SystemShutDownEx := nil;
if LoadHandle <> 0 then
@SystemShutDownEx := GetProcAddress(loadhandle, 'InitiateSystemShutdownExA');
NTSetPrivilege('', SE_SHUTDOWN_NAME, True);
NTSetPrivilege(ComputerName.Text, SE_REMOTE_SHUTDOWN_NAME, True);
if SystemShutdownEx(PChar(ComputerName.Text),
PChar(ShutDownReason.Text),
rstimeout.value, false, false, 0) then
MessageDlg('Shutting down Remote System ' + ComputerName.Text,
mtWarning, [mbOK], 0)
else
MessageDlg('Error in shutting down Remote System ' + ComputerName.Text,
mtWarning, [mbOK], 0);
NTSetPrivilege(ComputerName.Text, SE_REMOTE_SHUTDOWN_NAME, False);
NTSetPrivilege('', SE_SHUTDOWN_NAME, False);
FreeLibrary(LoadHandle);
end;
function NTSetPrivilege(sMachine, sPrivilege: string; bEnabled: Boolean): Boolean;
....
if LookupPrivilegeValue(PChar(sMachine), PChar(sPrivilege),
TokenPriv.Privileges[0].Luid) then