Windows XP run one program only

I need to run only one program on a Windows XP (32 bit) system.
If the user tries to exit the program the system must shut down.
i.e. No Presentation manager.

Is this possible ?
Who is Participating?
Hi hansw77041,

Have a look at the registry key HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\Shell.

You can put an arbitrary executable in there, which will run at logon instead of the standard explorer shell.

This will solve the first part of your problem, the next part is how to shutdown when this program is closed - there may be more registry settings which make it easy to enforce this but I don't know of them.

You could implement a WMI event sink via vbscript to respond to a particular named process ending - see code sample below for making a temporary event consumer that checks each seconds and triggers a msgbox when the specified process ends. Run the script in the background as a part of the login script for example and you have a nice way to watch for and respond to your program ending.

This is called a temporary event consumer because it's only active while the vbscript is running (eg kill wscript.exe/cscript.exe and the consumer stops). You can also make them permanent but it's not trivial, I can point you in the right direction if you want to try this path too!

strComputer = "."
processToWatch = "iexplore.exe"
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colMonitoredProcesses = objWMIService. _ 
ExecNotificationQuery("select * from __instancedeletionevent within 1 where TargetInstance isa 'Win32_Process'")
i = 0
Do While i = 0
  Set objLatestProcess = colMonitoredProcesses.NextEvent
  If ucase(objLatestProcess.TargetInstance.Name) = ucase(processToWatch) Then
    msgbox "Process " + processToWatch + " has terminated."
    'insert shutdown command here'
  End If

Open in new window

I have done this before.

I created a batch file that writes the tasklist to a text file using tasklist /v, and then the batch file searches for a particular task and if it does not exist I execute shutdown -r -t 15.  The batch file is executed via GP and runs 'hidden' and has a sleep time so that the computer boots, auto logs in and the program runs.  

If you can tie down the desktop (via GP) so users are unable to cancel the batch file running in the background and run only the single program you need to run.

This assumes you can use GP of course.

hansw77041Author Commented:
Hi ahwellsy,
One clarification please:  What is GP ?

I'll try these suggestions tomorrow.
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

hansw77041Author Commented:
Can't find   HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\Shell.

HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\ no Shell !

What am I missing ?

Ah I didn't realise, it may not exist by default, in which case the default of explorer.exe is chosen.

If it's not present you can just create it as a string value, and enter the full path to the executable you'd like to run at logon instead of explorer.exe.
Hi hansw77041,

Sorry GP is Group Policy.

If you are running Active Directory you can use Group Policy to tie down the desktop.

I know the solution I have posted is crude, but it is affective.  

I will try and dig out the code and post it.
Here is some code I use, this detects if a process (game) is running from a list in detect.txt, however it could easily be modified to see if a process does not exist.

Crude but effective :)
cd \windows
sleep 30
tasklist /V >c:\temp\tasklist.txt
Echo %NWUSERNAME% >c:\temp\detect.txt
Echo %COMPUTERNAME% >>c:\temp\detect.txt
time /t >>c:\temp\detect.txt
date /t >>c:\temp\detect.txt
findstr /G:c:\temp\games.txt c:\temp\tasklist.txt >>c:\temp\detect.txt
findstr /G:c:\temp\games.txt c:\temp\tasklist.txt >>c:\temp\detect.txt
findstr /G:c:\temp\games.txt c:\temp\tasklist.txt >>c:\temp\detect.txt
FOR /F "skip=5" %%1 IN (c:\temp\detect.txt) DO goto games
goto start
FOR /F "skip=5" %%i IN (c:\temp\detect.txt) DO set game=%%i
shutdown -r -t 10
blat c:\temp\detect.txt -to -f -s "*** Aplication ***" -server
Echo why did I get here?

Open in new window

hansw77041Author Commented:
Thanks for the help.
I split point because both solutions worked and each one had good points the other did not have.

I hope this is acceptable.

No probs hansw, glad to be of assistance!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.