Partager via


PowerShell script list and uninstall programs remotely or local machines using Primalforms to

 

 

 #Generated Form Function
function GenerateForm {
########################################################################
# Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.8.0
# Generated On: 4/15/2011 9:34 PM
# Author By: Raymond
########################################################################
function listprograms {  

Get-WmiObject win32_product -ComputerName $text1.Text | Out-GridView  

}  

function remoteuninstall {  

$app = Get-WmiObject win32_product -ComputerName $text1.Text | Where-Object {$_.name -match $text2.Text}
$app.uninstall() | Select-Object -Property returnvalue
}

#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
#endregion

#region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
$label2 = New-Object System.Windows.Forms.Label
$label1 = New-Object System.Windows.Forms.Label
$Text2 = New-Object System.Windows.Forms.RichTextBox
$Text1 = New-Object System.Windows.Forms.RichTextBox
$Button2 = New-Object System.Windows.Forms.Button
$Button1 = New-Object System.Windows.Forms.Button
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects

#----------------------------------------------
#Generated Event Script Blocks
#----------------------------------------------
#Provide Custom Code for events specified in PrimalForms.
$Button1_OnClick=
{
#TODO: Place custom script here
remoteuninstall
}

$handler_label2_Click=
{
#TODO: Place custom script here

}

$handler_EnterComputerName_TextChanged=
{
#TODO: Place custom script here

}

$handler_label1_Click=
{
#TODO: Place custom script here

}

$handler_button2_Click=
{
#TODO: Place custom script here
listprograms

}

$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
    $form1.WindowState = $InitialFormWindowState
}

#----------------------------------------------
#region Generated Form Code
$form1.BackColor = [System.Drawing.Color]::FromArgb(255,212,208,200)
$form1.Text = "Uninstall program"
$form1.Name = "form1"
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 490
$System_Drawing_Size.Height = 219
$form1.ClientSize = $System_Drawing_Size

$label2.TabIndex = 5
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 154
$System_Drawing_Size.Height = 23
$label2.Size = $System_Drawing_Size
$label2.Text = "Enter Application Name"

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 271
$System_Drawing_Point.Y = 91
$label2.Location = $System_Drawing_Point
$label2.DataBindings.DefaultDataSourceUpdateMode = 0
$label2.Name = "label2"
$label2.add_Click($handler_label2_Click)

$form1.Controls.Add($label2)

$label1.TabIndex = 4
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 141
$System_Drawing_Size.Height = 23
$label1.Size = $System_Drawing_Size
$label1.Text = "Enter Computer Name"

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 24
$System_Drawing_Point.Y = 92
$label1.Location = $System_Drawing_Point
$label1.DataBindings.DefaultDataSourceUpdateMode = 0
$label1.Name = "label1"
$label1.add_Click($handler_label1_Click)

$form1.Controls.Add($label1)

$Text2.Name = "Text2"
$Text2.Text = ""
$Text2.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 271
$System_Drawing_Point.Y = 36
$Text2.Location = $System_Drawing_Point
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 175
$System_Drawing_Size.Height = 29
$Text2.Size = $System_Drawing_Size
$Text2.TabIndex = 3

$form1.Controls.Add($Text2)

$Text1.Name = "Text1"
$Text1.Text = ""
$Text1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 24
$System_Drawing_Point.Y = 36
$Text1.Location = $System_Drawing_Point
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 175
$System_Drawing_Size.Height = 29
$Text1.Size = $System_Drawing_Size
$Text1.TabIndex = 2
$Text1.add_TextChanged($handler_EnterComputerName_TextChanged)

$form1.Controls.Add($Text1)

$Button2.TabIndex = 1
$Button2.Name = "Button2"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 75
$System_Drawing_Size.Height = 23
$Button2.Size = $System_Drawing_Size
$Button2.UseVisualStyleBackColor = $True

$Button2.Text = "List installed programs"

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 371
$System_Drawing_Point.Y = 162
$Button2.Location = $System_Drawing_Point
$Button2.DataBindings.DefaultDataSourceUpdateMode = 0
$Button2.add_Click($handler_button2_Click)

$form1.Controls.Add($Button2)

$Button1.TabIndex = 0
$Button1.Name = "Button1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 75
$System_Drawing_Size.Height = 23
$Button1.Size = $System_Drawing_Size
$Button1.UseVisualStyleBackColor = $True

$Button1.Text = "Uninstall"

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 24
$System_Drawing_Point.Y = 162
$Button1.Location = $System_Drawing_Point
$Button1.DataBindings.DefaultDataSourceUpdateMode = 0
$Button1.add_Click($Button1_OnClick)

$form1.Controls.Add($Button1)

#endregion Generated Form Code

#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$form1.ShowDialog()| Out-Null

} #End Function

#Call the Function
GenerateForm

Comments

  • Anonymous
    January 01, 2003
    Raymond: This is a very cool program but I think there is something missing in the funcion remoteuninstall. Shouldn't there be something beyond:$app = Get-WmiObject win32_product -ComputerName $text1.Text | Where-Object {$_.name -matchWhat is before the close bracket? Thanks again! Very nice work!
  • Anonymous
    January 01, 2003
    BTW, when I say 'missing from the function,' I mean that some of it has been cut from your code after posting it in html format. I know the code works. Sorry for the confusion.