
StartX v1.06 An application + source code to call the CreateProcess API
Welcome to StartX, A very
simple utility to allow you to call the CreateProcess API from the command line.
Places where you might find StartX useful
are in adding an Autorun.inf file to your CD-R / DVR-R Discs. For example
suppose you have a text file called readme.txt on the root of your CD which
you would like to run it automatically by displaying it in Wordpad maximized whenever the user inserts the CD. All
you need to do is put StartX.exe, some ico file and the readme.txt files
into the root directory and create a autorun.inf file with the following
contents:
[autorun]
open=StartX.exe /MAX "wordpad.exe readme.txt"
icon=youricon.ico
The more technically minded of you may say why is there
a need to have this program since you can use "start filename" on
autorun CD's without any apparent problems. The problem with this approach
is that it does not work on NT / 2000 / XP / 2003, Vista & 2008, "start" is
implemented as an "Internal" command in cmd.exe (as opposed
to a standard exe on Win 9x) with the upshot that your CD's will not autorun
on versions of Windows based on the NT kernel. Using StartX will mean that your CD's will
autorun on all OS's which support it.
StartX includes a full superset of the commands which
the Windows 2000 / XP internal Start command provides. The full list is:
StartX ["title"] [/Dpath] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED] [/PP]
[/Uuser] [/Wpassword] [/Odomain] [/K[desktop]] [/Px,y] [/Scx1,cy1]
[/CScx2,cy2] [/FR] [/FG] [/FB] [/BR] [/BG] [/BB] [/FS] [/LP] [/LNCO] [/LOW |
/NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL] [/WAIT] [/B]
[/NOUI] [/RETURNERROR] [/AFFINITYx] ["command/program parameters"]
The
enclosed zip file contains the StartX source code and a prebuilt version of StartX.
Copyright
- You are allowed to include the source code in
any product (commercial, shareware, freeware or otherwise) when your product
is released in binary form.
- You are allowed to modify the source code in
any way you want except you cannot modify the copyright details at the top
of each module.
- If you want to distribute source code with
your application, then you are only allowed to distribute versions released
by the author. This is to maintain a single distribution point for the
source code.
- The executable file itself, namely "StartX.exe" can be
freely redistributed by anyone.
Updates
V1.0 (29
January 2003)
3 July 2004
- Now includes explicit info on the usage of the
executable "StartX.exe" in the documentation
V1.01 (20 August 2004)
- Now returns the error code back to the OS as returned
from any failures when calling the Win32 SDK calls which StartX uses.
- Now includes a /NOUI command line parameter, which
suppresses any messages boxes which can appear when an error occurs. Thanks to Trevor Hart for these 2
suggestions.
V1.02 (20 December 2004)
- Now supports a /RETURNERROR command line parameter,
which returns the error code of the process being run. Setting this
parameter implies using /WAIT. Thanks to Tomasz Nowak for
suggesting this addition.
V1.03 (19 August 2005)
- Error codes are now reported as a string by calling FormatMessage. Thanks to Dennis Bareis for prompting this update.
- String resources which are displayed to the end user now use the format IDP_...
V1.04 (17 July 2006)
- Updated copyright details.
- Optimized CMyCommandLineInfo constructor code
- Code now uses new C++ style casts rather than old style C casts where
necessary.
- CSIDL folders parameter replacement now uses the value @CSIDLnumber@
instead of just @number@. This avoids problems where you need to pass a real
"@" onto the application being controlled. Thanks to Ramon Hansman for
reporting this issue.
- Updated the documentation to use the same style as the web site.
- Replaced all calls to ZeroMemory with memset
- Code now securely deletes the domain, username and password strings once
they have been used.
- Updated the code to clean compile on VC 2005
- The code now requires the Platform SDK if compiled using VC 6.
- Code now uses SHGFP_TYPE_CURRENT instead of SHGFP_TYPE_DEFAULT when
calling SHGetFolderPath.
- Fixed a coding error where CStartXApp::InitInstance returned TRUE
instead of FALSE.
- CreateProcessWithLogonW is now used if a username is specified or if the
prompt password command line option is set.
V1.05 (8 February 2008)
- Updated copyright details.
- Removed VC 6 style AppWizard comments from the code
- Updated the code to clean compile on VC 2008
- The code and shipped exe has been updated to take advantage of VC 2005 specific
coding techniques.
- In fact the shipped exe in the zip was compiled with VC 2005 SP1.
- CStartXApp::GetErrorMessage now uses the FORMAT_MESSAGE_IGNORE_INSERTS flag.
For more information please see Raymond Chen's blog at
http://blogs.msdn.com/oldnewthing/archive/2007/11/28/6564257.aspx. Thanks
to Alexey Kuznetsov for reporting this issue.
V1.06 (11 November 2008)
- Code now compiles cleanly using Code Analysis (/analyze)
- Updated code to compile correctly using _ATL_CSTRING_EXPLICIT_CONSTRUCTORS
define
- The code has now been updated to support VC 2005 or later only.
- StartX can now set the process affinity mask via the new AFFINITY
command line option. The value you provide here is the value passed to
SetProcessAffinityMask. So for example if you wanted to limit the new
process to only run on the 2nd and 3rd CPU only of a computer then you would
use the command line "/AFFINITY6". i.e. 0x2 & 0x4. Probably the most common
value you would use for this would be "/AFFINITY1" which would limit the
process to run on the first CPU only. Please note that the value you provide
on the command line should be decimal and not hexadecimal. Thanks to "Cobus"
for prompting this update.