Created
June 20, 2017 19:55
-
-
Save yaplex/a58863e02ace1d5c7ddd32f2e896894b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$serviceName = "MyService" | |
if (Get-Service $serviceName -ErrorAction SilentlyContinue) | |
{ | |
$serviceToRemove = Get-WmiObject -Class Win32_Service -Filter "name='$serviceName'" | |
$serviceToRemove.delete() | |
"service removed" | |
} | |
else | |
{ | |
"service does not exists" | |
} | |
"installing service" | |
# current directory | |
$directorypath = Split-Path $MyInvocation.MyCommand.Path | |
$secpasswd = ConvertTo-SecureString "MyP@$$w0rd" -AsPlainText -Force | |
$mycreds = New-Object System.Management.Automation.PSCredential (".\MyUserName", $secpasswd) | |
# you need hardcode application name anyway | |
$binaryPath = $directorypath + "\ApplicationName.exe" | |
New-Service -name $serviceName -binaryPathName $binaryPath -displayName $serviceName -startupType Automatic -credential $mycreds | |
"installation completed" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment