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!

有帮助吗?

解决方案

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"

其他提示

For my own usage I created a small .bat file:

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

And now, when I want to install service I just drag .exe file on the .bat. Works perfect :)

If you create a .bat file, then the working directory is based on the location from where you invoked the .bat. If you created a shortcut to 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 issue a cd C:\Services at the beginning of your bat file.

Have you tried setting working directory to C:\Services?

although this is an old question...

what helped me to solve the issue is to run the installer with logs

For example:

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

In my case the original error was like yours

FileNotFoundException

, but in the logs I found

SecurityException

The solution was to run as administrator

It works for me (of course) - It looks for MyService.exe in the containing folder.
"c:\windows\system32" is not the location of installutil, so perhaps earlier in the batch file the working directory is changed somehow.

Presuming this is not the only command in the batch file:
Try to add 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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top