Red Gate forums :: View topic - Windows Services
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product support center

Deployment Manager PowerShell Scripts forum

Windows Services

Search in Deployment Manager PowerShell Scripts forum
Post new topic   Reply to topic
Jump to:  
Author Message
justin.caldicott



Joined: 20 Apr 2011
Posts: 18

PostPosted: Fri Dec 14, 2012 3:57 pm    Post subject: Windows Services Reply with quote

This script uses the Service Control tool (sc.exe) to create or update a Windows Service. It assumes some variables have been set in the Deployment Manager web interface:

Code:

# These variables should be set via the Deployment Manager web interface:
#
# ServiceName - Name of the Windows service
# ServiceExecutable - Path to the .exe containing the service
#
# sc.exe is the Service Control utility in Windows
$service = Get-Service $ServiceName -ErrorAction SilentlyContinue
$fullPath = Resolve-Path $ServiceExecutable
if (! $service)
{
  Write-Host "The service will be installed"
  New-Service -Name $ServiceName -BinaryPathName $fullPath -StartupType Automatic
}
else
{
  Write-Host "The service will be stopped and reconfigured"
  Stop-Service $ServiceName -Force
  & "sc.exe" config $service.Name binPath= $fullPath start= auto | Write-Host
}
Write-Host "Starting the service"
Start-Service $ServiceName


This script uses InstallUtil.exe to install custom Event Log sources and Windows Services:

Code:

$NetFrameworkDirectory = $([System.Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory())
& (Join-Path $NetFrameworkDirectory "InstallUtil.exe") "path\to\my.dll" | Write-Host

_________________
Justin Caldicott
Product Manager - Deployment Manager
Red Gate
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group