writting small app to run while logon screen showing - Programmer

This is a discussion on writting small app to run while logon screen showing - Programmer ; Hi Win 98 based network I have been trying to develop a small app that will shutdown the machines on our site at a specific time in the evening to save our technicians physically walking around to do it. The ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: writting small app to run while logon screen showing

  1. writting small app to run while logon screen showing

    Hi

    Win 98 based network

    I have been trying to develop a small app that will shutdown the machines on
    our site at a specific time in the evening to save our technicians
    physically walking around to do it. The program works fine when it executed
    via a user logging on. However, we really need the program to shut down the
    computers when nobody is logged on and there is only the logon screen
    displayed. The technicians have said that the when they tried to execute
    the code via the config.sys or autoexec the program hangs........

    I have written the program in Delphi as a 'console app' but presumably the
    problem is that my program uses calls to Windows such as 'time'?

    I'm now stuck! My code needs to log-off and shutdown if a student has left
    their machine logged on but also needs to shutdown when only the logon
    screen is present, but I'm not sure where I should be looking for the
    solution.

    Any help appreciated.

    Dave
    (remove the nospam to reply)



    program shutdown;
    uses
    Windows,
    Messages,
    SysUtils,
    Variants,
    Classes,
    Graphics,
    Controls,
    // Forms,
    // Dialogs,
    StdCtrls;

    var
    shutDownTime:TdateTime;

    function GetWindowsVersion: Word;
    var
    VerInfo: TOSVersionInfo;
    begin
    VerInfo.dwOSVersionInfoSize := SizeOf(VerInfo);
    GetVersionEx(VerInfo);
    Result := VerInfo.dwPlatformID;
    { The results are as followed: }
    {case VerInfo.dwPlatformID of
    VER_PLATFORM_WIN32S: Platform is 'Windows 3.1x running Win32s';
    VER_PLATFORM_WIN32_WINDOWS: Platform is 'Windows 95/98';
    VER_PLATFORM_WIN32_NT: Platform is 'Windows NT';
    end;}
    end;
    procedure ExitWindows32(ShutDownFlag: Word);
    { proc to Exit 32-bit Windows. ShutDownFlag is either EWX_REBOOT,
    EWX_SHUTDOWN, or EWX_LOGOFF. }

    function ChangeNTSecurityForShutdown: Boolean;
    { This func changes security rights on a WinNT machine. }
    { to give app shutdown privileges. }
    { Use proc ExitWindows32 to reboot or shutdown the machine. }
    var
    hToken : THandle;
    tkp,
    Newt : TTokenPrivileges;
    retlength : DWORD;
    begin
    Result := False;
    if OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES +
    TOKEN_QUERY, hToken) <> False then
    begin
    { Get the LUID for shutdown privilege }
    if LookupPrivilegeValue( nil, 'SeShutdownPrivilege',
    tkp.Privileges[0].Luid) = True then
    begin
    tkp.PrivilegeCount := 1; // One to set
    tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
    { Get shutdown privilege for this process }
    Result := AdjustTokenPrivileges(hToken, False, tkp,
    SizeOf(TTokenPrivileges), Newt,
    retlength);
    end;
    end;
    end;

    begin
    if GetWindowsVersion = VER_PLATFORM_WIN32_NT then
    begin
    if ChangeNTSecurityForShutdown then
    ExitWindowsEx(ShutDownFlag, 0)
    // else
    { Failed to change security rights to give us shutdown privilege. }
    // MessageDlg('Unable to modify security rights for shutdown
    privileges.', mtError, [mbOK], 0);
    end
    else
    if GetWindowsVersion = VER_PLATFORM_WIN32_WINDOWS then
    ExitWindowsEx(ShutDownFlag, 0);
    end;

    begin
    shutDownTime:= encodeTime(22,30,00,00);
    LongTimeFormat:='hh:mm:ss.z';

    repeat
    until time> shutDownTime;
    ExitWindows32(EWX_FORCE+EWX_LOGOFF + EWX_POWEROFF+ EWX_SHUTDOWN);

    end.



  2. Re: writting small app to run while logon screen showing

    You could place the following line inside a batch file,
    than call the batch file via the Task Scheduler at the
    desired time:

    C:\WINDOWS\RUNDLL32.EXE shell32.dll,SHExitWindowsEx 1

    It does not seem to care if a user is logged on or not.


    "Dave" wrote in message
    news:bfiqfr$jqh$1@news7.svr.pol.co.uk...
    > Hi
    >
    > Win 98 based network
    >
    > I have been trying to develop a small app that will shutdown the machines

    on
    > our site at a specific time in the evening to save our technicians
    > physically walking around to do it. The program works fine when it

    executed
    > via a user logging on. However, we really need the program to shut down

    the
    > computers when nobody is logged on and there is only the logon screen
    > displayed. The technicians have said that the when they tried to execute
    > the code via the config.sys or autoexec the program hangs........
    >
    > I have written the program in Delphi as a 'console app' but presumably the
    > problem is that my program uses calls to Windows such as 'time'?
    >
    > I'm now stuck! My code needs to log-off and shutdown if a student has left
    > their machine logged on but also needs to shutdown when only the logon
    > screen is present, but I'm not sure where I should be looking for the
    > solution.
    >
    > Any help appreciated.
    >
    > Dave
    > (remove the nospam to reply)
    >
    >
    >
    > program shutdown;
    > uses
    > Windows,
    > Messages,
    > SysUtils,
    > Variants,
    > Classes,
    > Graphics,
    > Controls,
    > // Forms,
    > // Dialogs,
    > StdCtrls;
    >
    > var
    > shutDownTime:TdateTime;
    >
    > function GetWindowsVersion: Word;
    > var
    > VerInfo: TOSVersionInfo;
    > begin
    > VerInfo.dwOSVersionInfoSize := SizeOf(VerInfo);
    > GetVersionEx(VerInfo);
    > Result := VerInfo.dwPlatformID;
    > { The results are as followed: }
    > {case VerInfo.dwPlatformID of
    > VER_PLATFORM_WIN32S: Platform is 'Windows 3.1x running Win32s';
    > VER_PLATFORM_WIN32_WINDOWS: Platform is 'Windows 95/98';
    > VER_PLATFORM_WIN32_NT: Platform is 'Windows NT';
    > end;}
    > end;
    > procedure ExitWindows32(ShutDownFlag: Word);
    > { proc to Exit 32-bit Windows. ShutDownFlag is either EWX_REBOOT,
    > EWX_SHUTDOWN, or EWX_LOGOFF. }
    >
    > function ChangeNTSecurityForShutdown: Boolean;
    > { This func changes security rights on a WinNT machine. }
    > { to give app shutdown privileges. }
    > { Use proc ExitWindows32 to reboot or shutdown the machine. }
    > var
    > hToken : THandle;
    > tkp,
    > Newt : TTokenPrivileges;
    > retlength : DWORD;
    > begin
    > Result := False;
    > if OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES +
    > TOKEN_QUERY, hToken) <> False then
    > begin
    > { Get the LUID for shutdown privilege }
    > if LookupPrivilegeValue( nil, 'SeShutdownPrivilege',
    > tkp.Privileges[0].Luid) = True then
    > begin
    > tkp.PrivilegeCount := 1; // One to set
    > tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
    > { Get shutdown privilege for this process }
    > Result := AdjustTokenPrivileges(hToken, False, tkp,
    > SizeOf(TTokenPrivileges),

    Newt,
    > retlength);
    > end;
    > end;
    > end;
    >
    > begin
    > if GetWindowsVersion = VER_PLATFORM_WIN32_NT then
    > begin
    > if ChangeNTSecurityForShutdown then
    > ExitWindowsEx(ShutDownFlag, 0)
    > // else
    > { Failed to change security rights to give us shutdown

    privilege. }
    > // MessageDlg('Unable to modify security rights for shutdown
    > privileges.', mtError, [mbOK], 0);
    > end
    > else
    > if GetWindowsVersion = VER_PLATFORM_WIN32_WINDOWS then
    > ExitWindowsEx(ShutDownFlag, 0);
    > end;
    >
    > begin
    > shutDownTime:= encodeTime(22,30,00,00);
    > LongTimeFormat:='hh:mm:ss.z';
    >
    > repeat
    > until time> shutDownTime;
    > ExitWindows32(EWX_FORCE+EWX_LOGOFF + EWX_POWEROFF+ EWX_SHUTDOWN);
    >
    > end.
    >
    >




+ Reply to Thread