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.

314 lines
8.7 KiB

  1. #include <windows.h>
  2. #include <shellapi.h>
  3. #include "resource.h"
  4. #define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
  5. #define ISK_CLOSEAPP WM_USER + 0x021
  6. HINSTANCE g_hInst;
  7. char g_szTemp[1024];
  8. char g_szTemp2[1024];
  9. //-------------------------------------------------------------------------
  10. //
  11. // R E S 2 S T R
  12. //
  13. //
  14. // Converts a resource identifier into a character pointer
  15. //-------------------------------------------------------------------------
  16. char *Res2Str(int nString)
  17. {
  18. static BOOL fSet = FALSE;
  19. if(fSet)
  20. {
  21. LoadString(g_hInst, nString, g_szTemp, ARRAYSIZE(g_szTemp));
  22. fSet = FALSE;
  23. return(g_szTemp);
  24. }
  25. LoadString(g_hInst, nString, g_szTemp2, ARRAYSIZE(g_szTemp2));
  26. fSet = TRUE;
  27. return(g_szTemp2);
  28. }
  29. //-------------------------------------------------------------------------
  30. //
  31. // P A T H R E M O V E F I L E S P E C
  32. //
  33. //
  34. // Removes the file name from a path
  35. //-------------------------------------------------------------------------
  36. BOOL _PathRemoveFileSpec(LPSTR pFile)
  37. {
  38. LPSTR pT;
  39. LPSTR pT2 = pFile;
  40. for (pT = pT2; *pT2; pT2 = CharNext(pT2)) {
  41. if (*pT2 == '\\')
  42. pT = pT2; // last "\" found, (we will strip here)
  43. else if (*pT2 == ':') { // skip ":\" so we don't
  44. if (pT2[1] =='\\') // strip the "\" from "C:\"
  45. pT2++;
  46. pT = pT2 + 1;
  47. }
  48. }
  49. if (*pT == 0)
  50. return FALSE; // didn't strip anything
  51. //
  52. // handle the \foo case
  53. //
  54. else if ((pT == pFile) && (*pT == '\\')) {
  55. // Is it just a '\'?
  56. if (*(pT+1) != '\0') {
  57. // Nope.
  58. *(pT+1) = '\0';
  59. return TRUE; // stripped something
  60. }
  61. else {
  62. // Yep.
  63. return FALSE;
  64. }
  65. }
  66. else {
  67. *pT = 0;
  68. return TRUE; // stripped something
  69. }
  70. }
  71. //-------------------------------------------------------------------------
  72. //
  73. // F I L E E X I S T S
  74. //
  75. //
  76. // Checks to see if a file exists and returns true if it does
  77. //-------------------------------------------------------------------------
  78. BOOL FileExists( char *pszFile )
  79. {
  80. return (GetFileAttributes( pszFile ) != -1 );
  81. }
  82. //-------------------------------------------------------------------------
  83. //
  84. // E X E C A P P
  85. //
  86. //
  87. // Executes and application and returns the process handle
  88. //-------------------------------------------------------------------------
  89. HANDLE ExecApp( char *command, char *params, char *dir, int nWinState )
  90. {
  91. SHELLEXECUTEINFO sei;
  92. sei.fMask = SEE_MASK_NOCLOSEPROCESS;
  93. sei.hwnd = NULL;
  94. sei.lpVerb = "Open";
  95. sei.lpFile = command;
  96. sei.lpParameters = params;
  97. sei.lpDirectory = dir;
  98. sei.nShow = nWinState;
  99. sei.cbSize = sizeof(sei);
  100. if( ShellExecuteEx(&sei) )
  101. return sei.hProcess;
  102. return NULL;
  103. }
  104. int WINAPI WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow )
  105. {
  106. HANDLE hProcess;
  107. char szCommand[MAX_PATH];
  108. char szParams[MAX_PATH];
  109. char szDir[MAX_PATH];
  110. char szTemp[1024];
  111. char szRetPage[1024];
  112. BOOL fRetPage = FALSE;
  113. HWND hIskRo;
  114. HWND hISW;
  115. g_hInst = hInst;
  116. if( lstrlen( lpCmdLine ) == 0 )
  117. return FALSE;
  118. if( !FileExists( lpCmdLine ) )
  119. return FALSE;
  120. if( GetPrivateProfileInt( "ISK", "NoNT", 0, lpCmdLine ) == 1 )
  121. {
  122. OSVERSIONINFO osver;
  123. osver.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
  124. GetVersionEx( &osver );
  125. if( osver.dwMajorVersion < 4 || osver.dwPlatformId == VER_PLATFORM_WIN32_NT )
  126. {
  127. MessageBox( NULL, Res2Str( IDS_WINNT ), Res2Str( IDS_TITLE ), MB_OK | MB_SETFOREGROUND );
  128. return FALSE;
  129. }
  130. }
  131. if( GetPrivateProfileInt( "ISK", "CloseIE", 0, lpCmdLine ) == 1 )
  132. {
  133. HWND hwndIE;
  134. fRetPage = TRUE;
  135. hwndIE=FindWindow("IEFrame",NULL);
  136. if(hwndIE!=NULL)
  137. {
  138. PostMessage(hwndIE,WM_CLOSE,(WPARAM) NULL,(LPARAM) NULL);
  139. }
  140. else if ((hwndIE=FindWindow("Internet Explorer_Frame",NULL))!=NULL)
  141. {
  142. PostMessage(hwndIE,WM_CLOSE,(WPARAM) NULL,(LPARAM) NULL);
  143. }
  144. else
  145. {
  146. hwndIE=FindWindow("CabinetWClass",NULL);
  147. if(hwndIE!=NULL)
  148. {
  149. PostMessage(hwndIE,WM_CLOSE,(WPARAM) NULL,(LPARAM) NULL);
  150. }
  151. }
  152. hwndIE=FindWindow("IECD",NULL);
  153. if(hwndIE!=NULL)
  154. {
  155. PostMessage(hwndIE,WM_CLOSE,(WPARAM) NULL,(LPARAM) NULL);
  156. }
  157. }
  158. if( GetPrivateProfileInt( "ISK", "RunIExplore", 0, lpCmdLine ) == 1 )
  159. {
  160. char szPage[MAX_PATH];
  161. GetPrivateProfileString( "ISK", "Params", "", szParams, MAX_PATH, lpCmdLine );
  162. lstrcpy( szDir, lpCmdLine );
  163. _PathRemoveFileSpec( szDir );
  164. wsprintf( szPage, "file://%s\\%s", szDir, szParams );
  165. hProcess = ExecApp( "IEXPLORE.EXE", szPage, szDir, SW_SHOWNORMAL );
  166. }
  167. else
  168. {
  169. GetPrivateProfileString( "ISK", "Command", "", szCommand, MAX_PATH, lpCmdLine );
  170. GetPrivateProfileString( "ISK", "Params", "", szParams, MAX_PATH, lpCmdLine );
  171. lstrcpy( szDir, lpCmdLine );
  172. _PathRemoveFileSpec( szDir );
  173. hProcess = ExecApp( szCommand, szParams, szDir, SW_SHOWNORMAL );
  174. }
  175. if( fRetPage )
  176. {
  177. if( hProcess )
  178. {
  179. DWORD dwResult;
  180. while((dwResult=MsgWaitForMultipleObjects(1, &hProcess, FALSE, INFINITE, QS_ALLINPUT))==(WAIT_OBJECT_0 + 1))
  181. {
  182. MSG msg;
  183. // read all of the messages in this next loop
  184. // removing each message as we read it
  185. while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
  186. {
  187. if( msg.message == WM_QUIT )
  188. goto get_out;
  189. DefWindowProc( msg.hwnd, msg.message, msg.wParam, msg.lParam );
  190. // DispatchMessage( &msg );
  191. }
  192. }
  193. }
  194. get_out:
  195. // WaitForSingleObject( hProcess, INFINITE );
  196. hISW = FindWindow( NULL, Res2Str( IDS_ISW ) );
  197. if( hISW != NULL )
  198. {
  199. DWORD dwProcessId;
  200. HANDLE hProcess;
  201. GetWindowThreadProcessId( hISW, &dwProcessId );
  202. hProcess = OpenProcess( PROCESS_ALL_ACCESS, TRUE, dwProcessId );
  203. if( hProcess )
  204. {
  205. DWORD dwResult;
  206. while((dwResult=MsgWaitForMultipleObjects(1, &hProcess, FALSE, INFINITE, QS_ALLINPUT))==(WAIT_OBJECT_0 + 1))
  207. {
  208. MSG msg;
  209. // read all of the messages in this next loop
  210. // removing each message as we read it
  211. while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
  212. {
  213. if( msg.message == WM_QUIT )
  214. goto get_out2;
  215. DefWindowProc( msg.hwnd, msg.message, msg.wParam, msg.lParam );
  216. }
  217. }
  218. }
  219. }
  220. get_out2:
  221. GetPrivateProfileString( "ISK", "RetPage", "", szTemp, 1024, lpCmdLine );
  222. if( lstrlen( szTemp ) > 0 )
  223. {
  224. wsprintf( szRetPage, "%s\\%s", szDir, szTemp );
  225. ExecApp( "IECD.EXE", szRetPage, "", SW_SHOWNORMAL );
  226. }
  227. Sleep( 2000 );
  228. hIskRo = FindWindow( "ISK3RO", NULL );
  229. if( hIskRo ) SendMessage( hIskRo, ISK_CLOSEAPP, 0, 0 );
  230. }
  231. return 0;
  232. }
  233. int _stdcall ModuleEntry(void)
  234. {
  235. int i;
  236. STARTUPINFO si;
  237. LPSTR pszCmdLine = GetCommandLine();
  238. if ( *pszCmdLine == '\"' ) {
  239. /*
  240. * Scan, and skip over, subsequent characters until
  241. * another double-quote or a null is encountered.
  242. */
  243. while ( *++pszCmdLine && (*pszCmdLine != '\"') )
  244. ;
  245. /*
  246. * If we stopped on a double-quote (usual case), skip
  247. * over it.
  248. */
  249. if ( *pszCmdLine == '\"' )
  250. pszCmdLine++;
  251. }
  252. else {
  253. while (*pszCmdLine > ' ')
  254. pszCmdLine++;
  255. }
  256. /*
  257. * Skip past any white space preceeding the second token.
  258. */
  259. while (*pszCmdLine && (*pszCmdLine <= ' ')) {
  260. pszCmdLine++;
  261. }
  262. si.dwFlags = 0;
  263. GetStartupInfoA(&si);
  264. i = WinMain(GetModuleHandle(NULL), NULL, pszCmdLine,
  265. si.dwFlags & STARTF_USESHOWWINDOW ? si.wShowWindow : SW_SHOWDEFAULT);
  266. ExitProcess(i);
  267. return i; // We never comes here.
  268. }