Install / Uninstall Windows Service

I created a Windows service project using a project like VSTS 2008 Windows, and now I want to write scripts to install and remove it using PowerShell.

Any reference samples or documents?

+6
windows powershell visual-studio-2008 service
source share
3 answers

Here is the satinized version of the installation script I wrote. It is necessary to demonstrate all that you need to do:

## delete existing service # have to use WMI for much of this, native cmdlets are incomplete $service = Get-WmiObject -Class Win32_Service -Filter "Name = 'My Service'" if ($service -ne $null) { $service | stop-service $service.Delete() | out-null } ## run installutil # 'frameworkdir' env var apparently isn't present on Win2003... $installUtil = join-path $env:SystemRoot Microsoft.NET\Framework\v2.0.50727\installutil.exe $serviceExe = join-path $messageServerPath MyService.exe $installUtilLog = join-path $messageServerPath InstallUtil.log & $installUtil $serviceExe /logfile="$installUtilLog" | write-verbose $service = Get-WmiObject -Class Win32_Service -Filter "Name = 'My Service'" # change credentials if necessary if ($user -ne "" -and $password -ne "") { $service.change($null, $null, $null, $null, $null, $null, $user, $password, $null, $null, $null) | out-null } # activate $service | set-service -startuptype Automatic -passthru | start-service write-verbose "Successfully started service $($service.name)" 
+18
source share

You did not indicate which language you are using. More than likely, the Windows installation utility can handle it.

+4
source share

If I understand your question correctly, first you need to create an installer from VSTS. It has been a while since I did this, but basically it looks like this:

http://csharpcomputing.com/Tutorials/Lesson22.htm

Once you have created the installer, you can automate it using PowerShell.

If you really want PowerShell to be your service installer, there might be a way to automate the installation of Windows Service Installer from PowerShell using the ServiceInstaller Class .

+2
source share

All Articles