ich habe neu angefangen Scripte für meine Firma zu entwickeln.
Mit einem Script jedoch bin ich nicht ganz zufrieden.
Ich möchte gerne in einem PowerShell Script (PowerShell Console) den Close_Button "ausblenden"/Disablen.
Dies habe ich erfolgreich lösen können, doch OPSI (leider nur OPSI) bringt eine Fehlermeldung. (Hätte gerne Bilder geschickt nur Leider weiß ich hier nicht wie das geht sorry )
Hier ist der Code (ausschnitt) der die Fehlermeldung verursacht:
Code: Alles auswählen
function disable-Window {
try {
# Calling user32.dll methods for Windows and Menus
$MethodsCall = '
[DllImport("user32.dll")] public static extern long GetSystemMenu(IntPtr hWnd, bool bRevert);
[DllImport("user32.dll")] public static extern bool EnableMenuItem(long hMenuItem, long wIDEnableItem, long wEnable);
[DllImport("user32.dll")] public static extern long SetWindowLongPtr(long hWnd, long nIndex, long dwNewLong);
[DllImport("user32.dll")] public static extern bool EnableWindow(long hWnd, int bEnable);
'
# Create a new namespace for the Methods to be able to call them
Add-Type -MemberDefinition $MethodsCall -name NativeMethods -namespace Win32
# WM_SYSCOMMAND Message
$MF_DISABLED = 0x00000002L
$MF_ENABLED = 0x00000000L
#... http://msdn.microsoft.com/en-us/library/windows/desktop/ms647636(v=vs.85).aspx
$SC_CLOSE = 0xF060
#... http://msdn.microsoft.com/en-us/library/windows/desktop/ms646360(v=vs.85).aspx
# Extended Window Styles
$WS_EX_DLGMODALFRAME = 0x00000001L
$WS_EX_STATICEDGE = 0x00020000L
$WS_EX_TRANSPARENT = 0x00000020L
$WS_EX_LAYERED = 0x00080000
#... http://msdn.microsoft.com/en-us/library/windows/desktop/ff700543(v=vs.85).aspx
# Get window handle of Powershell process
$PSWindow = (Get-Process -Id $PID)
$hwnd = $PSWindow.MainWindowHandle
# Get System menu of windows handled
$hMenu = [Win32.NativeMethods]::GetSystemMenu($hwnd, 0)
# Window Style : TOOLWINDOW
[Win32.NativeMethods]::SetWindowLongPtr($hwnd, $GWL_EXSTYLE, $WS_EX_TOOLWINDOW) | Out-Null
# Disable X Button Window itself
[Win32.NativeMethods]::EnableMenuItem($hMenu, $SC_CLOSE, $MF_DISABLED) | Out-Null
# Disable Window itself
[Win32.NativeMethods]::EnableWindow($hwnd, 0) | Out-Null
}catch{}
banner
}
Vielen Dank schon Mal.