I am new to the batch script programming.Getting error while executing batch file if I give the relative path. I have following folder structure
Script folder - C:\batch\script\ServiceRegister.bat
Bin path - C:\batch\bin\ERecruitGenerateReportsWindowsService.exe
ServiceRegister.bat Batch file –
%windir%\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe %~dp0%~1\bin\ERecruitGenerateReportsWindowsService.exe
When I execute ServiceRegister.bat file I got the error:
Exception occurred while initializing the installation:
System.IO.FileNotFoundException: Could not load file or assembly 'file:///C:\batch\script\bin\ERecruitGenerateReportsWindowsService.exe' or one of its dependencies. The system cannot find the file specified.
I am using “%~dp0%~1” to go one level up in the directory still it gets its current path.
%~dp0%~1 - C:\batch\script\
I need the C:\batch\ path. How I can get this path? It works fine If I give the absolute path -
%windir%\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe C:\batch\bin\ERecruitGenerateReportsWindowsService.exe
Your attempt to use %~1
to go up one level in the directory structure is inventive and totally invalid syntax. The proper syntax is just as simple - use ..\
.
A leading \
is not required because %~dp0
ends with a \
.
%windir%\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe %~dp0..\bin\ERecruitGenerateReportsWindowsService.exe
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With