- UserSetProcessWindowStation: Use PsGetProcessWin32WindowStation and PsSetProcessWindowStation. Close the prevoious window station handle only when the window station was not set by UserSetProcessWindowStation (should be the case for console apps)
svn path=/trunk/; revision=51496
+NTKERNELAPI
+PVOID
+NTAPI
+PsGetProcessWin32WindowStation(
+ PEPROCESS Process
+);
+
+NTKERNELAPI
+VOID
+NTAPI
+PsSetProcessWindowStation(
+ PEPROCESS Process,
+ PVOID WindowStation
+);
+
ppi = PsGetCurrentProcessWin32Process();
ppi = PsGetCurrentProcessWin32Process();
+ /* Reference the new window station */
if(hWindowStation !=NULL)
{
Status = IntValidateWindowStationHandle( hWindowStation,
if(hWindowStation !=NULL)
{
Status = IntValidateWindowStationHandle( hWindowStation,
}
OldWinSta = ppi->prpwinsta;
}
OldWinSta = ppi->prpwinsta;
- hwinstaOld = ppi->hwinsta;
-
- /*
- * FIXME - don't allow changing the window station if there are threads that are attached to desktops and own gui objects
- */
-
- InterlockedExchangePointer(&PsGetCurrentProcess()->Win32WindowStation, hWindowStation);
-
- ppi->prpwinsta = NewWinSta;
- ppi->hwinsta = hWindowStation;
-
+ hwinstaOld = PsGetProcessWin32WindowStation(ppi->peProcess);
+ /* Dereference the previous window station */
if(OldWinSta != NULL)
{
ObDereferenceObject(OldWinSta);
}
if(OldWinSta != NULL)
{
ObDereferenceObject(OldWinSta);
}
+ /* Check if we have a stale handle (it should happen for console apps) */
+ if(hwinstaOld != ppi->hwinsta)
{
ObCloseHandle(hwinstaOld, UserMode);
}
{
ObCloseHandle(hwinstaOld, UserMode);
}
+ /*
+ * FIXME - don't allow changing the window station if there are threads that are attached to desktops and own gui objects
+ */
+
+ PsSetProcessWindowStation(ppi->peProcess, hWindowStation);
+
+ ppi->prpwinsta = NewWinSta;
+ ppi->hwinsta = hWindowStation;
+