Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/refactor #50

Open
wants to merge 5 commits into
base: feature/refactor
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,20 @@ $scriptBlock = {
Write-Host "[$env:ComputerName]: Stopping the service [$ServiceName]"
$serviceObject = Stop-WSMWindowsService -ServiceName $ServiceName
Write-Host "[$env:ComputerName]: Deleting the service [$ServiceName]"
$deleteResults = $serviceObject.Delete()

try {
$deleteResults = $serviceObject.Delete()
Dejulia489 marked this conversation as resolved.
Show resolved Hide resolved
}
catch {
Write-Error "[$env:ComputerName]: Failing remove Service [$ServiceName]. Used ServiceObject [$serviceObject]"
Write-Error $_.Exception.Message
return
}

if($deleteResults.ReturnValue -eq 0)
{
Write-Host "[$env:ComputerName]: Successfully removed [$ServiceName]"
$serviceObject = $null
}
else
{
Expand Down Expand Up @@ -280,22 +290,7 @@ $scriptBlock = {
}


if ($Machines)
{
$newPSSessionSPlat = @{
ComputerName = $Machines
SessionOption = $sessionOption
UseSSL = $UseSSL
}
if ($credential)
{
$newPSSessionSPlat.Credential = $credential
}
$sessions = New-PSSession @newPSSessionSPlat
}

$invokeCommandSplat = @{
Session = $sessions
ArgumentList = $ServiceName,
$ServiceDisplayName,
$ServiceDescription,
Expand All @@ -315,8 +310,23 @@ $invokeCommandSplat = @{
$InstallService
}

# Import utility script into session
Invoke-Command @invokeCommandSplat -FilePath $UTILITY_PATH
if ($Machines)
{
$newPSSessionSPlat = @{
ComputerName = $Machines
SessionOption = $sessionOption
UseSSL = $UseSSL
}
if ($credential)
{
$newPSSessionSPlat.Credential = $credential
}
$sessions = New-PSSession @newPSSessionSPlat
$invokeCommandSplat.Session = $sessions

# Import utility script into session
Invoke-Command @invokeCommandSplat -FilePath $UTILITY_PATH
Dejulia489 marked this conversation as resolved.
Show resolved Hide resolved
}

# Invoke script block
Invoke-Command @invokeCommandSplat -ScriptBlock $scriptBlock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ SeServiceLogonRight = $($currentSetting)
try
{
secedit.exe /configure /db "secedit.sdb" /cfg "$($tmp2)" /areas USER_RIGHTS
#write-host "secedit.exe /configure /db ""secedit.sdb"" /cfg ""$($tmp2)"" /areas USER_RIGHTS "
#Write-Host "secedit.exe /configure /db ""secedit.sdb"" /cfg ""$($tmp2)"" /areas USER_RIGHTS "
}
finally
{
Expand Down Expand Up @@ -220,13 +220,16 @@ function Get-WSMFullExecuteablePath
[switch]
$JustParentPath = $false
)
Write-Verbose "StartCommand=[$StartCommand]"
Write-Verbose "StringContainingPath=[$StringContainingPath]"
# pattern to analyse Service Startup Command
$matchPattern = '( |^)(?<path>([a-zA-Z]):\\([\\\w\/\(\)\[\]{}öäüÖÄÜ°^!§$%&=`´,;@#+._-]+)(.exe|.dll))|(( "|^")(?<path2>(([a-zA-Z]):\\([\\\w\/\(\)\[\]{}öäüÖÄÜ°^!§$%&=`´,;@#+._ -]+)(.exe|.dll)))(" |"$))'

# check if PathName can be processed
if ($StringContainingPath -notmatch $matchPattern)
#if ($StringContainingPath -notmatch $matchPattern)
if ($StartCommand -notmatch $matchPattern) #as workaround it will not be Used the parameter. The function Parameter always trims the Quotes.
{
return Write-Warning -Message "String can't be parsed. The StringContainingPath parameter should contain a valid Path ending with an '.exe' or '.dll'. Current string [$StringContainingPath]"
return Write-Warning -Message "String can't be parsed. The StringContainingPath parameter should contain a valid Path without spaces or wrapped in quotes and ending with an '.exe' or '.dll'. Current string [$StringContainingPath]"
}

# extract Path
Expand Down
2 changes: 1 addition & 1 deletion WindowsServiceManager/WindowsServiceManagerV5/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 5,
"Minor": 0,
"Patch": 1
"Patch": 5
},
"instanceNameFormat": "Deploy Windows Service",
"groups": [
Expand Down
2 changes: 1 addition & 1 deletion vss-extension.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifestVersion": 1,
"id": "WindowsServiceManager",
"version": "5.0.3",
"version": "5.0.7",
"name": "Windows Service Manager",
"description": "Installs and deploys a windows service or TopShelf service on a target machine or a deployment group target.",
"publisher": "MDSolutions",
Expand Down