Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I would like to know if I could close a process automatically using a batch file I can close a program using a batch file but I want to close a program as soon as it starts automatically. for example If I open the notepad the batch file should automatically detect it and close it rather then me clicking on the batch file so basically the batch file should start and monitor the program automatically and as soon as the program is run it should close it. Hope Im clear. Waiting for reply thanx

This is how to do it with batch
@echo off
cls
:loop
@ping -n 01 127.0.0.1>nul
tasklist 2>nul | find /i "????????.exe" >nul || goto :loop
taskkill /f /t /im ??????.exe
exit

Need some more information about how you want to do this.
Glad it works. Sorry about the delay been a bit busy today.

ok what I want to do is that the batch file should run automatically upon log on I know how to do this I figured it out now I want to hold the log off and shutdown process automatically so it is the same thing as before but this time it will look for the log off file and cancel it I tried it but it doesnt work! The following is the same code which you gave me but with the file which switch the user
@echo off
cls
:loop
@ping -n 01 127.0.0.1>nul
tasklist 2>nul | find /i "tsdiscon.exe" >nul || goto :loop
taskkill /f /t /im tsdiscon.exe
exit
the tsdiscon.exe file is the file which switch user when you press switch user i want to find this file and if it is running stop it from being executed is this possible?? plz help on this I wrote another file which when run will pause the switch user process until the user hits an key the code is
cd\
cd c:
cd WINDOWS
cd system32
pause
tsdiscon.exe
so to summerise I want to hold the log off/ shutdown/ switch user operation when the user hits the log off/ shutdown or switch user button thanx

I am a little confused. Why don't you just disable Fast User Switching as a service?
Does tsdiscon.exe run within svchost?
I believe it does but you may know?
Open a cmd /k then enter
tasklist /svc /fi "imagename eq svchost.exe"
if you see something like FastUserBlahblah then you can put the results into a text file and then look in there to stop it. But I am still confused as to why you need to go down this route instead of stopping the service.
Sorry if I am being dim.

Sorry for the late reply no I dont want to stop it I just want to hold it as you know that when you shutdown and if you want to cancel it then you could type "shutdown -a" in the run box and it will cancel it also you can write this as an batch file the reason I want to know this is because I am doing a project in which I want this software the software will hold the log off/ shutdown operation and will do something else then continue the log off operation. Is it posible to do it with batch file? or I have to use VB to do this!

I am still not sure if we are on the same page.
Is this what you want?Title badbloodyeyez batch script
@echo off
cls
:Loop
echo.
echo YOU NOW HAVE 4 CHOICES:-
echo.
echo TO LOG OFF TYPE L
echo.
echo TO SHUTDOWN COMPUTER TYPE S
echo.
echo TO RESTART COMPUTER TYPE R
echo.
echo TO USE COMPUTER TYPE C
echo.
set /p inp= TYPE THE LETTER AND PRESS ENTER: -^>
if %inp%==l goto loff
if %inp%==s goto sdown
if %inp%==r goto sdownr
if %inp%==c goto exit
cls
GOTO :Loop
:loff
cls
shutdown -l -t 00
GOTO :exit
:sdown
cls
shutdown -s -f -t 05 -c "CATCH YOU LATER"
GOTO :exit
:sdownr
cls
shutdown -r -f -t 05 -c "SEE YOU IN A MINUTE"
GOTO :exit
:exit

yes very nice file thanks for your reply and code and is it possible to run this file automatically when the user press log off/ shutdown or restart I mean the user will click on start then log off or shutdown and then this file will run automatically is it possible??? and thanx for the code I really appriciate your help I really do thanx

If you put the batch file in say windows then make a shortcut to it you can choose an icon, size etc. You have to edit the properties of the shortcut You can make it look like shutdown. then using either group policy editor or the registry you can remove log off or shutdown from start menu.

I tried running my file on log off but this program does not work niether does it log off the way I done it is as follows
in the run type in gpedit.msc
then user configuration and then windows settings and then scripts
but it does not work!!!

What does not work? You need to be more precise with what is needed and happening.
The batch is not run as a shutdown script it is the shutdown, log off, restart.These are the registry enteries to remove log off and shutdown. Do you know how to make a registry file. I hope so. Copy to notepad. Save as ?????.reg. Double click to merge into registry
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer]
"StartMenuLogOff"=dword:00000001
"NoClose"=dword:00000001Now make your shortcut to the batch file..... and now this is the part you need to tell me what you precisely need to do or wish to accomplish. OK as an idea.
Try this
Title Internet Explorer
@echo off
cls
color 1A
cls
echo.
echo.
echo Don't worry Internet Explorer is starting
start "" /wait /abovenormal "C:\Program Files\Internet Explorer\iexplore.exe" http://www.google.co.uk/
cls
:Loop
echo.
echo YOU NOW HAVE 4 CHOICES:-
echo.
echo TO HIBERNATE COMPUTER TYPE L
echo.
echo TO SHUTDOWN COMPUTER TYPE S
echo.
echo TO RESTART COMPUTER TYPE R
echo.
echo TO USE COMPUTER TYPE C
echo.
set /p inp= TYPE THE LETTER AND PRESS ENTER: -^>
for %%a in (l s r c) do if "%%a"=="%inp%" goto :%inp%
cls
goto :LOOP
:l
cls
shutdown -l -t 00
GOTO exit
:s
cls
shutdown -s -f -t 05 -c "CATCH YOU LATER"
GOTO exit
:r
cls
shutdown -r -f -t 05 -c "SEE YOU IN A MINUTE"
GOTO exit
cls
:c
exit

I am sorry if I'm being so noisy. Ok let me tell you wat I want to do ok If a user logs off I want to hold or cancel log off operation just like if the user wants to open notepad and we closed it so basically I dont want the user to log off or shutdown the computer!!!! but if he wants to log off/ shutdown he has to select a option just like in the code you gave me. So if the user press 'Start' and then 'log off' rather than the windows option comes which lets the user to log off or switch user the code you gave me will start

So you have your answers.
Use the registry keys to remove shutdown and logg off put a shortcut to the batch file in it's placeWindows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer]
"StartMenuLogOff"=dword:00000001
"NoClose"=dword:00000001

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |