-
Notifications
You must be signed in to change notification settings - Fork 5
/
ServiceRegister.ps1
31 lines (27 loc) · 1.13 KB
/
ServiceRegister.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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."