Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to automate the install of a Windows Service for when I'm testing it locally. It is built in .NET... I'd usually open the Visual Studio Command Prompt as Administrator and then type the installutil command, I'm wanting to turn it into an "one-click" install.

So I've created the following batch script to make sure the most recent version is built, then elevate myself to do the actual service install (UserAdmin is my administrator account).

cd C:\Path\To\Solution
echo Building Service
msbuild WinService.sln /noconlog /nologo

cd C:\Path\To\Solution\bin\Debug
runas /user:UserAdmin "cmd /k C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil C:\Path\To\Solution\bin\Debug\WinService.exe"

However, installutil always gives me the following error:

An exception occurred during the Install phase.
System.Security.SecurityException: The source was not found, but some 
or all event logs could not be searched.  Inaccessible logs: Security.

I'm not sure if this is configuration issue, or if my batch script is wrong. But since I can't create a directory in the C:\Windows\System32\ folder that the runas command prompt is started in, I suspect I'm not getting the permissions I was expecting. Is there a way I can check what user/permissions level I'm running at in the command prompt?

Note: I want to make this script as generic as possible. In the environment I'm working in everyone's administrator account is guaranteed to be 'UserAdmin'. The path to the solution will also be the same. This script will be added to SVN, so something like adding my particular password for the UserAdmin account would not be acceptable.

share|improve this question
    
runas requires password to be entered, what do you then, do you manually enter the password ? –  HackToHell Sep 11 '12 at 14:01
    
Yea, I noticed it prompted me for a password, so I was hoping that I could just go with manually entering it... that way other people on my team can enter their password for their local UserAdmin without modifying the batch script. –  Jeff Bridgman Sep 11 '12 at 14:32
    
Also, runas appears to not work quite as expected, as described here: superuser.com/a/485976/101146 –  Jeff Bridgman Oct 10 '12 at 19:55

3 Answers 3

Here is a solution that might be useful to somebody:

%WINDIR%\Microsoft.NET\Framework\v4.0.30319\installutil.exe /username=domain\YourUserName /password=YourPassword YourApplication.exe
share|improve this answer
@echo off

SET PROG="c:\YourServiceLocation\Service.exe" SET FIRSTPART=%WINDIR%"\Microsoft.NET\Framework\v" SET SECONDPART="\InstallUtil.exe" SET DOTNETVER=4.0.30319 IF EXIST %FIRSTPART%%DOTNETVER%%SECONDPART% GOTO install

GOTO fail :install ECHO Found .NET Framework version %DOTNETVER% ECHO Installing service %PROG% %FIRSTPART%%DOTNETVER%%SECONDPART% %PROG% GOTO end :fail echo FAILURE -- Could not find .NET Framework install :param_error echo USAGE: installNETservie.bat [install type (I or U)] [application (.exe)] :end ECHO DONE!!! Pause

Run this bat file as administrator

share|improve this answer
    
Could you please add a description to the code what it does does? You also seem to have a typo (installNETservie.bat). –  user 99572 is fine May 30 at 12:38
    
without using the command prompt , use this bat file and u can install the windows service locally. –  Chenthurij Jun 2 at 7:15

you could use sc.exe to create the service instead of installutil...

example:

sc [Servername] create Servicename [Optionname= Optionvalue...

here is one I create often:

sc create syscmd binpath= "%COMSPEC% /c start" type= own type= interact

this opens a command prompt (with system privs)

share|improve this answer
    
Hmmm, this StackOverflow answer suggests to me that using sc may not be the correct way to install a Windows Service developed in .NET stackoverflow.com/a/4694224/945456 –  Jeff Bridgman Sep 11 '12 at 14:43
    
It may not be, I guess it depends on your needs. It looks like from that answer that installutil requires a restart to remove the service, and sc does not. Also I can speak from experience that sc delete <said service> does not remove the registry entries and I would be willing to bet that installutil does. (which is why it requires a restart, to reload the registry) –  Dave York Sep 11 '12 at 14:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.