You get this error when you type 'installutil.exe' in a command prompt.
Reason: .net folder path is not set in the 'PATH' variable because of which location of installutil.exe was not found.
Resolution:
a) Use the visual studio command prompt, it will work there
b) Set .NET folder path in system's 'PATH' variable . Then try it should get the path of 'installutil.exe' and you can use it directly in any command prompt.
c) Use Coding
Resolution:
a) Use the visual studio command prompt, it will work there
b) Set .NET folder path in system's 'PATH' variable . Then try it should get the path of 'installutil.exe' and you can use it directly in any command prompt.
c) Use Coding
It's is really easy to just add it to the service itself. Add a reference to
System.Configuration.Install
and then update your Main()-function in Program.cs like this.static void Main(string[] args)
{
if (Environment.UserInteractive)
{
string parameter = string.Concat(args);
switch (parameter)
{
case "--install":
ManagedInstallerClass.InstallHelper(new[] { Assembly.GetExecutingAssembly().Location });
break;
case "--uninstall":
ManagedInstallerClass.InstallHelper(new[] { "/u", Assembly.GetExecutingAssembly().Location });
break;
}
}
else
{
ServiceBase[] servicesToRun = new ServiceBase[]
{
new ValidatorService()
};
ServiceBase.Run(servicesToRun
Then you can just call
WindowsService1.exe
with the --install
argument and it will install the service and you can forget about InstallUtil.exe
.
Thank you and great job.
ReplyDelete