2016-04-01 5 views
0

Ich verwende diesen Code (unter Windows 2003) zu entfernen und die Größe Fenster:Titelleiste vom Fenster entfernen. Fenster Prozess gestartet durch verschiedene Benutzer

Process process = Process.GetProcessById(12121); 

IntPtr mwh = process.MainWindowHandle; 
SetWindowLong(mwh, GWL_STYLE, WS_VISIBLE); 
ShowWindowAsync(mwh, 3); 
SetWindowPos(mwh, new IntPtr(0), 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED); 

und Erklärungen: [DllImport ("user32.dll")] private static extern bool ShowWindowAsync (IntPtr hWnd, int nCmdShow);

[DllImport("USER32.DLL")] 
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); 

[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)] 
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags); 

static readonly int GWL_STYLE = -16; 
static readonly int SWP_NOMOVE = 0x2; 
static readonly int SWP_NOSIZE = 0x1; 
static readonly int SWP_FRAMECHANGED = 0x20; 
static readonly int WS_VISIBLE = 0x10000000; 

Alles funktioniert korrekt, wenn ich die Fenstergröße mit dem von mir begonnenen Prozess verändere. Aber wenn ich das mit anderen Windows-Benutzern machen will, dann tut es nichts. Wie funktioniert es für andere Benutzer Windows?

Antwort

0

Das Verhalten ist in Windows Vista und höher aufgrund der UIPI (User Interface Privilege Isolation) beabsichtigt. Sie könnten es lösen, wenn Sie Zugriff auf den Quellcode der kontrollierten Anwendungen haben.

Lesen Sie diese Antwort für mehr: https://stackoverflow.com/a/15445510.

+0

Ich habe vergessen zu schreiben, dass es auf Windows 2003 läuft. – resterek

0

process.MainWindowHandle ist ein .NET-Konzept, in nativen Desktop-Apps gibt es kein Hauptfenster und funktioniert daher möglicherweise nicht immer korrekt in anderen Prozessen. Sie sollten überprüfen, ob mwh IntPtr.Zero ist, wenn dies der Fall ist, müssen Sie EnumWindows + GetWindowThreadProcessId + IsWindowVisible verwenden, um das Anwendungsfenster zu finden.

Das Aufrufen von SetWindowLong(mwh, GWL_STYLE, WS_VISIBLE); in einem Fenster, das Sie nicht erstellt haben, ist nicht OK. Sie müssen zuerst GetWindowLong anrufen, um den vorhandenen Stil zu erhalten, remove all the styles you don't want, und WS_POPUP hinzufügen. Möglicherweise möchten Sie auch einige der erweiterten Stile entfernen.