trying to run a .bat that runs an .exe from a mapped drive or share and have file not found - windows

I'm not sure what I'm doing wrong.
I have a file share called fileser01. I placed my exe which is hp.exe in \\fileser01\\software. I can map a drive whith this command:
net use f: \\fileser01\\software /user:domain\myaccount
So the drive shows as f:.
In the .bat file I have start "f:\" hp.exe but it says it can't find the file. What am I doing wrong? I even try to run a vbs and it says it can't find the file
I tried "f:" I tried putting it in another folder in software like media so "f:\media" and still same problem.

Your question says your batch files contains this:
start "f:\" hp.exe
No, that will not work. It needs to be this:
start "Window Title" "f:\hp.exe"
Or this:
start f:\hp.exe
The entire file name with no added spaces needs to be contained between the quotation marks. And in this case you could even omit the quotation marks since the file name and path contain no spaces, in which case you can also omit the window title.

Related

How to run an executable that contains a space in path from command line on Windows 10?

H:\>"H:\Program Files\R\R-3.4.0beta\bin\R.exe"
'H:\Program' is not recognized as an internal or external command,
operable program or batch file.
H:\>"H:\Progra~1\R\R-3.4.0beta\bin\R.exe"
The system cannot find the path specified.
H:\>H:\Progra~1\R\R-3.4.0beta\bin\R.exe
The system cannot find the path specified.
I tried using "..." and Progra~1 and both are not working on Windows 10.
What I'm doing wrong?
Short answer: Use & 'C:\path with spaces\app.exe'
Explanation: Just type your path into powershell and use TAB for auto completion when you choose any directory containing spaces. Powershell will automatically insert single quotes 'bla bla' and it will also put an & in front which is needed to treat the string as something that should be executed. Continue completing your path like usual.
The way to do this - and I can't believe I'm just now figuring this out - is to use Windows short names generated for files with non-8dot3 names. To get the path or program name in question, type dir /x <path to program>. It will spit out something like PROGRA~1 for Program Files folder. Of course you have to do that directory by directory, and if you have multiple files/folders with spaces in the name, it's cumbersome. If you want the full path formatted with short names, you can do:
for %I in (*) do echo %~sI
For example, if the file I want to access is C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\License Terms\License_msodbcsql_ENU.txt, I could type:
for %I in ("C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\License Terms\License_msodbcsql_ENU.txt") do echo %~sI
And what I get back is the much easier C:\PROGRA~1\MICROS~2\CLIENT~1\ODBC\170\LICENS~1\LICENS~1.TXT.
Annoying that you can't query the whole directory path without using a loop, but it is what it is. Good for aliases.
There may be an easier way with powershell, but I'm pretty sure there isn't from the cmd prompt.
you must be doing something wrong as the double quotes encapsulates the path to the executable including spaces.
To ensure you are doing it correctly, start typing the path to the command and use TAB after F:\Program until you see the correct path, in your case it will automatically do this
"F:\Program Files"
Use your arrow key to go back behind the end quotation and continue the path and use tab until you have reached.
"H:\Program Files\R\R-3.4.0beta\bin\R.exe"
You can also try and issue it with Start
start "H:\Program Files\R\R-3.4.0beta\bin\R.exe"
If Your cmd windows is open on the actual System drive where "Program Files" are located, you can run this instead of adding the drive letter as well:
".\Program Files\R\R-3.4.0beta\bin\R.exe"
Or add it to your environment variables with the path, then it should execute with just:
R.exe

Using CMD to open an .exe file, from the same directory?

Im trying to make this launcher for my game.
But I can't seem to find anywhere, how to open a file. Without specifying the location.
Like I want it to run a file, from the same folder as the .cmd file is in. (The one I created).
Been searching for ages, without finding out how.
Reasoning: The user is able to change where the game is going to be installed. So I cant specify a location..
Simply open Command Prompt. Then Drag and Drop your .exe file to the console. (This will copy the location of the .exe file to the console) Then just press "Enter". Then your .exe file should be running.
References http://www.howtogeek.com/209694/running-an-.exe-file-via-command-prompt/
Hope it helps
The argument %0 of a batch file references the name of that batch file. So to run an exe located in the same folder where your batch file is, use:
%~dp0program.exe
The ~dp expands the argument %0 to a full qualified path name - including a trailing \ that's why there is no \ between %~dp0 and program.exe
Details about expanding variables can be found by typing help for on the commandline
Turned out, it was just me being foolish.
Forgot that I could just type in the name of the file.
Instead of doing something big out of it.
Thanks #ByteHamster for refreshing my memory :)
"Quote" ByteHamster: If you are in the same folder, just type in the name of the exe file.

