$HideConsoleWindow = '[DllImport("user32.dll")]public static extern bool ShowWindow(IntPtr handle, int state);'
Add-Type -Name WPS -Member $HideConsoleWindow -Namespace CNS -ReferencedAssemblies System.Drawing -ErrorAction SilentlyContinue
[Void][CNS.WPS]::ShowWindow(([System.Diagnostics.Process]::GetCurrentProcess() | Get-Process).MainWindowHandle, 0)
Get-Process | Where-Object -FilterScript {$_.ProcessName -Eq "powershell" -And $_.Id -Ne $PID} | Stop-Process -PassThru
$ErrorActionPreference = "SilentlyContinue"
[Void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
If($MyInvocation.MyCommand.CommandType -Eq "ExternalScript")
{$ScriptPath = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition}
Else{$ScriptPath = Split-Path -Parent -Path ([Environment]::GetCommandLineArgs()[0])
If(-Not$ScriptPath){$ScriptPath = "."}}
Function GenArchiv
{
$ARC_WinForm = New-Object System.Windows.Forms.Form
$ARC_LablTB1 = New-Object System.Windows.Forms.Label
$ARC_LablTB2 = New-Object System.Windows.Forms.Label
$ARC_LablCnc = New-Object System.Windows.Forms.Label
$ARC_TextBx1 = New-Object System.Windows.Forms.TextBox
$ARC_TextBx2 = New-Object System.Windows.Forms.TextBox
$ARC_ChckBox = New-Object System.Windows.Forms.CheckBox
$ARC_GrBxCnc = New-Object System.Windows.Forms.GroupBox
$ARC_WinForm.Controls.AddRange(@(
$ARC_LablTB1,
$ARC_TextBx1,
$ARC_LablTB2,
$ARC_TextBx2,
$ARC_ChckBox,
$ARC_LablCnc,
$ARC_GrBxCnc))
$TMP = "$ScriptPath\TestTemp"
[String]$PathToZipExe = "$TMP\7zaX64.exe"
$CurDate = Get-Date -Format "dd-MM-yyyy"
$Archiv = "$TMP\Documents_Sicherung_$CurDate"
$ARC_WinForm.ClientSize = New-Object System.Drawing.Size(190,160)
$ARC_WinForm.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen
$ARC_WinForm.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::None
$ARC_WinForm.BackColor = [System.Drawing.Color]::FromArgb(255,30,30,30)
$ARC_WinForm.MinimizeBox = $False
$ARC_WinForm.MaximizeBox = $False
$ARC_WinForm.ControlBox = $False
$ARC_WinForm.ShowInTaskbar = $False
$ARC_WinForm.KeyPreview = $True
$ARC_WinForm.Topmost = $True
$ARC_LablTB1.Location = New-Object System.Drawing.Point(10,0)
$ARC_LablTB1.Size = New-Object System.Drawing.Size(190,22)
$ARC_LablTB1.Font = New-Object System.Drawing.Font("Verdena",9,[System.Drawing.FontStyle]::Bold)
$ARC_LablTB1.BackColor = [System.Drawing.Color]::FromArgb(255,30,30,30)
$ARC_LablTB1.ForeColor = [System.Drawing.Color]::Silver
$ARC_LablTB1.Margin = "4,0,4,0"
$ARC_LablTB1.TextAlign = "MiddleLeft"
$ARC_LablTB1.Text = "Kennwort festlegen"
$ARC_TextBx1.Location = New-Object System.Drawing.Point(15,27)
$ARC_TextBx1.Size = New-Object System.Drawing.Size(158,25)
$ARC_TextBx1.Font = New-Object System.Drawing.Font("Consolas",11,[System.Drawing.FontStyle]::Regular)
$ARC_TextBx1.BackColor = [System.Drawing.Color]::FromArgb(255,0,90,0)
$ARC_TextBx1.ForeColor = [System.Drawing.Color]::White
$ARC_TextBx1.Cursor = [System.Windows.Forms.Cursors]::Select
$ARC_TextBx1.UseSystemPasswordChar = $True
$ARC_TextBx1.MaxLength = 15
$ARC_TextBx1.TextAlign = "Center"
$ARC_TextBx1.AutoSize = $False
$ARC_TextBx1.Add_TextChanged(
{
If (-Not([String]::IsNullOrWhiteSpace($ARC_TextBx1.Text)))
{
$ARC_TextBx2.Enabled = $True
$ARC_TextBx2.BackColor = [System.Drawing.Color]::FromArgb(255,0,90,0)
$ARC_TextBx2.Cursor = [System.Windows.Forms.Cursors]::Select
}
Else
{
$ARC_TextBx2.Clear()
$ARC_TextBx2.BackColor = [System.Drawing.Color]::Black
$ARC_TextBx2.Enabled = $False
}
$ARC_WinForm.Add_KeyDown(
{
If ($_.KeyCode -Eq "Enter")
{
If (-Not([String]::IsNullOrWhiteSpace($ARC_TextBx1.Text)))
{
$ARC_TextBx2.Enabled = $True
$ARC_TextBx2.BackColor = [System.Drawing.Color]::FromArgb(255,0,90,0)
$ARC_TextBx2.Cursor = [System.Windows.Forms.Cursors]::Select
$ARC_TextBx2.Select()
}
Else
{
$ARC_TextBx2.Clear()
$ARC_TextBx2.BackColor = [System.Drawing.Color]::Black
$ARC_TextBx2.Enabled = $False
}
}
})
})
$ARC_LablTB2.Location = New-Object System.Drawing.Point(15,54)
$ARC_LablTB2.Size = New-Object System.Drawing.Size(158,22)
$ARC_LablTB2.Font = New-Object System.Drawing.Font("Verdena",9,[System.Drawing.FontStyle]::Bold)
$ARC_LablTB2.BackColor = [System.Drawing.Color]::FromArgb(255,30,30,30)
$ARC_LablTB2.ForeColor = [System.Drawing.Color]::Silver
$ARC_LablTB2.Margin = "4,0,4,0"
$ARC_LablTB2.TextAlign = "MiddleLeft"
$ARC_LablTB2.Text = "Erneut eingeben"
$ARC_TextBx2.Location = New-Object System.Drawing.Point(15,81)
$ARC_TextBx2.Size = New-Object System.Drawing.Size(158,25)
$ARC_TextBx2.Font = New-Object System.Drawing.Font("Consolas",11,[System.Drawing.FontStyle]::Regular)
$ARC_TextBx2.BackColor = [System.Drawing.Color]::FromArgb(255,30,30,30)
$ARC_TextBx2.ForeColor = [System.Drawing.Color]::White
$ARC_TextBx2.Cursor = [System.Windows.Forms.Cursors]::Default
$ARC_TextBx2.UseSystemPasswordChar = $True
$ARC_TextBx2.MaxLength = 16
$ARC_TextBx2.TextAlign = "Center"
$ARC_TextBx2.AutoSize = $False
$ARC_TextBx2.Enabled = $False
$ARC_TextBx2.Add_TextChanged(
{
If ($ARC_TextBx2.Text -Eq $ARC_TextBx1.Text)
{
$ARC_TextBx2.BackColor = [System.Drawing.Color]::FromArgb(255,0,90,0)
$ARC_TextBx2.ForeColor = [System.Drawing.Color]::White
$Script:mkw = $ARC_TextBx1.Text
}
Else
{
$ARC_TextBx2.BackColor = [System.Drawing.Color]::FromArgb(255,30,30,30)
$ARC_TextBx2.ForeColor = [System.Drawing.Color]::Red
}
$ARC_WinForm.Add_KeyDown(
{
If ($_.KeyCode -Eq "Enter")
{
If (Test-Path "$PathToZipExe")
{
$ARC_LablTB1.Text = "Erstelle Archiv ..."
$ARC_LablTB2.Text = "Einen Augenblick ..."
[Array]$Arguments = "a", "-t7z", "-mx=9", "-p$mkw", "-mhe=on", "-m0=lzma2", "$TMP\Documents_Sicherung_$CurDate.7z", "$TMP\*.txt";
& $PathToZipExe $Arguments;
Start-Sleep 3
$ARC_WinForm.Hide()
}
If (-Not(Test-Path "$TMP\Documents_Sicherung_$CurDate.7z"))
{
$MSG = [System.Windows.Forms.MessageBox]::Show("Die Archivdatei wurde nicht erstellt!`n`nBitte den Vorgang wiederholen.","Unbekannter Fehler!","OK","Error")
If ($MSG -Eq "OK")
{
[System.Environment]::Exit(0)
}
}
Else
{
$MSG = [System.Windows.Forms.MessageBox]::Show("Die Archivdatei wurde erstellt.","Vorgang erfolgreich ...","OK","Information")
If ($MSG -Eq "OK")
{
[System.Environment]::Exit(0)
}
}
}
})
})
$ARC_ChckBox.Location = New-Object System.Drawing.Point(15,125)
$ARC_ChckBox.Size = New-Object System.Drawing.Size(80,20)
$ARC_ChckBox.Font = New-Object System.Drawing.Font("Verdena",8,[System.Drawing.FontStyle]::Bold)
$ARC_ChckBox.ForeColor = [System.Drawing.Color]::Silver
$ARC_ChckBox.Cursor = [System.Windows.Forms.Cursors]::Hand
$ARC_ChckBox.Margin = "4,0,4,0"
$ARC_ChckBox.TextAlign = "MiddleLeft"
$ARC_ChckBox.Checked = $False
$ARC_ChckBox.Text = "Anzeigen"
$ARC_ChckBox.Add_CheckStateChanged(
{
If ($ARC_ChckBox.Checked -Eq $True)
{
$ARC_ChckBox.Checked
$ARC_ChckBox.ForeColor = [System.Drawing.Color]::Red
$ARC_TextBx1.UseSystemPasswordChar = $False
$ARC_TextBx2.UseSystemPasswordChar = $False
$ARC_ChckBox.Text = "Verbergen"
}
Else
{
-Not $ARC_ChckBox.Checked
$ARC_ChckBox.ForeColor = [System.Drawing.Color]::Silver
$ARC_TextBx1.UseSystemPasswordChar = $True
$ARC_TextBx2.UseSystemPasswordChar = $True
$ARC_ChckBox.Text = "Anzeigen"
}
})
$ARC_LablCnc.Location = New-Object System.Drawing.Point(100,126)
$ARC_LablCnc.Size = New-Object System.Drawing.Size(75,20)
$ARC_LablCnc.Font = New-Object System.Drawing.Font("Verdena",8,[System.Drawing.FontStyle]::Bold)
$ARC_LablCnc.BackColor = [System.Drawing.Color]::Silver
$ARC_LablCnc.ForeColor = [System.Drawing.Color]::Black
$ARC_LablCnc.Add_MouseHover({$ARC_LablCnc.BackColor = [System.Drawing.Color]::Gray;$ARC_LablCnc.ForeColor = [System.Drawing.Color]::Silver})
$ARC_LablCnc.Add_MouseLeave({$ARC_LablCnc.BackColor = [System.Drawing.Color]::Silver;$ARC_LablCnc.ForeColor = [System.Drawing.Color]::Black})
$ARC_LablCnc.Cursor = [System.Windows.Forms.Cursors]::Hand
$ARC_LablCnc.Margin = "4,0,4,0"
$ARC_LablCnc.TextAlign = "MiddleCenter"
$ARC_LablCnc.Text = "Abbrechen"
$ARC_LablCnc.Add_Click({[System.Environment]::Exit(0)})
$ARC_GrBxCnc.Location = New-Object System.Drawing.Point(97,118)
$ARC_GrBxCnc.Size = New-Object System.Drawing.Size(80,30)
$ARC_TextBx1.Select()
[Void]$ARC_WinForm.ShowDialog()
}
GenArchiv