Skip to content

Commit

Permalink
Removed need for PS Core altogether by using sc.exe
Browse files Browse the repository at this point in the history
  • Loading branch information
nike4613 committed Mar 30, 2021
1 parent 676afe2 commit 0535f7c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
11 changes: 3 additions & 8 deletions install-service.ps1
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
if ($PSEdition -neq "Core") {
Write-Host "This script requires PowerShell Core. Get it here: https://github.com/powershell/powershell#get-powershell"
$HOST.UI.RawUI.ReadKey(NoEcho,IncludeKeyDown) | OUT-NULL
$HOST.UI.RawUI.Flushinputbuffer()
}

# Ensure that the script is elevated
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))
{
# Relaunch as an elevated process:
Start-Process pwsh "-ExecutionPolicy","Unrestricted","-File",('"{0}"' -f $MyInvocation.MyCommand.Path) -Verb RunAs
Start-Process powershell "-ExecutionPolicy","Unrestricted","-File",('"{0}"' -f $MyInvocation.MyCommand.Path) -Verb RunAs
exit
}

Set-Location -LiteralPath $PSScriptRoot

# Create the service
New-Service -Name "AudioDGFix" -BinaryPathName "`"$(resolve-path .\AudioDGFix.exe)`" -s" -DependsOn "audiosrv" -StartupType AutomaticDelayedStart
sc.exe create "AudioDGFix" type= own start= delayed-auto binpath= "`"$(resolve-path .\AudioDGFix.exe)`" -s" depend= "audiosrv"
# Immediately start the Service
Start-Service -Name "AudioDGFix"
11 changes: 3 additions & 8 deletions uninstall-service.ps1
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
if ($PSEdition -neq "Core") {
Write-Host "This script requires PowerShell Core. Get it here: https://github.com/powershell/powershell#get-powershell"
$HOST.UI.RawUI.ReadKey(NoEcho,IncludeKeyDown) | OUT-NULL
$HOST.UI.RawUI.Flushinputbuffer()
}

# Ensure that the script is elevated
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))
{
# Relaunch as an elevated process:
Start-Process pwsh "-File",('"{0}"' -f $MyInvocation.MyCommand.Path) -Verb RunAs
Start-Process powershell "-File",('"{0}"' -f $MyInvocation.MyCommand.Path) -Verb RunAs
exit
}

# Remove the service
Stop-Service -Name "AudioDGFix"
Remove-Service -Name "AudioDGFix"
sc.exe stop "AudioDGFix"
sc.exe delete "AudioDGFix"

0 comments on commit 0535f7c

Please sign in to comment.