Scripting Windows Platform

Powershell Find licence key,List program,Unistall a program,Show process,Kill process

<#

Find license key, List program,Uninstall a program, Show the process, Kill process from powershell

Hi all, You will find below a script that will help you manage a remote computer from PowerShell. With this script you will be able: 1- Find from a remote computer, the license key. 2- List all program install on a remote computer 3- Uninstall a program remotely 4- Show remote computer process 5- Kill active process remotely and much more.

———————————————-

Read your Windows Key with Powershell

When you enter, register, and activate your copy of Windows with a retail key, the information is stored in the Windows Registry. Now this key is embedded in the BIOS / UEFI.

Find Windows product key

It should be noted that a retail product license is bound to the individual while the OEM product key is bound to the machine, in accordance with the Microsoft Windows Desktop license terms.

This function will display the licence key
#>
Function LicenceKey {
$computernameselect = $usercomputer.SelectedItem.ToString();
$licencekey = (Get-WmiObject -ComputerName $computernameselect -query “select * from SoftwareLicensingService”).OA3xOriginalProductKey
[System.Windows.Forms.MessageBox]::Show($licencekey,”Message”,1)
}

<#
Installed Software
This fonction use WMI, to list which applications are available remotely.

#>
Function ShowProgramList {
$ComputerNameSelect = $UserComputer.SelectedItem.ToString();
$Procs =  Get-WmiObject -Class Win32_Product -Computer $computernameselect | Sort-Object Name
Addprogram  $procs $list
}

<#
This fonction will display the application list from the select remote computer.

#>

Function AddProgram{
param($procs, $list)
$list.BeginUpdate()
$list.items.Clear()
foreach ($proc2 in $procs)
{
$item = New-Object    System.Windows.Forms.ListViewItem($proc2.Name)
[Void]$item.SubItems.Add($proc2.InstallDate)
[Void] $list.Items.Add($item)
}
$list.EndUpdate()
}

<#
This fonction unistall remote application .

#>

Function UnistallProgram {
$ProgramUninstall = $list.SelectedItems.text
$computernameselect = $usercomputer.SelectedItem.ToString();
[System.Windows.Forms.MessageBox]::Show($programuninstall,”Message”,1)
$app = Get-WmiObject Win32_Product -ComputerName $computernameselect | where { $_.name -eq $programuninstall }
$app.Uninstall()
showprogram
}

Function ListEvent {
param($procs, $list)
$list.BeginUpdate()
$list.items.Clear()
foreach ($proc2 in $procs)
{

$item = New-Object System.Windows.Forms.ListViewItem($proc2.Message)
[string] $timeG = $proc2.TimeGenerated
[Void]$item.SubItems.Add($timeG )
[Void] $list.Items.Add($item)
}
$list.EndUpdate()
}

Function Showevent {
$computernameselect = $usercomputer.SelectedItem.ToString();
$systemevent = Get-EventLog -ComputerName $computernameselect -LogName system -EntryType Error -Newest 45
$applicationevent = Get-EventLog -ComputerName $computernameselect – LogName application -EntryType Error -Newest 45
$procs = $systemevent + $applicationevent
$global:exportvalue = $procs
ListEvent  $procs $list
}

Function EditEvent {
$Editevent = $list.SelectedItems.text
[System.Windows.Forms.MessageBox]::Show($Editevent,”Message”,1)
}

Function ListProcess{
param($procs, $list)
$list.BeginUpdate()
$list.items.Clear()
Foreach ($proc2 in $procs)
{
$item = New-Object System.Windows.Forms.ListViewItem($proc2.processName)
[Void]$item.SubItems.Add($proc2.id)
[Void] $list.Items.Add($item)
}
$list.EndUpdate()
}

Function KillProcess {
$computernameselect = $usercomputer.SelectedItem.ToString();
$procs = Get-Process -computerName $computernameselect
$global:exportvalue = $procs
$killprocess = $list.SelectedItems.text

Foreach ($row in $procs ) {
if ($row.ProcessName -eq $killprocess) {
(Get-WmiObject Win32_Process -ComputerName $computernameselect | ?{ $_.ProcessName -match $killprocess }).Terminate()
}
}
ListProcess $procs $list
}

Function UserSelectProcess {
$computernameselect = $usercomputer.SelectedItem.ToString();
$procs = Get-Process -computerName $computernameselect | Sort-Object processName
$computernameselect
Listprocess  $procs $list

}

$Formprocess = New-Object System.Windows.Forms.Form
$formprocess.Text = “Remote Control”
$Formprocess.Size = New-Object System.Drawing.Size(300,150)
$Formprocess.StartPosition = “CenterScreen”
$formprocess.Font = New-Object System.Drawing.Font(“Segoe UI”,10)
$Formprocess.Width = 480
$Formprocess.Height = 870

$list = New-Object System.Windows.Forms.ListView
$list.TabIndex = 11

$list.Width = 440
$list.Height = 560
$list.Location = ‘10,10’
$list.View = “Details”
$list.GridLines = $true
$list.FullRowSelect = $true
$list.AllowColumnReorder = $true
$list.Scrollable = $true
$list.Sorting =’None’
$list.add_ColumnClick({SortList $_.Column})
# $list.LabelEdit = $true

