Jump to content

Batch File - START %USERPROFILE%\Desktop\some.exe doesn'


kumarkumar

Recommended Posts

I am trying to run a simple batch file where I would use it to run another exe.

@ECHO OFF
START %USERPROFILE%\Desktop\some.exe

This doesn't work. I get the error "Windows cannot find "C:\Documents'. Make sure you types the name correctly........"

I guess this is because there are spaces in "Documents and Settings".

I tried

@ECHO OFF
START "%USERPROFILE%\Desktop\some.exe"

This doesn't work either. It opens command prompt and stays as it is.

I tried

@ECHO OFF
START "%USERPROFILE%"\Desktop\some.exe

This doesn't work either. It opens command prompt and stays as it is.

Wherever there is space in the path to exe, START command doesn't work (ex. %PROGRAMFILES%, %CD%, %TEMP%, etc)

What could be wrong?

Link to comment
Share on other sites


Thanks jaclaz. :thumbup

Adding "title" did the trick.

I can use just one line in the batch file for my job (to make things more simpler) :)

START "" "%USERPROFILE%\Desktop\some.exe"

The following combinations of double quotes also work

START "" "%USERPROFILE%"\Desktop\some.exe

START "" "%USERPROFILE%"\Desktop\some.exe"

START "" "%USERPROFILE%""\Desktop\some.exe"

@MrJinje

I wanted to use START command and not just

"%USERPROFILE%\Desktop\some.exe"

(which would also run some.exe), because I wanted the cmd window to close automatically after it had opened some.exe, which is not possible without START command.

Edited by kumarkumar
Link to comment
Share on other sites

The following combinations of double quotes also work

No matter if they work or not, DO NOT use them :realmad: , use the first one: one single set of double quotes wrapping around the WHOLE path\exe.

SYNTAX is there to be respected, not "invented", the first "wrong" example works only because you do not have a space in \Desktop\some.exe and the second (the one with the odd double quote) only works because of a "parsing defect" of the command interpreter, don't trust it.

Third is pointless, it only adds to extra unneeded characters.

:hello:

jaclaz

Edited by jaclaz
Link to comment
Share on other sites

START often needs a "title" to work:

http://ss64.com/nt/start.html

If there is a space in the path to the command, it must be enclosed in double quotes.

Check if userprofile is defined

I.E::

SET USERPROFILE
PAUSE
START "Window Title" "%USERPROFILE%\Desktop\some.exe"

jaclaz

Just a small correction

If I were to follow the START syntax correctly shouldn't it be

@ECHO OFF
START "%USERPROFILE%\Desktop" some.exe /h

(with a space between the path and exe)

Link to comment
Share on other sites

Just a small correction

If I were to follow the START syntax correctly shouldn't it be

@ECHO OFF
START "%USERPROFILE%\Desktop" some.exe /h

(with a space between the path and exe)

NO. :realmad:

That line would give a title of "%USERPROFILE%\Desktop" to the window.

The "/h" is a paremeter to "some.exe".

Read again the given link.

command : The command, batch file or executable program to run

command means the name of executable, including a fully qualified path to it UNLESS:

  1. the program is in the SAME directory as the running batch
  2. the program is anywhere in the PATH

A GENERAL rule about command line and batch parsing is that the SPACE is a separator, thus a full path containing spaces MUST be enclosed in double quotes.

A workaround is using 8.3 compliant names, but this can generate "colliding" paths. (hint: use DIR /X)

Don't be tricked by the optional [/Dpath] option that sets the "working directory", not the target to be executed.

jaclaz

Link to comment
Share on other sites

My bad :( a typo

The correct syntax should have been (following the suggestions in http://ss64.com/nt/start.html)

@ECHO OFF
START "Some Title" "%USERPROFILE%\Desktop" some.exe /h

(where /h is the parameter to some.exe)

Now if you look at any example in that website you would notice a space after the "path to the exe" and the "exe"

START "My Login Script" /Min Login.cmd
START "" /wait MySlowProgram.exe

Edited by kumarkumar
Link to comment
Share on other sites

No it shouldn't, here are all of the examples on that page:

START "My Login Script" /Min Login.cmd

START "" /wait MySlowProgram.exe

START \\print_server\printer_name

START /Dc:\Documents\ /MAX notepad.exe

start /wait /b First.exe

start /wait /b Second.exe

start /wait /b Third.exe

Nowhere does a path terminate then include a space before the name of the executable file. It also does not in the example you've provided.

Since some.exe is located at the path %USERPROFILE%\Desktop you'd use the following:

@START "Some Title" "%USERPROFILE%\Desktop\some.exe" /h

Link to comment
Share on other sites

Since some.exe is located at the path %USERPROFILE%\Desktop you'd use the following:
@START "Some Title" "%USERPROFILE%\Desktop\some.exe" /h

...should kumarkumar be willing to follow the advice he asked for.....:whistle:

:hello:

jaclaz

Edited by jaclaz
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...