Assarbad's RShutdown2 v.1.5x

May the source be with you, stranger ...

GoPyright © 2000 by -=Assarbad [GoP]=-


Introduction

Surfing the web, it's not really hard to find an application that resembles partial functionality of RShutdown2.
First - shutting down machines remotely. Second - sending messages per messenger service.

BUT it's hard to find an application as small as RShutdown2 and including its functionality ;)

Well, since I am administrator in a small NT domain, and I was fascinated by the idea to shut down machines remotely - and I am a Delphi programmer on the other hand, I decided to write this tool in Delphi. This would make me learn certain techniques and I could share them with others. Thus RShutdown2 comes with source code.

History

In Delphi you have two options, either have an empty program with almost 300 kB or using nonVCL techniques (pure Win32 API) to decrease the size of your app. As you can see I finally chose the second.

But, nevertheless the first version (RShutdown without "2" ;) was already done and used VCL + some non-standard Delphi components. This makes a program hard to download (because of 300 kB) an not portable.

 History:

 1.50
 - slightly improved design
 - redesigned the main dialog. now BOFH and NORMAL mode use the same dialog.
 1.41c
 - cosmetics: Hyperlink window class is Whistler-compatible now
 - restructured source - now it is better reusable!
 1.41b
 - fixed a bug which lets the dialog windows appear behind the main window.
 1.41a
 - fixed some minor bugs. Thanks to Jerold Schulman.
   The bugs were:
     - console did not close after job finished.
     - no "/Y" parameter to prevent prompting on local shutdown
     + some other things I recognized myself ;)
 - changed the subsystem to CONSOLE thus allowing RShutdown2 to write to an
   already available console.
   The thing with it is, that GUI and CONSOLE are defined as two separate
   subsystems. Since that information is determined by a flag in the EXE
   information records in the PE you cannot choose it during a run of a program.
   That is a program can only be either GUI or CONSOLE not both. That does not
   mean that GUI apps aren't allowed to use CONSOLEs but they are not attached
   to a native console or create a new automatically.
   Since starting a process is almost always done by the operating system, there
   is even no workaround for that problem BUT making an app CONSOLE and
   detaching that console from the app if it is not run in command-line mode.
   That's simply what I did ;)
 1.41
 - added traybar menu
 - added "domain list" button
 - release
 1.40
 - added command-line support
 1.34
 - The status button will not flicker anymore, while moving the mouse
 on an item with hint.
 - The error log will scroll to the last item on refresh.
 - Double clicking the caption bar will minimize to tray. Just like
 the "Minimize" button
 - Fixed minor bug: The currcompname variable was set even
 if the serverdialog function was not successful
 -release
 - fixed some minor bugs. Thanks to
   The bugs were:
     - console did not close after job finished.
     - no "/Y" parameter to prevent prompting on local shutdown
     + some other things I recognized myself ;)
 - changed the subsystem to CONSOLE thus allowing RShutdown2 to write to an
   already available console.
   The thing with it is, that GUI and CONSOLE are defined as two separate
   subsystems. Since that information is determined by a flag in the EXE
   information records in the PE you cannot choose it during a run of a program.
   That is a program can only be either GUI or CONSOLE not both. That does not
   mean that GUI apps aren't allowed to use CONSOLEs but they are not attached
   to a native console or create a new automatically.
   Since starting a process is almost always done by the operating system, there
   is even no workaround for that problem BUT making an app CONSOLE and
   detaching that console from the app if it is not run in command-line mode.
   That's simply what I did ;)

Copyright and licensing

RShutdown2 is Copyright ©2001 by -=Assarbad=-

COPYRIGHT AND RESTRICTIONS:
There are no restrictions for reusing source and binary. You may use it commercially and private ...

The only limitation is don't remove the copyright signature from the source files.

-= LICENSE [v1.1 - 05.11.2000] =-


THIS PROGRAM IS FREEWARE WITH SOURCE.


