Skip to content

Commit

Permalink
Add register service files.
Browse files Browse the repository at this point in the history
  • Loading branch information
ctigeek committed Oct 1, 2014
1 parent a845b23 commit ec195e2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
31 changes: 31 additions & 0 deletions ServiceRegister.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
$serviceName = "DbSync"
$description = "Synchronizes data for Control Panel from MySql to Sql Server"
$exePath = "D:\DbSyncService\DbSyncService.exe"
$username = ".\LocalSystem"
$password = convertto-securestring -String "sss" -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password

$existingService = Get-WmiObject -Class Win32_Service -Filter "Name='$serviceName'"

if ($existingService)
{
"'$serviceName' exists already. Stopping."
Stop-Service $serviceName
"Waiting 3 seconds to allow existing service to stop."
Start-Sleep -s 3

$existingService.Delete()
"Waiting 5 seconds to allow service to be uninstalled."
Start-Sleep -s 5
}

"Installing the service."
New-Service -BinaryPathName $exePath -Name $serviceName -Credential $cred -DisplayName $serviceName -Description $description -StartupType Manual
"Installed the service."
$ShouldStartService = Read-Host "Would you like the '$serviceName ' service started? Y or N"
if($ShouldStartService -eq "Y")
{
"Starting the service."
Start-Service $serviceName
}
"Completed."
20 changes: 20 additions & 0 deletions ServiceUnregister.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
$serviceName = "DbSync"
$description = "Synchronizes data for Control Panel from MySql to Sql Server"
$exePath = "D:\DbSyncService\DbSyncService.exe"


$existingService = Get-WmiObject -Class Win32_Service -Filter "Name='$serviceName'"

if ($existingService)
{
"'$serviceName' exists already. Stopping."
Stop-Service $serviceName
"Waiting 3 seconds to allow existing service to stop."
Start-Sleep -s 3

$existingService.Delete()
"Waiting 5 seconds to allow service to be uninstalled."
Start-Sleep -s 5
}

"Completed."

0 comments on commit ec195e2

Please sign in to comment.