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

Adding a GUI button for remote uninstalling with WMI #4

Open
wants to merge 5 commits into
base: master
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
120 changes: 113 additions & 7 deletions LazyWinAdmin/LazyWinAdmin.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function Main {
#--------------------------------------------
# Declare Global Variables and Functions here
#--------------------------------------------

#region Get-ComputerTxtBox
function Get-ComputerTxtBox
{ $global:ComputerName = $textbox_computername.Text}
Expand Down Expand Up @@ -5607,6 +5607,11 @@ function Call-MainForm_pff
$buttonShares = New-Object 'System.Windows.Forms.Button'
$buttonEventVwr = New-Object 'System.Windows.Forms.Button'
$button_GPupdate = New-Object 'System.Windows.Forms.Button'


$button_RemoteUninstall = New-Object 'System.Windows.Forms.Button'


$button_Applications = New-Object 'System.Windows.Forms.Button'
$button_ping = New-Object 'System.Windows.Forms.Button'
$button_remot = New-Object 'System.Windows.Forms.Button'
Expand Down Expand Up @@ -7044,6 +7049,90 @@ function Call-MainForm_pff
}
else {Show-MsgBox -BoxType "OKOnly" -Title "$ComputerName - Group Policy Update" -Prompt "Gpupdate does not seem to work! Are you in a Domain ?" -Icon "Exclamation"}
}



$button_RemoteUninstall_Click={
$program_to_uninstall = ""
#region Remote Uninstall GUI
$current_dir = Split-Path $script:MyInvocation.MyCommand.Path
$PROGRAM_OUTPUT = $current_dir + "\programs.txt"
Get-WmiObject Win32_Product -ComputerName $ComputerName | select name | Out-File $PROGRAM_OUTPUT
#Get-RemoteProgram -ComputerName $ComputerName | Out-File $PROGRAM_OUTPUT
$name_arr = Get-Content $PROGRAM_OUTPUT | Sort-Object
# Note: Edited from
# https://foxdeploy.com/resources/ise-snippets/xaml-to-gui/ original XAML loader script
# Change contents of here string to your XAML code from Visual Studio
$RawXAML = @"
<Window x:Class="WpfApplication3.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication3"
mc:Ignorable="d"
Title="Remotely Uninstall Programs" Height="644.151" Width="532.521">
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
<Grid>
<StackPanel x:Name="StackButtonsHere" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top" Width="470"/>
</Grid>
</ScrollViewer>
</Window>
"@

[void][System.Reflection.Assembly]::LoadWithPartialName('PresentationFramework')
[xml]$XAML = $RawXAML -replace 'mc:Ignorable="d"','' -replace "x:N",'N' -replace '^<Win.*', '<Window'

#Read XAML
$XAMLReader= New-Object System.Xml.XmlNodeReader $XAML
try{
$Form=[Windows.Markup.XamlReader]::Load($XAMLReader)
} catch {
Throw "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed."
}

$XAML.SelectNodes("//*[@Name]") |
ForEach-Object {
Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name)
}

Get-Variable WPF*

$counter = 0
foreach ($program_name in $name_arr){
if ($counter -gt 3){
if ($program_name -ne ""){
$NewButton = New-Object System.Windows.Controls.Button
$buttonName = "button"+[string]($counter-4)
$NewButton.Name = $buttonName
$NewButton.Content = $program_name.trimend()
$NewButton.Height = 20
$NewButton.Width = 400
$NewButton.ToolTip = $program_name.trimend()
$NewButton.HorizontalContentAlignment="Left"
$WPFStackButtonsHere.AddChild($NewButton)

$AddedButton = ($WPFStackButtonsHere.Children |
Where-Object {
$_.Name -eq $buttonName
})

# Add Click Event
$AddedButton.Add_Click({
$program_to_uninstall = $this.Content.trimend()
Write-Host $program_to_uninstall
Get-WmiObject Win32_Product -ComputerName $ComputerName | Where-Object{$_.name -match $program_to_uninstall } | ForEach-Object{$_.Uninstall()}
})
}
}
$counter = $counter + 1
}

$Form.ShowDialog() | Out-Null
#endregion

}