Because the program/source is free of charge, there is no warranty for it. The program is provided 'as is' without warranty of any kind, either expressed or implied. Should the program prove defective, you assume the cost of all necessary servicing, repair or correction.
If this program is distributed on a data storage medium for sale, the pricing has to be within the limits of 200% of the production costs. Else, if you are a distributor, you must not distribute this program on your medium. If you distribute it, I _would like_ to get a free copy (this is voluntary).
LIMITATION: If you are a monkey you are only authorized to use this program if you are currently swinging from your tail on a tree AND have 2 (two) or more bananas currently on your tree as well. You (the monkey) may not eat (or use) the program, unless 1 (one) banana is eaten first AND the 2nd (second) banana is eaten afterwards. If you work for the government or any governmental agency
... you are a monkey! Furthermore you are not allowed to use the source to make money, without sharing it with me (I'd like to have 15% ... no joke).

The source is provided under the above conditions. You may alter it as you want. The only condition is to not misrepresent its origin (Keep the file header as it is, don't remove the copyright informations). Therefore, only do not claim this source to be your mindwork - you need not to credit me or something, even if it would be nice :-)
You may wonder, why I don't call this OpenSource. Due to the very simple reason, that the existing OpenSource licenses are sooooooooooooooo looooooong and too complicated - I just wrote this simple one, which can be read within 2 minutes maximum.
[GoP]

How to use

RSHutdown2 version 1.50 improves the overall design. That is, BOFH mode and NORMAL mode use the same dialog unlike 1.4x versions.

RShutdown2 version 1.4x introduced three new features. The most important is command-line mode. The others are a tray menu and a domain listing button. More on that later.

RShutdown2 comes with three modi. Normal (NORM), BOFH and command-line mode (CMD).

NORM

Number NORM BOFH Function
1 x x Send a message to a machine. (Uses the NT messenger service)
2 x x Reboot a machine (locally or remotely ;). The message in the message field is sent as a warning.
3 x x Abort an initiated shutdown (locally or remotely).
4 x x Close the program.
5 x x Minimize window to traybar - Same as double clicking the caption bar or using the minimize box in the upper right corner.

The tray icon seen above is created. Double clicking with the left mouse button will simply restore the window. Right clicking opens a popup menu:

Functions of the traybar popup menu:

Name Function
Log off Log the current session out. Closing all processes running in this security context. Asks for confirmation.
Shutdown Shuts down the local machine. Asks for confirmation.
Reboot Shuts down the local machine and reboots afterwards. Asks for confirmation.
Power off Shuts down the local machine and switches power off if available through HAL and hardware (ATX). Asks for confirmation.
Abort Aborts an initiated shutdown process if the countdown is not at 0, yet. This is again for the local machine only.
Restore Restores the program window.
Exit Closes the program.
About Shows the About dialog.
6 x x If in NORM mode switch to BOFH mode and vice versa.
7 x x Hint button. It shows hints on the usage of several controls.
8, 9, 10 x x Buttons that add some shortcuts on Clear/Copy/Paste functions for the message field.
11 x x Message field. Type here the message which is either send or shown as warning on Reboot/Shutdown.
12 x x Duration until the Reboot/Shutdown takes effect. The user will see a warning box with the message you entered and the countdown.
13   x Contains of machine names, one per line on which to perform the respective action.
14   x Lists the names of all machines known to be in a domain/workgroup. Old content will be overwritten.
15, 16   x Load and save the name list from/to a text file.
17 x x Determines wether to perform a shutdown with reboot (which is effectively rebooting) and if to force Reboot/Shutdown. That is, killing apps without giving them a chance to close properly (e.g. with "Save" to save modified files). Default is ON [!!!] for both.
18 x   Presents a dialog that lets you choose another machine to do an action.

BOFH

For functions see the table at "NORM"

CMD

The following is text copied from the console window.
There's only one more command-line switch: "/BOFH" (without quotes). It will open the window initially in BOFH mode.

RShutdown2 (c) 2001 -=Assarbad=- [command line mode]

SYNTAX: RShutdown2 /[command type] [:"message"] /machine [machine name] /XX /Y

Instead of one machine name you may use a file with one machine name per line!

        RShutdown2 /[command type] [:"message"] /file [file name] /XX /Y

Command types are (without quotes):
        "help"          for this help screen
        "send"          to send a popup message using the messenger service
        "reboot"        to reboot a machine and optionally send a warning
        "shutdown"      to shutdown the machine and optionally send a warning
        "abort"         to abort a shutdown (abort takes NO MESSAGE TEXT!)
Parameters are:
        /XX             is durations in seconds where XXXX is a decimal number!
                        More than two digits are explicitly allowed ;)
                        Send and abort mode ignore this value.
        /Y              Will not prompt on local shutdown in CMD mode.

Note:   IN SEND-MODE YOU HAVE TO GIVE A MESSAGE. Do not forget to set a message
        in quotes nor forget to set a filename in quotes if it contains blank
        spaces. It does not matter if machine name has a trailing "\\".
        Always stick to the order of parameters.

An example would be:
RShutdown2 /shutdown :"You are kicked by Admin" /file machines.txt

Further notes

As you probably read above, that program is a CONSOLE application now. This allows you to run it in the same console you started it!

For debugging purposes I had included a statement which would make the program waiting for pressing a key after doing its job. This is fixed now.

BUT, you should note, that if the syntax is incorrect the program will also stop and wait for pressing a key which can be considered to be normal behaviour. Thus using RShutdown2 in .CMD scripts needs a syntax verification before.

About box

Frankly speaking, the about box is not just a simple about box. It is also the error log of the program. Since RShutdown2 is thread-based, it allows you to open the error-log while the actions are in progress.

Number Function
1 Closes the About box.
2 This field is used to show error codes and the according messages to the actions.
3, 4 Clear the error log or copy it to clipboard.
5, 6 These "Hyperlinks" will open your default browser or a new browser window in any open browser if pressed. One refers to my homepage the other one to my mail address (you need a mail client for that).

Have fun, -=Assarbad=-

Visit my homepage for more NT tools.



****************************************************************
****************************************************************
***        Copyright (c) 2001 by -=Assarbad [GoP]=-          ***
***       ____________                 ___________           ***
***      /\   ________\               /\   _____  \          ***
***     /  \  \       /    __________/  \  \    \  \         ***
***     \   \  \   __/___ /\   _____  \  \  \____\  \        ***
***      \   \  \ /\___  \  \  \    \  \  \   _______\       ***
***       \   \  \ /   \  \  \  \    \  \  \  \      /       ***
***        \   \  \_____\  \  \  \____\  \  \  \____/        ***
***         \   \___________\  \__________\  \__\            ***
***          \  /           /  /          /  /  /            ***
***           \/___________/ \/__________/ \/__/             ***
***                                                          ***
****************************************************************
****************************************************************