Call another .bat file from within the same folder?

I have my primary Batch file in a folder with a second batch file in the same folder. How do I make it so that the second batch file can be called from within the first. This must be able to work with any user's Windows computer.
I figured it was something like this (in the primary file):
call C:\%UserProfile%\#Hashtag\gameData\second.bat
But it says my syntax or path is incorrect.
call "%~dp0second.bat"
%~dp0 gives you the path (including a trailing backslash) of the location of your currently running batchfile.
Agreeing violently with #Stephan, there's a sort of invisible change to the code besides using the %~dp0, in that the path now is also in " double quotes. That's most likely the issue with the first one because of expansion of the %UserProfile% variable... my guess is there's a space in that string.
There's no issue using the # character in a filename.
Maybe due to the folder name #hashtag it is throwing an error. Add the folder path to PATH variable and then try calling the batch file name directly.

DOS start command does open directory with spaces

Help please..
I wanted to Open the copied file folder once the file has been copied.
I used DOS command start. It works fine as long as the directory path does not contain any space characters.
If I use quotes in the path it rather opne another dos screen:
**Here sample CMD file:
XCopy C:\1\Source\Test.txt C:\1\Target 1\ /R/Y/K
start "C:\1\Target 1\"
Pause**
You had the right idea with the quotes. The tricky bit is that start assumes the first parameter is the window title if it is quoted. If you want to quote your target then you must provide a quoted title first. It can be empty:
start "" "C:\1\Target 1\"
However, if you happen to have a batch file named Target 1.bat, then it will execute the batch script instead of opening the Target 1 folder in Windows Explorer. For that reason, it is safer to use robert oh's answer, explicitly specifying explorer as the target with the folder as a parameter.
You could use
start explorer "c:\some folder\"

starting a windows executable via batch script, exe not in Program Files

This is probably batch scripting 101, but I can't find any clear explanation/documentation on why this is happening or if my workaround is actually the solution. So basically any terminology or links to good sources is really appreciated.
So I have a program I want to execute via batch script (along with several other programs). It's the only one where the exe is not in a Program Files folder. I can get it to start like this:
C:\WeirdProgram\WeirdProgramModule\weirdmodule.exe
But I get an error along the lines of:
Run-time Error '3024':
Could not find file
C:\Users\MyUserName\Desktop\ModuleSettings.mdb
So it seems that the program is looking for its settings files from the same location that the batch script starts up. Given that I finally got everything to work by doing the following:
cd C:\WeirdProgram\WeirdProgramModule\
weirdmodule.exe
That works fine, and it's not the end of the world to have to go this route (just one extra line), but I've convinced myself that I'm doing something wrong based on lack of basic understanding.
Anybody know or can point me to why it works this way?
Oh, and doing the following:
start "C:\WeirdProgram\WeirdProgramModule\weirdmodule.exe"
doesn't do anything at all.
Thanks,
you are doing it perfectly :-)
the executable is probably looking for this file in the "current working directory", which is being set, when you "cd" to it before.
you can set your working directory manually by creating a shortcut to your batch file; right click; properties.
edit:
you can also set your current working directory using the start command:
start "Title" /D "C:\WeirdProgram\WeirdProgramModule\" "weirdmodule.exe"
edit:
If you like to pass params, just add them to the executable filename as you would in a regular shortcut:
start "Title" /D "C:\WeirdProgram\WeirdProgramModule\" "weirdmodule.exe" "param1 param2"
or
start "Title" /D "C:\WeirdProgram\WeirdProgramModule\" "weirdmodule.exe param1 param2"
For reference, the syntax is described here: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds.mspx?mfr=true.
What's happening is that weirdmodule.exe is looking in the "current directory" for the .mdb file. You might be able to tell it where to find the .mdb file through a command line parameter or some other configuration method (registry or .ini file maybe). How you'd specify the location is entirely up to the weirdmodule.exe program, though.
Other than that, your current workaround is probably what you're stuck with.
As far as your problem with using start.exe... the start.exe program has the very, very odd behavior (bizarre behavior in my opinion) of treating the first parameter as the 'title' to put in the window if (and only if) the first parameter is in quotes. So you have a couple of options:
Don't use quotes to specify the program. This works for you because you don't need quotes (there aren't any spaces or other special characters in the path that would require quoting it):
start C:\WeirdProgram\WeirdProgramModule\weirdmodule.exe
Give an empty (or some other string) title as the first parameter. This is something you'd have to do if your path required quotes:
start "" "C:\WeirdProgram\WeirdProgramModule\weirdmodule.exe"

Resources