Jump to content

Shutdown in RDP Session

Abu Rashid

Recommended Posts

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)

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")


While 1



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

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

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

Icon and images are attached in zip file.


Edited by Abu Rashid
Link to comment
Share on other sites

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...