Pass parameters to InstallUtil from Powershell
Asked Answered
R

1

1

I am trying to install a windows service from Power-shell as follows.

$sn = """" + $serviceName + " " + $exeName + """"
C:\Windows\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe -i /ServiceName=[$sn]  $exeFilePath

I am getting the following exception.

Microsoft (R) .NET Framework Installation utility Version 2.0.50727.3053
Copyright (c) Microsoft Corporation.  All rights reserved.

Exception occurred while initializing the installation:
System.IO.FileNotFoundException: Could not load file or assembly 'file:///E:\Scheduled' or one of its dependencies. The system cannot f
ind the file specified..

But the following command work.

C:\Windows\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe -i /ServiceName=["Scheduled Download Service"]  $exeFilePath

I am trying to install the Windows Service with a dynamic name and using Power-shell I pass the Service Name. Any help is appreciated.

The answer is correct for VS 2008. But will fail in VS 2012. Because InstallUtil is modified.

You should use $sn = """" + $serviceName + " " + $exeName + """"

The reason is, InstallUtil(2.0) automatically adds the quotes and so we should ignore them (as in the answer). But InstallUtil(4), this is skipped if the string contains quotes in any location (which is a bug? - they should have checked whether there are quotes in the beginning and ending of the string - Currently this breaks all 2.0 code).

Reflecter is your friend.

Rehnberg answered 6/12, 2011 at 8:5 Comment(0)
P
3

Your problem is in this line:

$sn = """" + $serviceName + " " + $exeName + """"

If you will replace it with something simpler, or do it like this:

$sn = $serviceName.ToString() + " " + $exeName

It will work

Premise answered 6/12, 2011 at 8:15 Comment(3)
Thanks. It worked.. However the Service Name is installed as [Scheduled Download Service]. I expect Scheduled Download Service.Rehnberg
Still it is [Scheduled Download Service].Rehnberg
Thanks. Worked - $sn = $serviceName + " " + $exeName C:\Windows\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe -i /ServiceName=$sn $exeFilePathRehnberg

© 2022 - 2024 — McMap. All rights reserved.