$formprocess.Controls.Add($list)

$tag2 = New-Object -TypeName PSCustomObject -Property @{
sortOrder = [System.Windows.Forms.SortOrder]::Ascending
}

# Create the columns
$col = $list.Columns.Add(“Name”, 300)
$col.Tag = $tag2
$col = $list.Columns.Add(“”, 120)
$col.Tag = $tag2

# Add task button to list
$btnquit = New-Object System.Windows.Forms.Button
$btnquit.Name = “btnquit”
$btnquit.Size = New-Object System.Drawing.Size(100,30)
$btnquit.Text = “Quit”
$btnquit.Location = New-Object System.Drawing.Size(360,790)
$btnquit.add_Click({quitprocess})
$formprocess.Controls.Add($btnquit)

# Add event button to list
$btnevent = New-Object System.Windows.Forms.Button
$btnevent.Name = “btnevent”
$btnevent.Size = New-Object System.Drawing.Size(100,30)
$btnevent.Text = “List Event”
$btnevent.Location = New-Object System.Drawing.Size(360,590)
$btnevent.add_Click({Showevent})
$formprocess.Controls.Add($btnevent)

# Add edit event button to list
$btneventedit = New-Object System.Windows.Forms.Button
$btneventedit.Name = “btneventedit”
$btneventedit.Size = New-Object System.Drawing.Size(100,30)
$btneventedit.Text = “Edit Event”
$btneventedit.Location = New-Object System.Drawing.Size(360,630)
$btneventedit.add_Click({editevent})
$formprocess.Controls.Add($btneventedit)

# Add task button to list
$btnkill = New-Object System.Windows.Forms.Button
$btnkill.Name = “btnkill”
$btnkill.Size = New-Object System.Drawing.Size(100,30)
$btnkill.Text = “Kill Process”
$btnkill.Location = New-Object System.Drawing.Size(240,630)
$btnkill.add_Click({killprocess})
$formprocess.Controls.Add($btnkill)

# Add task button to list
$btnuninstall = New-Object System.Windows.Forms.Button
$btnuninstall.Name = “btnuninstall”
$btnuninstall.Size = New-Object System.Drawing.Size(90,30)
$btnuninstall.Text = “Uninstall”
$btnuninstall.Location = New-Object System.Drawing.Size(10,630)
$btnuninstall.add_Click({unistallprogram})
$formprocess.Controls.Add($btnuninstall)

# Add task button to list
$btngo = New-Object System.Windows.Forms.Button
$btngo.Name = “btngo”
$btngo.Size = New-Object System.Drawing.Size(100,30)
$btngo.Text = “Show Process”
$btngo.Location = New-Object System.Drawing.Size(240,590)
$btngo.add_Click({userlectprocess})
$formprocess.Controls.Add($btngo)

# Add task button to list
$btnshowprogram = New-Object System.Windows.Forms.Button
$btnshowprogram.Name = “btnshowprogram”
$btnshowprogram.Size = New-Object System.Drawing.Size(90,30)
$btnshowprogram.Text = “S Program”
$btnshowprogram.Location = New-Object System.Drawing.Size(10,590)
$btnshowprogram.add_Click({showprogram})
$formprocess.Controls.Add($btnshowprogram)

# Add liscence Key button
$btnlicencekey= New-Object System.Windows.Forms.Button
$btnlicencekey.Name = “btnlicenceKey”
$btnlicencekey.Size = New-Object System.Drawing.Size(120,30)
$btnlicencekey.Text = “Window Key”
$btnlicencekey.Location = New-Object System.Drawing.Size(110,630)
$btnlicencekey.add_Click({LicenceKey})
$formprocess.Controls.Add($btnlicencekey)

# Add export Key button
$btnexport= New-Object System.Windows.Forms.Button
$btnexport.Name = “btnlicenceKey”
$btnexport.Size = New-Object System.Drawing.Size(120,30)
$btnexport.Text = “Export”
$btnexport.Location = New-Object System.Drawing.Size(110,670)
$btnexport.add_Click({exportinfo})
$formprocess.Controls.Add($btnexport)

$usercomputer = New-Object System.Windows.Forms.ComboBox
$usercomputer.Location = New-Object System.Drawing.Size(110,590)
$usercomputer.Size = New-Object System.Drawing.Size(120,100)
$usercomputer.Height = 100

[void] $usercomputer.Items.Add(“COM-AUDAIN”)
[void] $usercomputer.Items.Add(“10.44.43.51”)
[void] $usercomputer.Items.Add(“10.44.43.51”)
[void] $usercomputer.Items.Add(“RemoteJeanComputer”)

$usercomputer.Sorted = $true;
$usercomputer.Text = “COM-AUDAIN”;
$usercomputer.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList
$formprocess.Controls.Add($usercomputer)

$btnuninstall.visible = $false
$btneventedit.Visible = $false
$btnkill.Visible = $False
$formprocess.ShowDialog()| Out-Null