C# – Install util looks for service on wrong folder

batch-filecinstallutilnetservice

3
I'm trying to install a Windows Service using a batch file, let's call it "setup.bat". Inside the file I have the following commands:

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

When I excute the batch file (running as administrator on windows7) I get this:

Exception occurred while initializing the installation:
System.IO.FileNotFoundException: Could not load file or assembly 'file:///C:\Win
dows\system32\MyService.exe' or one of its dependencies. The system cannot f
ind the file specified..
The actual service is located at
"SomeRandomLocation\MyService.exe".
the bat file is
"SomeRandomLocation\setup.bat"

what is going on? how do I force it to install from my "setup.bat" folder?

this should work dynamicly. meaning in any folder!

Best Answer

I don't know anything about the install process. But %~dp0 will give the absolute path of your running batch file. So if your exe is in the same folder, you could try:

"%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\installutil" "%~dp0MyService.exe"
Related Topic