Changes for fixing bugs in code

This commit is contained in:
2021-12-15 09:38:58 +01:00
parent ae965aed86
commit d2a78fd86f
3 changed files with 34 additions and 9 deletions

View File

@@ -1,4 +1,5 @@
# Build 20. Using API 2
# Build 21. Using API 2
Write-Host "Starting Powerful Computer Manager..."
param([Int32]$startup=0)
#Write-Host $startup
$srcdir = $PSCommandPath | Split-Path -Parent
@@ -9,7 +10,8 @@ $64bit = [Environment]::Is64BitOperatingSystem
$computerName = [System.Net.Dns]::GetHostName()
$UUID=(Get-CimInstance Win32_ComputerSystemProduct).UUID
if ((Get-Host | Select-Object Version).Version.Major -lt 6){#Powershell Windows (Not Core)
# Powershell of Windows / Powershell Core
if ((Get-Host | Select-Object Version).Version.Major -lt 6){#Powershell Windows (Not Core) Powershell < 6
add-type -TypeDefinition @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
@@ -27,6 +29,11 @@ if ((Get-Host | Select-Object Version).Version.Major -lt 6){#Powershell Windows
@{'Invoke-RestMethod:SkipCertificateCheck' = $true}
}
# Force install nuget if not installed (If not installed, it breaks uninstalls silently)
If(-not(Get-PackageProvider NuGet -ErrorAction silentlycontinue)){
Install-PackageProvider -Name NuGet -Confirm:$False -Force
}
$exists = Invoke-RestMethod -Method Post -Uri "$server/get/computerexists?ComputerName=$computerName&UUID=$UUID"
if ($exists.Result -eq "ERROR"){
@@ -117,13 +124,20 @@ foreach ($CookName in $cooks){
switch ($step[0].ToUpper()) { #Command
"UNINSTALL" { # Remove program
Get-Package -Name "$param*" -ErrorAction Continue #This will return error if program is not installed, do not see it.
if ($? -eq $True){ #If its True, is that package exists
Get-Package -Name "$param*" -ErrorVariable errvar | Uninstall-Package -ErrorVariable errvar
if ($? -eq $False){ # If fail then put 1 (When fail, powershell returns False)
$err = 1
}
}
# YOU HAVE TO CHECK IF NUGET IS INSTALLED, IF NOT, EXIT AS Error (If not doing this, program will stuck)
If(-not(Get-PackageProvider NuGet -ErrorAction silentlycontinue)){
Write-Host "You don't have NuGet installed! Aborting..."
$err = 1
}else{
# Uninstall package
Get-Package -Name "$param*" -ErrorAction Continue #This will return error if program is not installed, do not see it.
if ($? -eq $True){ #If its True, is that package exists
Get-Package -Name "$param*" -ErrorVariable errvar | Uninstall-Package -ErrorVariable errvar
if ($? -eq $False){ # If fail then put 1 (When fail, powershell returns False)
$err = 1
}
}
}
}
"SERV_DISABLE" { # Disable a service
Set-Service $param -StartupType Disabled -Status Stopped -ErrorVariable errvar