开发者

Installing C# Windows Service on Windows 7

开发者 https://www.devze.com 2023-01-13 17:46 出处:网络
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 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开发者_JAVA技巧.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?


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)

  • UAC (MSDN)

  • UAC (Wikipedia)

  • InstallUtil (MSDN)

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


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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消