I want to know if it´s possible to disable Win+D Windows-Shortkey? And the "view Desktop"-Button in the bottom right corner must be disabled, too.
Only for my Script and I´ve got the approach to catch this two processes and after completely minimizing all running programms, THAN open up the Script (only) again. So the Script is everytime viewable on the desktop.
The Script owns a Form
without a Controlbox
.
Suggest it like a Windows-Sidebar-Element that is allways viewable on the Desktop.
To Save the $PID
in a extra LOCAL-File (Script running on each PC from a Server) is necessary, because an other Script in the background run the Script again, if a worker would kill the Task.
Here is my Script Code:
#Clear Sessions
Get-PSSession | Remove-PSSession
#Save current used Process-ID in a TextFile
$PID > C:\Users\Public\Documents\PID.txt
#Imports
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
#$Icon = New-Object System.Drawing.Icon ("Icon-Path here")
#Get NetworkData
$hostname = $env:computername
$IPAdress = (gwmi Win32_NetworkAdapterConfiguration | ? { $_.IPAddress -ne $null }).ipaddress[0]
#Create a Form
$myForm = New-Object System.Windows.Forms.Form
$myForm.DataBindings.DefaultDataSourceUpdateMode = 0
$myForm.Size = New-Object System.Drawing.Size(190,70)
$myForm.Text ="Nutzerdaten"
#Optic-Settings
$myForm.FormBorderStyle = "FixedDialog"
$myForm.MaximizeBox = $false
$myForm.MinimizeBox = $false
$myForm.ControlBox = $false
$myForm.StartPosition = "CenterScreen"
$myForm.ShowInTaskbar = $false #Close-Window-Button unlocked
$myForm.Opacity = 0.6 #0.1 - 1 for transparancy
#$myForm.Icon = $Icon
#Disable Win+D
$myForm.Add_KeyDown({
if( $_.KeyCode -eq "LWin" )
{
Start-Sleep -Seconds 5
[System.Windows.Forms.MessageBox]::Show( "Später wird das Fenster wieder sichtbar gemacht, wenn man Win+D gedrückt hat." )
}
})
#Disable normal closeing (only by crash Script or end PwerShell in Task-Manager)
$myForm.add_FormClosing({$_.Cancel = $true})
#Label with Hostname Data
$lblHost = New-Object System.Windows.Forms.Label
$lblHost.Size = New-Object System.Drawing.Size(180,15)
$lblHost.Top = "5"
$lblHost.Left = "5"
$lblHost.Text = "Hostname : " + $hostname #View Hostname in transparancy mode
$myForm.Controls.Add($lblHost)
#on Click open MessageBox and show closeable Dialog with the IP-Adress and Hostname)
$lblHost.Add_Click({
[System.Windows.Forms.MessageBox]::Show("Hostname = "+$hostname+" | IP-Adress = "+$IPAdress )
})
#Label with IP-Adress (v4 only)
$lblIP = New-Object System.Windows.Forms.Label
$lblIP.Size = New-Object System.Drawing.Size(180,15)
$lblIP.Top = "20"
$lblIP.Left = "5"
$lblIP.Text = "IP-Adress : " + $IPAdress #View Ip-Adress in transparancy mode
$myForm.Controls.Add($lblIP)
#on Click open MessageBox and show closeable Dialog with the IP-Adress and Hostname)
$lblIP.Add_Click({
[System.Windows.Forms.MessageBox]::Show("Hostname = "+$hostname+" | IP-Adress = "+$IPAdress )
})
#View Form/GUI
$myForm.ShowDialog()
Thank you for reading this and I hope that some got any idear how to clear this problem.
Kind regards, M. Lengl