$button_Applications_Click={
Get-ComputerTxtBox
Expand Down Expand Up @@ -7426,6 +7515,7 @@ function Call-MainForm_pff
$buttonShares.remove_Click($buttonShares_Click)
$buttonEventVwr.remove_Click($buttonEventVwr_Click)
$button_GPupdate.remove_Click($button_GPupdate_Click)
$button_RemoteUninstall.remove_Click($button_RemoteUninstall_Click)
$button_Applications.remove_Click($button_Applications_Click)
$button_ping.remove_Click($button_ping_Click)
$button_remot.remove_Click($button_remot_Click)
Expand Down Expand Up @@ -7758,7 +7848,7 @@ cMI4bmTc512jvQLAriAIyPd9Y6mAG6gAZUPR6LYBAAAAAElFTkSuQmCC')
$tabcontrol_computer.Multiline = $True
$tabcontrol_computer.Name = "tabcontrol_computer"
$tabcontrol_computer.SelectedIndex = 0
$tabcontrol_computer.Size = '1170, 137'
$tabcontrol_computer.Size = '2170, 137'
$tabcontrol_computer.TabIndex = 11
#
# tabpage_general
Expand All @@ -7768,6 +7858,7 @@ cMI4bmTc512jvQLAriAIyPd9Y6mAG6gAZUPR6LYBAAAAAElFTkSuQmCC')
$tabpage_general.Controls.Add($groupbox_ManagementConsole)
$tabpage_general.Controls.Add($button_GPupdate)
$tabpage_general.Controls.Add($button_Applications)
$tabpage_general.Controls.Add($button_RemoteUninstall)
$tabpage_general.Controls.Add($button_ping)
$tabpage_general.Controls.Add($button_remot)
$tabpage_general.Controls.Add($buttonRemoteAssistance)
Expand All @@ -7779,7 +7870,7 @@ cMI4bmTc512jvQLAriAIyPd9Y6mAG6gAZUPR6LYBAAAAAElFTkSuQmCC')
$tabpage_general.BackColor = 'Control'
$tabpage_general.Location = '4, 22'
$tabpage_general.Name = "tabpage_general"
$tabpage_general.Size = '1162, 111'
$tabpage_general.Size = '4162, 111'
$tabpage_general.TabIndex = 12
$tabpage_general.Text = "General"
#
Expand All @@ -7790,7 +7881,7 @@ cMI4bmTc512jvQLAriAIyPd9Y6mAG6gAZUPR6LYBAAAAAElFTkSuQmCC')
$groupbox_InternetExplorer.Controls.Add($button_IEHPHomepage)
$groupbox_InternetExplorer.Controls.Add($button_HTTPS)
$groupbox_InternetExplorer.Controls.Add($button_IEDellOpenManage)
$groupbox_InternetExplorer.Location = '992, 4'
$groupbox_InternetExplorer.Location = '1035, 4'
$groupbox_InternetExplorer.Name = "groupbox_InternetExplorer"
$groupbox_InternetExplorer.Size = '141, 104'
$groupbox_InternetExplorer.TabIndex = 51
Expand Down Expand Up @@ -7887,12 +7978,12 @@ xt9mqRZgsszPB9gHI9MNpiATHR4oWWT8dSb9IoB2BmFl70cKl4WMZ+JOWA/jmFXuw2oxv69GQIz3
$groupbox_ManagementConsole.Controls.Add($buttonServices)
$groupbox_ManagementConsole.Controls.Add($buttonShares)
$groupbox_ManagementConsole.Controls.Add($buttonEventVwr)
$groupbox_ManagementConsole.Location = '815, 4'
$groupbox_ManagementConsole.Location = '885, 4'
$groupbox_ManagementConsole.Name = "groupbox_ManagementConsole"
$groupbox_ManagementConsole.Size = '171, 77'
$groupbox_ManagementConsole.Size = '157, 77'
$groupbox_ManagementConsole.TabIndex = 49
$groupbox_ManagementConsole.TabStop = $False
$groupbox_ManagementConsole.Text = "Management Console (MMC)"
$groupbox_ManagementConsole.Text = "Management Console"
#
# button_mmcCompmgmt
#
Expand Down Expand Up @@ -8110,6 +8201,21 @@ EAA7')
$tooltipinfo.SetToolTip($button_Applications, "List Applications installed")
$button_Applications.UseVisualStyleBackColor = $True
$button_Applications.add_Click($button_Applications_Click)
#
# button_RemoteUninstall
#
$button_RemoteUninstall.Image = [System.Convert]::FromBase64String('iVBORw0KGgoAAAANSUhEUgAAAC4AAAAuCAYAAABXuSs3AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JQAAgIMAAPn/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VKrSI1EW4k1bOx+lFglNYogKRC0WzRWl2nOT9vO/EQzXT53wdbef4n6qeeIa6eB8EZwbu1ft+xwhZ6jh8mP3y8Kg3d6xb492UJ5MJMvFtxM1lOup5BKGGtJE22TKDZxp5VGzbUgaa3UdHNhmtbMB7QuvkP74gl0e4JNvsp+uuBXTQIFcuODZLYM45a34OaHEG4JIX2sVZg0QYcBSWOVZG2JaGmeaGkebHUd9ua2Pp8S+GZzXjuu1G9zO5N+Zv/f9t8w0iIbewMRtwAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAxNy0wOC0yMlQxNDo0ODozMC0wNDowMGyRApEAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMTctMDgtMjJUMTQ6NDg6MzAtMDQ6MDAdzLotAAAAAElFTkSuQmCC')
$button_RemoteUninstall.ImageAlign = 'TopCenter'
$button_RemoteUninstall.Font = "Microsoft Sans Serif, 8.25pt"
$button_RemoteUninstall.Location = '809, 4'
$button_RemoteUninstall.Name = "button_RemoteUninstall"
$button_RemoteUninstall.Size = '74, 77'
$button_RemoteUninstall.TabIndex = 0
$button_RemoteUninstall.Text = "Uninstall"
$button_RemoteUninstall.TextAlign = 'BottomCenter'
$tooltipinfo.SetToolTip($button_RemoteUninstall, "Remotely Uninstall Applications")
$button_RemoteUninstall.UseVisualStyleBackColor = $True
$button_RemoteUninstall.add_Click($button_RemoteUninstall_Click)
#
# button_ping
#
Expand Down
3 changes: 3 additions & 0 deletions LazyWinAdmin/RunLazyWinadmin.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo on

PowerShell.exe -ExecutionPolicy Bypass -Command "& 'C:\Users\lvelikov\Desktop\LWA_Testing\LazyWinAdmin-PVA\LazyWinAdmin.ps1'"
Binary file added Media/newbutton.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Media/screen2.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.