Correct InstallUtil Path To File Syntax?

Mr. Smith picture Mr. Smith · Aug 14, 2009 · Viewed 27.5k times · Source

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

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe -i ".\MyService.exe"
    pause

When I excute the batch file (running as administrator on Vista) 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 C:\Services\MyService.exe. What should the ".\MyService.exe" part be for it to function properly?

Answer

jason027 picture jason027 · Mar 9, 2012

Just in case someone else comes here for this error... when you run InstallUtil.exe, if the path to your service contains spaces, surround it with quotes. Yes this is obvious, but the error it gives you if you don't is not.

wrong...

C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe C:\Users\joeblow\Documents\Visual Studio 2010\Projects\WindowsService1\WindowsService1\bin\Debug\WindowsService1.exe

right...

C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe "C:\Users\joeblow\Documents\Visual Studio 2010\Projects\WindowsService1\WindowsService1\bin\Debug\WindowsService1.exe"