how to start executable from command line in windows - windows

I have a program when I click it, it opens fine.But when I run it command prompt it gives an error that is related to a dll that my program uses.I do in cmd
"Path_to_program\program.exe"
And a note:my program is installed my D: drive
But it gives an error related to dll.the dll is in the same directory with program.I guess it is related to dll.is there an option to give the dll as dependency to my command?

You need to change to the same folder that the program is in so that your working directory matches.
Try
cd Path_to_program
program.exe

Related

Command prompt from C: drive, how to start executable in another drive?

I have a Windows machine with the current user in C:\Users\User.
I have an executable in another drive, let's say at D:\Folder\MyProg.exe.
Opening command prompt, it starts in the directory C:\Users\User
I type the command: start D:\Folder\MyProg.exe or D:\Folder\MyProg.exe
The exe fails to open, with a pop-up: MyProg has encountered an error
In order to run start the .exe from command prompt, I have to cd to the other directory and then start the exe.
Opening command prompt, it starts in the directory C:\Users\User
I type the command: cd /d D:\Folder && start MyProg.exe
The exe successfully opens.
Is there a better way to, from C:, start an executable in another drive?
Reproducing
Windows 10 Pro, v1809 (I don't think the version really matters)
My real use case is industrial automation, but one can observe the same result with convert.exe (cnet download link)
As commented by #Mofi, I realized the answer is most likely this:
But some programs are not good coded. Such programs depend on files in directory of the program and do not use appropriate code to reference those files from within the program with program files path, but use instead a relative path
As he instructed in the next comment, start provides a /d parameter that lets you specify a startup directory. Thus, a concise command would be:
start "" /d D:\Folder MyProg.exe
Note: the "" is for the <Title> field. The .exe I am opening is a GUI application (not a console application), so it is not necessary in this case, I just included in case other viewers find this useful in their application.
I have a Windows machine with the current user in C:\Users\User.
I have an executable in another drive, let's say at D:\Folder\MyProg.exe.
Opening command prompt, it starts in the directory C:\Users\User I type the command: start D:\Folder\MyProg.exe The exe fails to open.
In order to run start the .exe from command prompt, I have to cd to the other directory and then start the exe.
Maybe not. Try:
PATH D:\Folder;%Path%
"D:\Folder\MyProg.exe"

Running a batch file through command prompt - system cannot find the path specified

I am trying to uninstall Oracle on this Windows 7 (64 bit) machine by downloading a standalone tool from Oracle, I need to run a batch file that is supposed to uninstall but I am unable to run it.
I tried to open command prompt as administrator and I am trying to run this as below:
As you can clearly see from the screenshot, I am doing a "dir" on the directory and can clearly see the file right there. Not sure what's going on here.
I also tried to run the batch file by double clicking from Windows Explorer and a terminal window opens and closes quickly but the batch file is not doing what it is supposed to do (it is clearly not executing from Windows Explorer).
Can anyone help me with this?
As theB pointed out above in a comment, this worked for me:
Open the bat file in notepad. I'll bet it starts with #echo off, and
that the error is actually coming from inside the batch file. The
error if the batch file itself wasn't found is 'X' is not recognized
as an internal or external command, operable program or batch file
'Run as Administrator' changes the current directory. See my answer here
Difference between "%~dp0" and ".\"?

Windows 7 Command Prompt: How do I execute a batch script from the command line?

I'm using Windows 7, and my problem is running this file from a console (cmd.exe):
W:\software\projects\myproject\build\msvc\build.bat
When I move into the folder containing the file manually and run it from there using the following command sequence, it works:
W:\>cd software
W:\software>cd projects
W:\software\projects>cd myproject
W:\software\projects\myproject>cd build
W:\software\projects\myproject\build>cd msvc
W:\software\projects\myproject\build\msvc>build.bat
However, when I try to run the file from the root directory in any of these ways:
W:\>software\projects\myproject\build\msvc\build.bat
W:\>call software\projects\myproject\build\msvc\build.bat
W:\>#call software\projects\myproject\build\msvc\build.bat
W:\>"software\projects\myproject\build\msvc\build.bat"
W:\>call "software\projects\myproject\build\msvc\build.bat"
W:\>#call "software\projects\myproject\build\msvc\build.bat"
I get the following error message:
The system cannot find the path specified.
I'm pretty sure you didn't have to navigate to the folder containing the file in order to run it when I was using Windows XP (though I could be wrong, of course), but this apparently seems to be the case with Windows 7. Or am I missing something?
You are correct. You do not need to navigate to the batch scripts folder before executing.
The error "The system cannot find the path specified." is most likely caused by something inside your batch-file.
Try to add
cd W:\software\projects\myproject\build\msvc
w:
or in a single command (as suggested by James K, Thanks!)
cd /d W:\software\projects\myproject\build\msvc
Searched a bit more and found this generic solution:
cd /d %~dp0
at the top of your batch file to set the working directory to the directory of the script to check whether this is the cause.
If you execute your file from W:\ this is where the commands are executed (working directory). It is most likely that your script cannot find some file it uses in this location.

How to register DLL from .bat file in Windows 7

As part of a poor-mans installation (on Windows 7) I need to register a DLL from a .bat file. I provide the user with a set of files that make up the application, tell them to copy them to some (any) directory, then, as the 1st part of the install, tell them to execute my register.bat file which invokes regsvr32 on the appropriate DLL(s)
This fails with 0x80004005 (permission) error. I then try running the .bat file as an Admin. This doesn't work as it opens the command prompt in \windows\system32 which is not where the DLLs to be registered are located. As I don't know where the user has placed the register.bat file I can't put the path to the DLL files in the .bat file.
Any thoughts?
Try using %~dp0 to get the folder the batch file is stored in, like:
regsvr32 %~dp0\mylibrary.dll
You can get and use the path of the current directory like this:
set "FullPath=%cd%\Test.dll"

Running Bat file on Win 7 machine

I have an executeable (Command line which requires arguments/parameters) i need to run on a Win 7 machine. I can run the executeable if i right click and choose run as administrator. Of course, it returns an error code that the required command line parameters were not found. In addition, the executable will create an error log if it has a problem, errors out, throws an exception, etc. I then created a batch file and added MyProgram.exe param to it, and right clicked that and chose run as administrator. I get nothing.....no return code, no error log. I created a shortcut on the desktop to the batch file and changed its advanced properties to run as administrator and still nothing. Anyone have any ideas? I need to run this executable with params from a batch file on a Win 7 machine. Thanx
Edited:
I guess maybe it could be a problem with my Batch file, since i am a novice at those as well. I simply had one line:
MyProgram.exe MyImportFile.txt 1 1
Try creating a shortcut on Desktop to cmd.exe
There you have your commandline. Right click your new shortcut, run as administrator.
Then run your bat file or your exe directly with your parameters.

Resources