in reply to (tye)Re: NT RPC and Shutdown.
in thread NT RPC and Shutdown.

If you have rights or access to a userid with rights, use Win32::Lanman or Win32::NetResource to map to the remote machine's ipc$ share (w/o drive letter) as that userid (or do a net use \\remotehost\ipc$ * /user:[domain\]userid. If I remember right you must have 'Allow user to logon from the network' and 'Allow user to shutdown the system' rights. Then call
Win32::InitiateSystemShutdown( $machine, $message, $count, $force, $reboot );

Returns true (1) on success, which you will capture, of course.

Remember:

$machine should have either \\\\ or // prepended to the hostname/IP address or simply "" for localhost

$message is a quoted text string to display in the pop-up on $machine

$count is the number of seconds for a countdown to shutdown/reboot

$force = 1 means applications will die in an undignified mannor, not saving data. 0 means apps will try to die gracefully, but may hang the request.

$reboot = 1 the box will reboot versus a shutdown (0)

HTH!
Dex

p.s. - there is a matching Win32::AbortSystemShutdown which, if sent before $count seconds from above, will cancel the shutdown.

Replies are listed 'Best First'.
(tye)Re4: NT RPC and Shutdown.
by tye (Sage) on Mar 15, 2001 at 22:29 UTC

    BTW, thanks for the added instructions. Here some amplifications, mostly taken from the Win32API::Registry documentation I mentioned.

    For this API, you don't need "//" nor "\\\\" on the front of the machine name (though they don't hurt either).

    $message is a quoted text string to display in the pop-up on $machine

    I find "quoted text string" misleading here. It just needs to be a Perl string (scalar).

    If "force" is false, then any applications running on the remote computer get a chance to prompt the remote user whether they want to save changes. Also, for any applications that do not exit quickly enough, the operating system will prompt the user whether they wish to wait longer for the application to exit or force it to exit now. At any of these prompts the user can press CANCEL to abort the shutdown but if no applications have unsaved data, they will likely all exit quickly and the shutdown will progress with the remote user having no option to cancel the shutdown.

    If "force" is true, all applications are told to exit immediately and so will not prompt the user even if there is unsaved data. Any applications that take too long to exit will be forcibly killed after a short time. The only way to abort the shutdown is to call AbortSystemShutdown() before the timeout expires and there is no way to abort the shutdown once it has begun.

            - tye (but my friends call me "Tye")
Re: Re: Re: NT RPC and Shutdown.
by Blue (Hermit) on Mar 15, 2001 at 00:16 UTC
    there is a matching Win32::AbortSystemShutdown which, if sent before $count seconds from above, will cancel the shutdown

    Great, so I'll make a "self-destruct button" that causes a shutdown in a specified amount of time, with a nice big pTK countdown and a red button to abort it, like any good self-destruct sequence should have.

    =Blue
    ...you might be eaten by a grue...

      The NT shutdown already has a big countdown window (but no abort button), BTW. (:

              - tye (but my friends call me "Tye")
        Ah, my UNIX-hood is showing through. It just seemed so dramatically appropriate, in a "B" movie sort of way.

        Of course I can do the same for my UNIX servers, but no one but me is looking at the console, anyhow, so it's not as fun. 8)

        =Blue
        ...you might be eaten by a grue...