Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

178 lines
4.1 KiB

  1. // ----------------------------------------------------------------------------
  2. //
  3. // Desktop.c
  4. //
  5. //
  6. // Author: Jost Eckhardt
  7. //
  8. // This code was written for ECO Kommunikation Insight
  9. // Copyright (c) 1997-1999 Microsoft Corporation
  10. //
  11. // ----------------------------------------------------------------------------
  12. #include <windows.h>
  13. #include <TCHAR.h>
  14. #include <WinSvc.h>
  15. #include "_UMTool.h"
  16. #include "UtilMan.h"
  17. #include "LmErr.h"
  18. #include "LmAccess.h"
  19. #include "LmApiBuf.h"
  20. #ifndef ONLY_DSWITCH
  21. // ----------------------------------------------------
  22. BOOL InitDesktopAccess(desktop_access_tsp dAccess)
  23. {
  24. memset(dAccess,0,sizeof(desktop_access_ts));
  25. dAccess->orgStation = GetProcessWindowStation();
  26. dAccess->userStation= OpenWindowStation(_TEXT("WinSta0"), FALSE, MAXIMUM_ALLOWED);
  27. if (!dAccess->userStation)
  28. return FALSE;
  29. SetProcessWindowStation((HWINSTA)dAccess->userStation);
  30. return TRUE;
  31. }
  32. // ----------------------------------------------------
  33. VOID ExitDesktopAccess(desktop_access_tsp dAccess)
  34. {
  35. if (dAccess->orgStation)
  36. SetProcessWindowStation((HWINSTA)dAccess->orgStation);
  37. if (dAccess->userStation)
  38. CloseWindowStation((HWINSTA)dAccess->userStation);
  39. memset(dAccess,0,sizeof(desktop_access_ts));
  40. }
  41. // ----------------------------------------------------
  42. BOOL QueryCurrentDesktop(desktop_tsp desktop,BOOL onlyType)
  43. {
  44. USER_INFO_11 *ui11;//LanManager without Administrator for own account!
  45. LPBYTE buf;
  46. HDESK hdesk;
  47. DWORD nl;
  48. hdesk = OpenInputDesktop(0, FALSE, MAXIMUM_ALLOWED);
  49. if (!hdesk)
  50. {
  51. hdesk = OpenDesktop(_TEXT("Winlogon"),0,FALSE,MAXIMUM_ALLOWED);
  52. if (!hdesk)
  53. {
  54. desktop->userName[0] = 0;
  55. desktop->name[0] = 0;
  56. desktop->type = DESKTOP_ACCESSDENIED;
  57. desktop->user = USER_GUEST;
  58. return FALSE;
  59. }
  60. }
  61. GetUserObjectInformation(hdesk,UOI_NAME,desktop->name,NAME_LEN,&nl);
  62. CloseDesktop(hdesk);
  63. if (!_tcsicmp(desktop->name, _TEXT("Default")))
  64. desktop->type = DESKTOP_DEFAULT;
  65. else if (!_tcsicmp(desktop->name, _TEXT("Winlogon")))
  66. desktop->type = DESKTOP_WINLOGON;
  67. else if (!_tcsicmp(desktop->name, _TEXT("screen-saver")))
  68. desktop->type = DESKTOP_SCREENSAVER;
  69. else if (!_tcsicmp(desktop->name, _TEXT("Display.Cpl Desktop")))
  70. desktop->type = DESKTOP_TESTDISPLAY;
  71. else
  72. desktop->type = DESKTOP_OTHER;
  73. if (onlyType)
  74. {
  75. desktop->userName[0] = 0;
  76. desktop->user = USER_GUEST;
  77. return TRUE;
  78. }
  79. nl = NAME_LEN;
  80. GetUserName(desktop->userName, &nl);
  81. if (!_tcsicmp(desktop->userName,_TEXT("SYSTEM")))
  82. {
  83. desktop->user = USER_SUPERVISOR;
  84. return TRUE;
  85. }
  86. desktop->user = USER_GUEST;
  87. //mDEBUGOUT((1,(uchar_tp)L"%s User: %s", desktop->name,userName));
  88. if (NetUserGetInfo(NULL,//local computer
  89. desktop->userName, 11, &buf) == NERR_Success)
  90. {
  91. ui11 = (USER_INFO_11 *)buf;
  92. switch (ui11->usri11_priv)
  93. {
  94. case USER_PRIV_GUEST:
  95. desktop->user = USER_GUEST;
  96. break;
  97. case USER_PRIV_USER:
  98. desktop->user = USER_USER;
  99. break;
  100. case USER_PRIV_ADMIN:
  101. default:
  102. desktop->user = USER_SUPERVISOR;
  103. }
  104. //if (ui11->usri11_name)
  105. //Vstrncpy(desktop->userName,ui11->usri11_name,PUBLICNAME_LEN);
  106. NetApiBufferFree(buf);
  107. }
  108. return TRUE;
  109. }
  110. #endif //ndef ONLY_DSWITCH
  111. // ----------------------------------------------------
  112. BOOL SwitchToCurrentDesktop(void)
  113. {
  114. HDESK hdesk;
  115. hdesk = OpenInputDesktop(0, FALSE, MAXIMUM_ALLOWED);
  116. if (!hdesk)
  117. {
  118. hdesk = OpenDesktop(_TEXT("Winlogon"),0,FALSE,MAXIMUM_ALLOWED);
  119. if (!hdesk)
  120. return FALSE;
  121. }
  122. CloseDesktop(GetThreadDesktop(GetCurrentThreadId()));
  123. SetThreadDesktop(hdesk);
  124. return TRUE;
  125. }
  126. #ifndef ONLY_DSWITCH
  127. // ----------------------------------------------------
  128. VOID WaitDesktopChanged(desktop_tsp desktop)
  129. {
  130. HDESK hdesk;
  131. DWORD i;
  132. hdesk = OpenInputDesktop(0, FALSE, MAXIMUM_ALLOWED);
  133. for (i = 0; i < 50; i++)
  134. {
  135. if (hdesk)
  136. break;
  137. Sleep(120);
  138. hdesk = OpenDesktop(_TEXT("Winlogon"),0,FALSE,MAXIMUM_ALLOWED);
  139. }
  140. if (hdesk)
  141. CloseDesktop(hdesk);
  142. QueryCurrentDesktop(desktop,TRUE);
  143. SwitchToCurrentDesktop();
  144. }
  145. #endif //ndef ONLY_DSWITCH