Computing.Net > Forums > Programming > START command won't work on startup

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

START command won't work on startup

Reply to Message Icon

Name: mcel
Date: January 18, 2009 at 09:26:29 Pacific
OS: XP Sp3
CPU/Ram: centrino 4gb
Product: Hewlett-packard / -
Subcategory: Batch
Comment:

Hi

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)
exit

file2.bat:

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

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)



Sponsored Link
Ads by Google

Response Number 1
Name: Judago
Date: January 18, 2009 at 12:20:50 Pacific
Reply:

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%
pause
start notepad "%~f0"

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


0

Response Number 2
Name: mcel
Date: January 18, 2009 at 13:12:14 Pacific
Reply:

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 127.0.0.1 >> file2.bat
etc.

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?


0

Response Number 3
Name: reno
Date: January 18, 2009 at 22:22:57 Pacific
Reply:

::CODE START

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

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

::CODE END

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 127.0.0.1 and > is seperated by space. in first post you dont have space.


0

Response Number 4
Name: Judago
Date: January 19, 2009 at 13:36:01 Pacific
Reply:

%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 ...
       |  |
     options.

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??


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: START command won't work on startup

My Brother's Laptop Won't Turn On www.computing.net/answers/programming/my-brothers-laptop-wont-turn-on/19108.html

data type string won't work www.computing.net/answers/programming/data-type-string-wont-work/4126.html

PPC: New Line character won't work www.computing.net/answers/programming/ppc-new-line-character-wont-work/14131.html