views:

211

answers:

3

I have a batch file that I have been using to install my C# Windows Services for awhile now, never had a problem until Windows 7. I have attempted to run the batch file with Administrator privileges. I have attempted to run the command prompt with admin privs, navigate to the windows service EXE and run InstallUtil there. Still doesn't work.

After reading some other suggestions I tried moving my files out of the /bin folder and running them from another location but that also didn't work.

The batch file looks like this

@ECHO OFF

REM The following directory is for .NET 2.0
set DOTNETFX2=%SystemRoot%\Microsoft.NET\Framework\v2.0.50727
set PATH=%PATH%;%DOTNETFX2%

echo Installing IEPPAMS Win Service...
echo ---------------------------------------------------
InstallUtil /i IEPPAMS_WinService1.exe
echo ---------------------------------------------------
echo Done.

and I have a install log file that I dump info to. If I just double click the .bat file I get

Running a transacted installation.

Beginning the Install phase of the installation. See the contents of the log file for the C:\Users\Justin\Desktop\service test\IEPPAMS_WinService1.exe assembly's progress. The file is located at C:\Users\Justin\Desktop\service test\IEPPAMS_WinService1.InstallLog.

An exception occurred during the Install phase. System.InvalidOperationException: Cannot open Service Control Manager on computer '.'. This operation might require other privileges. The inner exception System.ComponentModel.Win32Exception was thrown with the following error message: Access is denied.

The Rollback phase of the installation is beginning. See the contents of the log file for the C:\Users\Justin\Desktop\service test\IEPPAMS_WinService1.exe assembly's progress. The file is located at C:\Users\Justin\Desktop\service test\IEPPAMS_WinService1.InstallLog.

The Rollback phase completed successfully.

The transacted install has completed.

When I run the .bat file with admin privileges nothing is written to the log file, and the service is still not installed.

Any thoughts? Is there a new way to install services in Windows 7?

+2  A: 

Right click on the batch file and run it as Administrator.

You are most likely running into battle with the new security model (User Account Control) from Windows Vista and Windows 7. Even if you are running as an account that has Admin rights you will still need to elevate to do some (most) administrative activities. (Yes it is possible to disable this feature, but don't)

Edit... The correct commandline is InstallUtil YourApp.exe. The /i does not look to be a vaild switch for InstallUtil.

Matthew Whited
Matthew, thanks but I tried that. The results are described at the end of my question.
Justin C
@Justin, try launching Command Window as Admin and then try issuing the command manually. It's looks to be a permissions issue but without sitting at your machine it's hard to guess what permission is causing the problem.
Matthew Whited
BTW, did you try looking in that log file?
Matthew Whited
Yeah, so as I described I tried right clicking the batch file and running as admin and I also tried running the command prompt as admin and neither worked. Nothing is written to the log file when I use admin settings, but the service is not installed. When I don't use admin settings the log file contains the info I pasted above.
Justin C
All I have left to suggest would be to look in your install code and make sure that it's not trying to do anything crazy. Do you have a strong name key on the project?
Matthew Whited
Yeah, it is a unique name. This exact code installs no problem on Windows XP and Windows Server 2003. That makes me want to agree that it is a permissions problem but nothing I do works. I did read one message board that talked about problems with the 64 bit InstallUtil running when the 32 bit should be running. I am on a 32 bit machine so that might have something to do with it.
Justin C
You shouldn't have to worry about that unless you are on a x64 machine. If you are on x86 you shouldn't even have the 64bit Framework installed. Are you on Home, Pro, Ultimate? This shouldn't be an issue but who knows.
Matthew Whited
@Justin, What happens if you remove the `/i`?
Matthew Whited
The `/i` maybe a shortcut to `/InstallStateDir` and it is probably getting confused looking for a directory named `IEPPAMS_WinService1.exe`. In the future there is a `/ShowCallStack` which might help find out there the problem is really occurring.
Matthew Whited
Thanks Matthew, all great ideas. I ended up finding a solution that worked. Still don't 100% understand why, but this last comment of yours sheds some light on it. I posted the answer myself.
Justin C
+1  A: 

When I run the .bat file with admin privileges nothing is written to the log file, and the service is still not installed.

First off, you HAVE to run as admin permissions.

Second, when you "Run as Administrator", it actually changes the directory to c:\windows\system32 as the initial directory ( no idea why ), which would probably explain why running as admin causes no log file. Manually change to the path IEPPAMS_WinService1.exe resides in that the start of your script.

Serapth
A: 

So I was able to fix the problem by typing in the command line the entire path to InstallUtil and it worked. So after navigating to the folder that had my EXE I typed the following:

C:\Windows\Microsoft.NET\Framework\v4.0.21006\installutil.exe IEPPAMS_WinService1.exe

Not sure why I have to do that in Windows 7 now when I never had to in XP, but oh well. Thanks for all the suggestions!

Justin C