Henrik
Henrik

Reputation: 169

Get the current path of the .bat file within the same .bat file

I am trying to create a windows service of some .exe file by using .bat file. As far as I know I need to use the path of the .exe file i want to run as service. But in generally the path of .exe file can be different, so I cannot use static path in the .bat file. I can solve the part of my problem by placing .exe and .bat files in the same direction, but I need to somehow get the direction of the .bat file within itself and add the name of my .exe file. It is just an idea so is it possible to do it in .bat file ?

Thank you

P.S.

To run .exe as a windows service, I use .bat file with the following script

SC create MyService displayname= "MyService" binpath= "<path of exe>\NAME.exe" start= auto

SC failure MyService reset= 86400 actions= restart/1000/restart/1000/run/1000

sc failure MyService command= "\"<path of exe>\NAME.exe""

Upvotes: 0

Views: 1190

Answers (1)

user7818749
user7818749

Reputation:

Use %~dp0

This example will set the path of the batch file you are running the code from.

set filepath=%~dp0
echo %filepath:~0,-1%

Upvotes: 2

Related Questions