Sunday, January 25, 2009

Hidden Start - run apps in the background

Console applications and batch scripts are regularly run at Windows startup and in schedule. The main inconvenience of this is that every application creates a new console window which flickers on the screen. Hidden Start (or Hstart) is a small startup manager that allows console applications to be started without any windows in the background and much more. Hstart is usually started by entering the following command line:
hstart /NOCONSOLE "batch_file_1.bat" "batch_file_2.bat" "batch_file_3.bat"


Hstart is very effective if you are using console utilities for everyday tasks: daily backups, automatic source code compilation and code signing.



Hstart is very small (~12 Kb), but it allows you to:

* start multiple applications in the specified order synchronously;
* start console applications without any windows in the background;
* set the working directory and priority class of the created processes;
* handle UAC privilege elevation under Windows Vista;
* show simple messages after command execution.

Using Hstart, it is also possible to run batch files in the background and save console output into a log file:
hstart /NOCONSOLE /IDLE /D="E:\Backups\"
"cmd.exe /c "E:\Backups\backup.bat > backup-log.txt""

It is very effective if you are using console utilities for daily backups. The command line switch /IDLE means that the backup process will run with the lowest priority class, and /D="" sets the starting directory of the batch file (necessary if it uses relative paths).

Here is how it works out:
hstart /TEST "cmd.exe /k "echo "a phrase" "" with spaces "" eof""

Compare with the old algorithm:
hstart /NQ /TEST "cmd.exe /k \"echo \"a phrase\" \" with spaces \" eof\""

This will execute cmd.exe with the following parameters:
cmd.exe /k "echo "a phrase" " with spaces " eof"

And you will see: "a phrase" " with spaces " eof

Test mode

The /TEST command line switch allows you to see what parameters are passed to Hstart and how they are processed:
hstart /TEST "notepad "C:\Windows\System32\drivers\etc\hosts""

You will be prompted with an information message before executing any commands:



It is highly recommended to check all command lines with the /TEST switch before using Hstart in a real-world environment.
Message after command execution

Hstart allows you to run console applications completely hidden, and now there is a simple way to tell the user whether the command is executed correctly or not:
hstart /WAIT /MSG="Your command executed successfully."
/TITLE="Congratulations!!!" "Success.exe -parameters"

This will bring up the following message after command execution:



Here is how to set up an error message:
hstart /WAIT /ERRMSG="An error occurred while processing your request."
/ERRTITLE="Unknown Error" "Failure.exe -parameters"

The error message will be displayed only if the executed command failed:



Run applications from the Windows Shell

Essentially, the new /SHELL command line switch works in the same way as the Windows Run dialog: the given parameters are passed to the Windows Shell to be handled rather than by calling the application directly. This makes it possible for the Shell to select an appropriate program to run for a given filename.



The /SHELL command line switch is also required when running elevated and UIAccess applications under Windows Vista.
UAC privilege elevation under Windows Vista

Especially for Windows Vista users, Hstart v2.0 provides two new command line switches: /RUNAS and /UAC. The first switch is equal to the "Run as administrator" Shell command:
hstart /RUNAS "notepad.exe" "cmd.exe" "inputdoc.exe"

After running this command line, you will see three UAC confirmation dialogs: first for Notepad, second for Command Prompt and third for an unsigned application (inputdoc.exe). Here is the third UAC dialog:



Compare with the following command line:
hstart /UAC "notepad.exe" "cmd.exe" "inputdoc.exe"

In this case, you will see only one UAC confirmation dialog asking you to run Hstart executable with administrative privileges:


Hstart executable is digitally signed, so it can be used to launch other unsigned applications at Windows startup without being blocked by UAC.

Also it is possible to run batch files in the background with administrative privileges:
hstart /RUNAS /NOCONSOLE "D:\Batch Files\Requires_Admin_Privileges.bat"

Hstart is only a 14 KB download.


http://www.ntwind.com/download/hstart.zip

No comments:

Post a Comment