The utility installation is looking for a service in the wrong folder

3 I am trying to install a Windows service using a batch file, let me call it "setup.bat". Inside the file, I have the following commands:

"%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\installutil" "MyService.exe"

When I release the batch file (works as an administrator on windows7), I get the following:

An exception occurred during initialization of the installation: System.IO.FileNotFoundException: Failed to load file or assembly: /// C: \ Win dows \ system32 \ MyService.exe 'or one of its dependencies. The system cannot ind the specified file .. The actual service is located at the address of the "SomeRandomLocation\MyService.exe". bat file "SomeRandomLocation\setup.bat"

what's happening? how can i get it to install from my setup.bat folder?

this should work dynamically. value in any folder!

+3
source share
5 answers

I don’t know anything about the installation process. But it %~dp0will give an absolute path to your running batch file. Therefore, if your exe is in the same folder, you can try:

"%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\installutil" "%~dp0MyService.exe"
+6
source

If you are creating a .bat file, then the working directory is based on the location from which you called .bat. If you created a shortcut for the .bat file, then the working directory is based on the location of the .bat file. Any relative path in your script is interpreted relative to the working directory.

To avoid changing all your paths. Just type cd C:\Servicesbat at the beginning of the file.

+1
source

.bat :

"C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe" %1

, , .exe .bat. :)

+1

C:\Services?

0

This works for me (of course) - it searches MyService.exein the folder with the folder.
"c:\windows\system32"is not a location installutil, so it’s possible that the working directory has somehow changed in the batch file earlier.

Assuming this is not the only command in the batch file:
Try adding set OLDDIR=%CD%at the very beginning of the batch file,
And add chdir /d %OLDDIR%just before the installutil command and see if this works.

-1
source

All Articles