START command won't work on startup

Hewlett-packard / -
January 18, 2009 at 09:26:29
Specs: XP Sp3, centrino 4gb

I have an .exe file that deletes itself on startup. It runs a .bat file that deletes the .exe file and than itself.

file1.exe (compiled batch file):

if "%CD%\file1.exe"=="C:\file1.exe" (
start "file2" /MIN file2.bat
) ELSE (exit)


TSKILL file1 /A /V
ping -n 4>nul
del file1.exe
del file2.bat

However, when I try to run file1.exe on startup it fails to start file2.bat, and therefore it will not delete itself. It almost seems like the START command doesn't work right after booting your computer.

Is there a way to solve this?

(file1.exe is executed on startup by adding a key to the registry: hkey_current_user\software\microsoft\windows\currentversion\run)

See More: START command wont work on startup

Report •

January 18, 2009 at 12:20:50
start expects the first argument enclosed in double quotes to be a title, try:
start "" "file2"

However there is another issue. Some "compiled" batch files are self extracting archives that extract a copy of your batch file to a temporary directory and run it from there. %cd% may not be what you think it is, it could be c:\documents and settings\<user>\local settings\temp on xp.

Here are two little tests you can "compile" in and get an unexpected result.

echo %cd%
start notepad "%~f0"

Give it a try and see what you come up with.

Report •

January 18, 2009 at 13:12:14
So just leave it blank where it says title?
Like this: start "" /MIN file2.bat

The exe actually creates file2.bat, like this:
echo TSKILL file1 /A /V > file2.bat
echo ping -n 4 >> file2.bat

So file2.bat is created in the same folder as file1.exe

I tried the start notepad "%~f0" command:

It opened file2.bat in notepad.

What does %~f0 do?

Report •

January 18, 2009 at 22:22:57
echo ^(
	echo echo CALLER: %%1 [%%date%% %%time%%]
	echo TSKILL %~n0 /A /V
	echo ping -n 4
	echo del %~f0
	echo del %%~f0
	echo exit 
echo ^)^>^>log 2^>^&1
)> file2.bat

start /min file2.bat "start" 
::%comspec% /c file2.bat "%comspec%"


first try the start /min, then try again with %comspec% /c. lastly, view the log file to see if there is any error.

check your ping statement, make sure and > is seperated by space. in first post you dont have space.

Report •

Related Solutions

January 19, 2009 at 13:36:01
%0 is the batch that is running, it is a parameter, valid parameters are %0 - %9. You can think of it like this at the command line:

program name.
c:>%0 %1 %2 ...
       |  |

Parameters happen to take the same modifiers that for variables take, which can be quite useful. For a list of these parameters goto the command line and type in "for /?", on xp the list is on the second last/last page of output. The one I used above was "fully qualified path name".

If you have to use quotes on you file name unfortunately at title has to be specified, either null like I used or whatever you like
(i.e. put the title you want in between the quotes).

Doesn't it seem odd that a "compiled" batch file (.exe) open in notedpad as source??

Report •

Ask Question