Jump to content

Recommended Posts

Posted (edited)

Purpose: To be able to easily shutdown a PC you are connected to in an RDP (Remote Desktop) session, and also give other users logged in the ability to cancel the shutdown or save their work.

I mainly wrote this because there is no shutdown option on the start menu in an RDP session, you need to open the task manager and select turn off from the shutdown menu. So this is a shortcut, and it also has a few other features like allowing the user to cancel the shutdown (Provided by Beyondexec).

#Include <process.au3>
#include <GuiConstants.au3>

Opt("WinTitleMatchMode", 4)
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode 

FileInstall("c:\shutdown.jpg", @TempDir & "\"); Files to include, you must copy these to c:\ obviously before compiling.
FileInstall("c:\turnoff.bmp", @TempDir & "\")
FileInstall("c:\reboot.bmp", @TempDir & "\")
FileInstall("c:\cancel.bmp", @TempDir & "\")
FileInstall("c:\bexec.exe", @TempDir & "\")

$mainwindow = GuiCreate("Remote Shutdown", 314, 200, @DesktopWidth / 2 - 157, @DesktopHeight / 2 - 100, $WS_POPUP); Create GUI
GuiSetIcon("shell32.dll", 27)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

GUICtrlCreatePic(@TempDir & "\shutdown.jpg", 0, 0, 314, 200); Use Picture of Windows Shutdown Dialog
GUICtrlSetState(-1, $GUI_DISABLE)

$button1 = GUICtrlCreateButton ("", 141,81,33,33,$BS_BITMAP,); Replace buttons we need to use with our own
GUICtrlSetImage(-1, @TempDir & "\turnoff.bmp")
GUICtrlSetOnEvent(-1, "button1")

$button2 = GUICtrlCreateButton ("", 226,81,33,33,$BS_BITMAP)
GUICtrlSetImage(-1, @TempDir & "\reboot.bmp")
GUICtrlSetOnEvent(-1, "button2")

$button3 = GUICtrlCreateButton ("", 243,168,61,21,$BS_BITMAP)
GUICtrlSetImage(-1, @TempDir & "\cancel.bmp")
GUICtrlSetOnEvent(-1, "CLOSEClicked")

GUISwitch($mainwindow)
GUISetState(@SW_SHOW)

While 1

    Sleep(1000)

WEnd

Func button1()
; User selected to turn off PC
    GUISetState(@SW_HIDE)
    _RunDos(@TempDir & "\bexec \\" & @ComputerName & " -d shutdown -f -m ""Shutdown procedure has been initiated by " & @Username & """" )
    Exit
EndFunc

Func button2()
; User selected to reboot PC
    _RunDos(@TempDir & "\bexec \\" & @ComputerName & " -d reboot -f -m ""Reboot procedure has been initiated by " & @Username & """" )
    Exit
EndFunc

Func CLOSEClicked()
; User cancelled Shutdown procedure or pressed alt-f4
; So we exit script.
    Exit
EndFunc

Icon and images are attached in zip file.

Shutdown.zip

Edited by Abu Rashid
Posted

As stated the point of the script is to save clicks.

And why even bother going to start->run

Just press windws-key + r.

Also the ability to warn others users logged in is one of the main features here, not just getting the PC shut down.

Posted

big daddy, what exactly does that do?

[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...