#Script als Administrator ausführen
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
{ Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }
#Powershell Fenster unterdrücken
$window = Add-Type -memberDefinition @"
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
"@ -name "Win32ShowWindowAsync" -namespace Win32Functions -passThru
$window::ShowWindow((Get-Process –id $pid).MainWindowHandle, 0)
# Die ersten beiden Befehle holen sich die .NET-Erweiterungen (sog. Assemblies) für die grafische Gestaltung in den RAM.
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
# Aktivieren den umfangreichen visuelle Stile im PowerShell-Konsolenmodus:
#[System.Windows.Forms.Application]::EnableVisualStyles()
# Die nächste Zeile erstellt aus der Formsbibliothek das Fensterobjekt.
$objForm = New-Object System.Windows.Forms.Form
# Schrift und Schriftgrößse
$objForm.Font = "Microsoft Sans Serif,10"
#$objForm.ForeColor = "red"
#$objFont = New-Object System.Drawing.Font("Times New Roman",10,[System.Drawing.FontStyle]::Regular)
#$objFont = New-Object System.Drawing.Font("Lucida Console",8,[System.Drawing.FontStyle]::Regular)
#$objForm.Font = $objFont
### Schriftstile sind: Regular, Bold, Italic, Underline, Strikeout
# Hintergrundfarbe für das Fenster festlegen
$objForm.Backcolor= "#f0f0f0"
#$objForm.Backcolor= "white"
#$objForm.BackColor= "Transparent"
# Icon in die Titelleiste aus Datei Magnify.exe setzen
$icon = [System.Drawing.Icon]::ExtractAssociatedIcon("$($ENV:windir)\System32\Magnify.exe")
$objForm.Icon = $Icon
# Hintergrundbild mit Formatierung Zentral = 2
#$objForm.BackgroundImageLayout = 2
#$objForm.BackgroundImage = [System.Drawing.Image]::FromFile('C:\Intel\beenden.png') #kann selbst definiert werden
# Position des Fensters festlegen
$objForm.StartPosition = "CenterScreen"
# Fenstergröße festlegen
$objForm.Size = New-Object System.Drawing.Size(600,620)
# Titelleisten Text festlegen
$objForm.Text = "Wiederherstellungspunkte erstellen anzeigen löschen"
# ---------------------------------------------------------------------------------------------
# Legen Sie die Eigenschaft Topmost auf $True fest, um zu erzwingen,
# dass das Fenster über anderen geöffneten Fenstern und Dialogfeldern geöffnet wird.
#$objForm.Topmost = $True
# Aktivieren des Formulars, und stellt den Fokus auf das von Ihnen erstellte Textfeld ein.
$objForm.Add_Shown({$InputBox1.Select()})
# ---------------------------------------------------------------------------------------------
#################################### Deine Scripte ab hier #################################
#Liest Name ID und Datum der Wiederherstellungspunkt
function Name-ID-Datum {
$Anzahl_raw = Get-WmiObject win32_shadowcopy |measure Count -sum
$Anzahl = $Anzahl_raw.sum
$Name_raw = Get-computerrestorepoint | Sort SequenceNumber |select Description | out-string
$Name = $Name_raw.replace("Description",$null).replace("-----------",$null).trim()
$ID_raw = Get-WmiObject -Class win32_shadowcopy | sort installdate |select ID | out-string
$ID = $ID_raw.replace("ID",$null).replace("--",$null).trim()
$Datum_raw = Get-ComputerRestorePoint | Format-Table @{Label=""; Expression={$_.ConvertToDateTime($_.CreationTime)}}-Auto | out-string
$Datum = $Datum_raw.replace("Date",$null).replace("-------------------",$null).trim()
$outputBox.text= "`r`n" + "Auf diesem System befinden sich $Anzahl Schattenkopien" + "`r`n" + "`r`n" +
"Name:" + "`r`n" + $Name + "`r`n" + "`r`n" +
"ID:" + "`r`n" + $ID + "`r`n" + "`r`n" +
"Datum:" + "`r`n" + $Datum }
# ---------------------------------------------------------------------------------------------
#Wiederherstellungspunkt erstellen mit Progress-Bar
function Erstellen {
if ($InputBox1.Text-gt 1)
{
# startet das Skript im STA-Mode neu, wenn dies erforderlich sein sollte.
If ($host.Runspace.ApartmentState -ne 'STA') {
write-host "Script is not running in STA mode. Switching "
$Script = $MyInvocation.MyCommand.Definition
Start-Process powershell.exe -ArgumentList "-sta $Script"
Exit}
# Grundform
Function Form {
[Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
[Reflection.Assembly]::LoadWithPartialName("System.Drawing") | Out-Null
[Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms.VisualStyles") | Out-Null
$ProgressForm = New-Object System.Windows.Forms.Form
$ProgressForm.Text = "Bitte warten..."
$ProgressForm.Width = 350
$ProgressForm.Height = 100
$ProgressForm.MaximizeBox = $False
$ProgressForm.MinimizeBox = $False
$ProgressForm.ControlBox = $False
$ProgressForm.ShowIcon = $False
$ProgressForm.StartPosition = 1
$ProgressForm.Visible = $False
$ProgressForm.FormBorderStyle = "FixedDialog"
#$ProgressForm.WindowState = "Normal"
$InText = New-Object System.Windows.Forms.Label
$InText.Text = 'Wiederherstellungspunkt wird erstellt...'
$InText.Location = '18,10'
$InText.Size = New-Object System.Drawing.Size(330,18)
$progressBar1 = New-Object System.Windows.Forms.ProgressBar
$ProgressBar1.Name = 'LoadingBar'
$ProgressBar1.Style = "Marquee"
$ProgressBar1.Location = "17,30"
$ProgressBar1.Size = "300,18"
$ProgressBar1.MarqueeAnimationSpeed = 40
$ProgressForm.Controls.Add($InText)
$ProgressForm.Controls.Add($ProgressBar1)
$sharedData.Form = $ProgressForm # Speichern der Form in die Hashtable
[System.Windows.Forms.Application]::EnableVisualStyles()
[System.Windows.Forms.Application]::Run($ProgressForm)
#[System.Windows.Forms.Application]:

oEvents()
}
# Hashtable für Datenaustausch zwischen den Threads
$sharedData = [HashTable]::Synchronized(@{})
$sharedData.Form = $Null
# Thread eigener Runspace mit der Hashtable
$newRunspace = [RunSpaceFactory]::CreateRunspace()
$newRunspace.ApartmentState = "STA"
$newRunspace.ThreadOptions = "ReuseThread"
$newRunspace.Open()
$newRunspace.SessionStateProxy.setVariable("sharedData", $sharedData)
# Thread eigene asynchrone Powershell
$PS = [PowerShell]::Create()
$PS.Runspace = $newRunspace
$PS.AddScript($Function:Form) | Out-Null
$AsyncResult = $PS.BeginInvoke()
# --------------------------------------------------------
# Eigentliches Script ab hier
$erstellen = $InputBox1.text;
$date= Get-Date -UFormat %d.%m.%Y
$outputBox.text= ""
$InputBox1.Text = ""
Checkpoint-Computer -Description "$erstellen $date" -RestorePointType "MODIFY_SETTINGS"
$outputBox.text= "`r`n" + "Wiederherstellungspunkt wurde erstellt"
#$InputBox1.Text = ""
# Eigentliches Script ab hier Ende
# --------------------------------------------------------
# Form schließen
If($sharedData.Form) {$sharedData.Form.close()}
# neue Powershell beenden und Objekt entfernen
$PS.Endinvoke($AsyncResult)
$PS.dispose()
}
else
{
[System.Windows.Forms.MessageBox]::Show("Bitte geben Sie einen Name zum erstellen eines Wiederherstellungspunktes ein","Info",0,"Information")
#$outputBox.Text = "`r`n" + "Bitte geben Sie einen Name zum erstellen eines Wiederherstellungspunktes ein."
}
}
#Wiederherstellungspunkt erstellen mit Progress-Bar Ende
# ---------------------------------------------------------------------------------------------
#Wiederherstellungspunkt Löschen bestimten
function Entfern1 {
if ($InputBox2.Text-match "[1234567890]")
{
$entfern = $InputBox2.text;
#vssadmin delete shadows /for=c: /Shadow=$entfern /quiet
vssadmin delete shadows /Shadow=$entfern /quiet
$outputBox.text= "`r`n" + "Wiederherstellungspunkt wurde gelöcht"
$InputBox2.Text = ""
}
else
{
[System.Windows.Forms.MessageBox]::Show("Bitte geben Sie eine ID zum löschen eines Wiederherstellungspunktes ein","Info",0,"Information")
#$outputBox.Text = "`r`n" + "Bitte geben Sie eine ID zum löschen eines Wiederherstellungspunktes ein."
}
}
#Wiederherstellungspunkt Löschen nur der älteste
function Entfern2 {
# MsgBox:
$result = [System.Windows.Forms.MessageBox]::Show('Wollen Sie den ältesten Wiederherstellungspunkt löschen?', 'Löschung von Daten!', 'YesNo', 'Warning')
# Überprüfen das Ergebnis:
if ($result -eq 'Yes')
{
#vssadmin delete shadows /for=c: /oldest /quiet
vssadmin delete shadows /oldest /quiet
$outputBox.text= "`r`n" + "Der Älteste Wiederherstellungspunkt wurde gelöcht"
$InputBox2.Text = ""
}
else
{
Write-Output "Abbruch!!"
}
}
#Wiederherstellungspunkt Löschen alle
function Entfern3 {
# MsgBox:
$result = [System.Windows.Forms.MessageBox]::Show('Wollen Sie alle Wiederherstellungspunkt löschen?', 'Löschung von Daten!', 'YesNo', 'Warning')
# Überprüfen das Ergebnis:
if ($result -eq 'Yes')
{
#vssadmin delete shadows /for=c: /all /quiet
vssadmin delete shadows /all /quiet
$outputBox.text= "`r`n" + "Alle Wiederherstellungspunkte wurde gelöcht"
$InputBox2.Text = ""
}
else
{
Write-Output "Abbruch!!"
}
}
#Wiederherstellungspunkt Lösche Neuesten
function Entfern4 {
# MsgBox:
$result = [System.Windows.Forms.MessageBox]::Show('Wollen Sie den neuesten Wiederherstellungspunkt löschen?', 'Löschung von Daten!', 'YesNo', 'Warning')
# Überprüfen das Ergebnis:
if ($result -eq 'Yes')
{
#Liest Neueste ID aus
$ID1_raw = Get-WmiObject -Class win32_shadowcopy | sort installdate |select -last 1 |select ID | out-string
$ID1 = $ID1_raw.replace("ID",$null).replace("--",$null).trim()
#vssadmin delete shadows /for=c: /Shadow=$ID1 /quiet
vssadmin delete shadows /Shadow=$ID1 /quiet
$outputBox.text= "`r`n" + "Neuester Wiederherstellungspunkte wurde gelöcht"
$InputBox2.Text = ""
}
else
{
Write-Output "Abbruch!!"
}
}
#################################### Deine Scripte ab hier Ende #################################
# OutputBox
$outputBox = New-Object System.Windows.Forms.TextBox
$outputBox.Location = New-Object System.Drawing.Size(20,140)
$outputBox.Size = New-Object System.Drawing.Size(360,400)
$outputBox.MultiLine = $True
$outputBox.ScrollBars = "Vertical"
#$outputBox.BackColor = "lightgray"
$Anzahl_raw = Get-WmiObject win32_shadowcopy |measure Count -sum
$Anzahl = $Anzahl_raw.sum
$Name_raw = Get-computerrestorepoint | Sort SequenceNumber |select Description | out-string
$Name = $Name_raw.replace("Description",$null).replace("-----------",$null).trim()
$ID_raw = Get-WmiObject -Class win32_shadowcopy | sort installdate |select ID | out-string
$ID = $ID_raw.replace("ID",$null).replace("--",$null).trim()
$Datum_raw = Get-ComputerRestorePoint | Format-Table @{Label=""; Expression={$_.ConvertToDateTime($_.CreationTime)}}-Auto | out-string
$Datum = $Datum_raw.replace("Date",$null).replace("-------------------",$null).trim()
$outputBox.text= "`r`n" + "Auf diesem System befinden sich $Anzahl Schattenkopien" + "`r`n" + "`r`n" +
"Name:" + "`r`n" + $Name + "`r`n" + "`r`n" +
"ID:" + "`r`n" + $ID + "`r`n" + "`r`n" +
"Datum:" + "`r`n" + $Datum
$objForm.Controls.Add($outputBox)
# Textausgabe 1 Hilfe Text
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,10)
$objLabel.Size = New-Object System.Drawing.Size(500,40)
$objLabel.Text = "Gib einen Namen zum erstellen eines Wiederherstellungspunkts an" +
"`r`n" + "oder eine ID zum Löschen eines bestimmten Wiederherstellungspunkts."
$objLabel.Name = "Wiederherstellungspunkt erstellen"
$objForm.Controls.Add($objLabel)
# Textausgabe 2 Name: Erstellen
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(360,60)
$objLabel.Size = New-Object System.Drawing.Size(500,20)
$objLabel.Text = "Name: Erstellen"
$objLabel.Name = "Wiederherstellungspunkt Erstellen"
$objForm.Controls.Add($objLabel)
# Textausgabe 3 ID: Löschen
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(360,100)
$objLabel.Size = New-Object System.Drawing.Size(500,20)
$objLabel.Text = "ID: Löschen"
$objLabel.Name = "Wiederherstellungspunkt Löschen"
$objForm.Controls.Add($objLabel)
# InputBox 1
$InputBox1 = New-Object System.Windows.Forms.TextBox
$InputBox1.Location = New-Object System.Drawing.Size(20,60)
$InputBox1.Size = New-Object System.Drawing.Size(300,40)
#$InputBox1.Text = "Wiederherstellungspunkt"
#$InputBox1.ForeColor = "White"
#$InputBox1.BackColor = "lightgray"
#$InputBox1.MaxLength = 24
$objForm.Controls.Add($InputBox1)
# InputBox 2
$InputBox2 = New-Object System.Windows.Forms.TextBox
$InputBox2.Location = New-Object System.Drawing.Size(20,100)
$InputBox2.Size = New-Object System.Drawing.Size(300,40)
$objForm.Controls.Add($InputBox2)
# Widerherstellungspunkt Name ID und Datum Anzeigen
$AnzeigeButton = New-Object System.Windows.Forms.Button
$AnzeigeButton.Location = New-Object System.Drawing.Size(394,140)
$AnzeigeButton.Size = New-Object System.Drawing.Size(174,46)
$AnzeigeButton.FlatStyle = [System.Windows.Forms.FlatStyle]::Flat
$AnzeigeButton.FlatAppearance.BorderSize=1
$AnzeigeButton.FlatAppearance.BorderColor = [System.Drawing.Color]::Black #White
$AnzeigeButton.ForeColor = "Black"
$AnzeigeButton.BackColor = "lightgray"
$AnzeigeButton.Text = "Wiederherstellungspunkte Anzeigen"
$AnzeigeButton.Add_Click({Name-ID-Datum})
$objForm.Controls.Add($AnzeigeButton)
# Wiederherstellungspunkt Erstellen
$ErstellenButton = New-Object System.Windows.Forms.Button
$ErstellenButton.Location = New-Object System.Drawing.Size(394,200)
$ErstellenButton.Size = New-Object System.Drawing.Size(174,46)
$ErstellenButton.FlatStyle = [System.Windows.Forms.FlatStyle]::Flat
$ErstellenButton.FlatAppearance.BorderSize=1
$ErstellenButton.FlatAppearance.BorderColor = [System.Drawing.Color]::Black
$ErstellenButton.ForeColor = "Black"
$ErstellenButton.BackColor = "#f66cdd"
$ErstellenButton.Text = "Wiederherstellungspunkt Erstellen"
$ErstellenButton.Name = "OK"
$ErstellenButton.Add_Click({Erstellen})
$objForm.Controls.Add($ErstellenButton)
# Wiederherstellungspunkt Löschen Bestimmten
$LoechenButton1 = New-Object System.Windows.Forms.Button
$LoechenButton1.Location = New-Object System.Drawing.Size(394,260)
$LoechenButton1.Size = New-Object System.Drawing.Size(174,46)
$LoechenButton1.FlatStyle = [System.Windows.Forms.FlatStyle]::Flat
$LoechenButton1.FlatAppearance.BorderSize=1
$LoechenButton1.FlatAppearance.BorderColor = [System.Drawing.Color]::Black
$LoechenButton1.ForeColor = "Black"
$LoechenButton1.BackColor = "lightgray"
$LoechenButton1.Text = "Lösche Bestimmten Wiederherstellungspunkt"
$LoechenButton1.Name = "OK"
$LoechenButton1.Add_Click({Entfern1})
$objForm.Controls.Add($LoechenButton1)
# Wiederherstellungspunkt Löschen Älteste
$LoechenButton2 = New-Object System.Windows.Forms.Button
$LoechenButton2.Location = New-Object System.Drawing.Size(394,320)
$LoechenButton2.Size = New-Object System.Drawing.Size(174,46)
$LoechenButton2.FlatStyle = [System.Windows.Forms.FlatStyle]::Flat
$LoechenButton2.FlatAppearance.BorderSize=1
$LoechenButton2.FlatAppearance.BorderColor = "#f7010c"
$LoechenButton2.ForeColor = "Black"
$LoechenButton2.BackColor = "lightgray"
$LoechenButton2.Text = "Lösche Ältesten Wiederherstellungspunkt"
$LoechenButton2.Name = "OK"
$LoechenButton2.Add_Click({Entfern2})
$objForm.Controls.Add($LoechenButton2)
# Wiederherstellungspunkt Löschen Alle
$LoechenButton3 = New-Object System.Windows.Forms.Button
$LoechenButton3.Location = New-Object System.Drawing.Size(394,380)
$LoechenButton3.Size = New-Object System.Drawing.Size(174,46)
$LoechenButton3.FlatStyle = [System.Windows.Forms.FlatStyle]::Flat
$LoechenButton3.FlatAppearance.BorderSize=1
$LoechenButton3.FlatAppearance.BorderColor = "#f7010c"
$LoechenButton3.ForeColor = "Black"
$LoechenButton3.BackColor = "lightgray"
$LoechenButton3.Text = "Lösche Alle Wiederherstellungspunkte"
$LoechenButton3.Name = "OK"
$LoechenButton3.Add_Click({Entfern3})
$objForm.Controls.Add($LoechenButton3)
# Wiederherstellungspunkt Löschen Neuester
$LoechenButton4 = New-Object System.Windows.Forms.Button
$LoechenButton4.Location = New-Object System.Drawing.Size(394,440)
$LoechenButton4.Size = New-Object System.Drawing.Size(174,46)
$LoechenButton4.FlatStyle = [System.Windows.Forms.FlatStyle]::Flat
$LoechenButton4.FlatAppearance.BorderSize=1
$LoechenButton4.FlatAppearance.BorderColor = "#f7010c"
$LoechenButton4.ForeColor = "Black"
$LoechenButton4.BackColor = "lightgray"
$LoechenButton4.Text = "Lösche Neuesten Wiederherstellungspunkt"
$LoechenButton4.Name = "OK"
$LoechenButton4.Add_Click({Entfern4})
$objForm.Controls.Add($LoechenButton4)
# Clear Button
#$ClearButton = New-Object System.Windows.Forms.Button
#$ClearButton.Location = New-Object System.Drawing.Size(394,440)
#$ClearButton.Size = New-Object System.Drawing.Size(174,23)
#$ClearButton.FlatStyle = [System.Windows.Forms.FlatStyle]::Flat
#$ClearButton.FlatAppearance.BorderSize=1
#$ClearButton.FlatAppearance.BorderColor = [System.Drawing.Color]::Black
#$ClearButton.ForeColor = "Black"
#$ClearButton.BackColor = "lightgray"
#$ClearButton.Text = "Lösche Textausgabefeld"
#$ClearButton.Add_Click{$outputBox.Clear()}
#$ClearButton.Add_Click{$InputBox.Clear()}
#$objForm.Controls.Add($ClearButton)
# Beenden Button
$BeendenButton = New-Object System.Windows.Forms.Button
$BeendenButton.Location = New-Object System.Drawing.Size(394,500)
$BeendenButton.Size = New-Object System.Drawing.Size(75,23)
$BeendenButton.FlatStyle = [System.Windows.Forms.FlatStyle]::Flat
$BeendenButton.FlatAppearance.BorderSize=1
$BeendenButton.FlatAppearance.BorderColor = [System.Drawing.Color]::Black
$BeendenButton.ForeColor = "Black"
$BeendenButton.BackColor = "lightgray"
$BeendenButton.Text = "Beenden"
$BeendenButton.Name = "Beenden"
$BeendenButton.DialogResult = "Cancel"
$BeendenButton.Add_Click({$objForm.Close()})
$objForm.Controls.Add($BeendenButton)
<#
# Check Box
$Checkbox = New-Object System.Windows.Forms.CheckBox
#$Checkbox.Location = New-Object System.Drawing.Size(394,510)
$Checkbox.Location = New-Object System.Drawing.Size(380,540)
$checkbox.Size = new-object System.Drawing.Size(240,23)
#$Checkbox.AutoSize = $True
#$Checkbox.Text = "Wiederherstellungspunkt" + "`r`n" + " Erstellen" + "`r`n" + "`r`n" + " Aktivieren"
#$Checkbox.Text = "Lösche Button Aktivieren"
$Checkbox.Text = "Deaktivierte Button Aktivieren"
$objForm.Controls.Add($Checkbox)
$Checkbox.Add_CheckStateChanged({$LoechenButton2.Enabled = $checkbox.Checked})
$LoechenButton2.Enabled = $False
$Checkbox.Add_CheckStateChanged({$LoechenButton3.Enabled = $checkbox.Checked})
$LoechenButton3.Enabled = $False
$Checkbox.Add_CheckStateChanged({$LoechenButton4.Enabled = $checkbox.Checked})
$LoechenButton4.Enabled = $False
#>
# InputBox Tastaturabfrage Enter
$InputBox1.Add_KeyDown({if ($_.KeyCode -eq "Enter") {Erstellen} })
$InputBox2.Add_KeyDown({if ($_.KeyCode -eq "Enter") {Entfern1} })
# ESC Taste Programm Beenden
$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape") {$objForm.Close() } })
# Die letzte Zeile sorgt dafür, dass unser Fensterobjekt auf dem Bildschirm angezeigt wird.
[void] $objForm.ShowDialog()