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.

350 lines
9.0 KiB

  1. #include <windows.h>
  2. #include "resource.h"
  3. #define ISK_STARTAPP WM_USER + 0x020
  4. #define ISK_CLOSEAPP WM_USER + 0x021
  5. #define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
  6. HINSTANCE g_hInst;
  7. char g_lpCmd[MAX_PATH];
  8. int g_nCount=0;
  9. BOOL g_fFirst = FALSE;
  10. HANDLE g_hExec;
  11. BOOL _PathRemoveFileSpec(LPSTR pFile)
  12. {
  13. LPSTR pT;
  14. LPSTR pT2 = pFile;
  15. for (pT = pT2; *pT2; pT2 = CharNext(pT2)) {
  16. if (*pT2 == '\\')
  17. pT = pT2; // last "\" found, (we will strip here)
  18. else if (*pT2 == ':') { // skip ":\" so we don't
  19. if (pT2[1] =='\\') // strip the "\" from "C:\"
  20. pT2++;
  21. pT = pT2 + 1;
  22. }
  23. }
  24. if (*pT == 0)
  25. return FALSE; // didn't strip anything
  26. //
  27. // handle the \foo case
  28. //
  29. else if ((pT == pFile) && (*pT == '\\')) {
  30. // Is it just a '\'?
  31. if (*(pT+1) != '\0') {
  32. // Nope.
  33. *(pT+1) = '\0';
  34. return TRUE; // stripped something
  35. }
  36. else {
  37. // Yep.
  38. return FALSE;
  39. }
  40. }
  41. else {
  42. *pT = 0;
  43. return TRUE; // stripped something
  44. }
  45. }
  46. HRESULT LaunchProcess(LPCSTR pszCmd, HANDLE *phProc, LPCSTR pszDir, UINT uShow)
  47. {
  48. STARTUPINFO startInfo;
  49. PROCESS_INFORMATION processInfo;
  50. HRESULT hr = S_OK;
  51. BOOL fRet;
  52. if(phProc)
  53. *phProc = NULL;
  54. // Create process on pszCmd
  55. ZeroMemory(&startInfo, sizeof(startInfo));
  56. startInfo.cb = sizeof(startInfo);
  57. startInfo.dwFlags |= STARTF_USESHOWWINDOW;
  58. startInfo.wShowWindow = (WORD) uShow;
  59. fRet = CreateProcess(NULL, (LPSTR) pszCmd, NULL, NULL, FALSE,
  60. NORMAL_PRIORITY_CLASS, NULL, pszDir, &startInfo, &processInfo);
  61. if(!fRet)
  62. return E_FAIL;
  63. if(phProc)
  64. *phProc = processInfo.hProcess;
  65. else
  66. CloseHandle(processInfo.hProcess);
  67. CloseHandle(processInfo.hThread);
  68. return S_OK;
  69. }
  70. //=--------------------------------------------------------------------------=
  71. // Function name here
  72. //=--------------------------------------------------------------------------=
  73. // Function description
  74. //
  75. // Parameters:
  76. //
  77. // Returns:
  78. //
  79. // Notes:
  80. //
  81. HRESULT LaunchAndWait(LPSTR pszCmd, HANDLE hAbort, HANDLE *phProc, LPSTR pszDir, UINT uShow)
  82. {
  83. HRESULT hr = S_OK;
  84. hr = LaunchProcess(pszCmd, phProc, pszDir, uShow);
  85. if(SUCCEEDED(hr))
  86. {
  87. DWORD dwRet;
  88. HANDLE pHandles[2];
  89. BOOL fQuit = FALSE;
  90. pHandles[0] = *phProc;
  91. if(hAbort)
  92. pHandles[1] = hAbort;
  93. while(!fQuit)
  94. {
  95. dwRet = MsgWaitForMultipleObjects(hAbort ? 2 : 1, pHandles, FALSE, INFINITE, QS_ALLINPUT);
  96. // Give abort the highest priority
  97. if(dwRet == WAIT_OBJECT_0)
  98. {
  99. fQuit = TRUE;
  100. }
  101. else if((dwRet == WAIT_OBJECT_0 + 1) && hAbort)
  102. {
  103. // Any abort work?
  104. hr = E_ABORT;
  105. fQuit = TRUE;
  106. }
  107. else
  108. {
  109. MSG msg;
  110. // read all of the messages in this next loop
  111. // removing each message as we read it
  112. while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
  113. {
  114. // if it's a quit message we're out of here
  115. if (msg.message == WM_QUIT)
  116. {
  117. TerminateProcess(pHandles[0],0);
  118. fQuit = TRUE;
  119. }
  120. else
  121. {
  122. // otherwise dispatch it
  123. DispatchMessage(&msg);
  124. } // end of PeekMessage while loop
  125. }
  126. }
  127. }
  128. }
  129. return hr;
  130. }
  131. LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
  132. {
  133. char szCDPath[MAX_PATH];
  134. char * szCheckRunOnce;
  135. char szMsg[128];
  136. char szPath[MAX_PATH];
  137. char szWinPath[MAX_PATH];
  138. char szTest[MAX_PATH];
  139. long lResult;
  140. HKEY hkRunOnce;
  141. DWORD dwTest;
  142. switch( msg )
  143. {
  144. case WM_CREATE:
  145. ShowWindow( hWnd, SW_HIDE );
  146. lstrcpy( szCDPath, g_lpCmd);
  147. _PathRemoveFileSpec( szCDPath );
  148. if(LaunchAndWait(g_lpCmd, NULL, &g_hExec, szCDPath, SW_SHOWNORMAL)==E_FAIL)
  149. {
  150. TCHAR szMessage[MAX_PATH];
  151. TCHAR szTitle[MAX_PATH];
  152. LoadString( g_hInst, IDS_CDMESSAGE, szMessage, MAX_PATH );
  153. LoadString( g_hInst, IDS_CDTITLE, szTitle, MAX_PATH );
  154. MessageBox(NULL,szMessage,szTitle,MB_OK);
  155. }
  156. SendMessage(hWnd,WM_CLOSE,(WPARAM) 0,(LPARAM) 0);
  157. break;
  158. case ISK_STARTAPP:
  159. if( !g_fFirst )
  160. g_fFirst = TRUE;
  161. g_nCount++;
  162. // wsprintf( szMsg, "Start App\ng_nCount++\ng_nCount: %d", g_nCount );
  163. // MessageBox( NULL, szMsg, "ISK3RO", MB_OK | MB_SETFOREGROUND );
  164. break;
  165. case ISK_CLOSEAPP:
  166. g_nCount--;
  167. if( g_fFirst )
  168. {
  169. if( g_nCount < 1 )
  170. PostQuitMessage(0);
  171. }
  172. wsprintf( szMsg, "Close App\ng_nCount--\ng_nCount: %d", g_nCount );
  173. // MessageBox( NULL, szMsg, "ISK3RO", MB_OK | MB_SETFOREGROUND );
  174. break;
  175. case WM_DESTROY:
  176. PostQuitMessage(0);
  177. break;
  178. default:
  179. return DefWindowProc( hWnd, msg, wParam, lParam );
  180. }
  181. return 1;
  182. }
  183. void RegisterMe( )
  184. {
  185. WNDCLASS wc;
  186. MSG msg;
  187. wc.style = 0;
  188. wc.lpfnWndProc = MainWndProc;
  189. wc.cbClsExtra = wc.cbWndExtra = 0;
  190. wc.hInstance = g_hInst;
  191. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  192. wc.hIcon = NULL;
  193. wc.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
  194. wc.lpszMenuName = NULL;
  195. wc.lpszClassName = "ISK3RO";
  196. RegisterClass(&wc);
  197. CreateWindow( "ISK3RO", "Isk3Ro", WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, 0, 0, 30, 30,
  198. NULL, NULL, g_hInst, NULL );
  199. while( GetMessage( &msg, NULL, 0, 0 ) )
  200. {
  201. TranslateMessage( &msg );
  202. DispatchMessage( &msg );
  203. }
  204. }
  205. int WINAPI WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow )
  206. {
  207. char szCDPath[MAX_PATH];
  208. HWND hwndIE=NULL;
  209. char *pParams;
  210. int i;
  211. int len;
  212. BOOL bIsOk;
  213. HKEY hkCheckCD;
  214. g_hInst = hInst;
  215. lstrcpy( g_lpCmd, lpCmdLine );
  216. if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion",0,KEY_READ|KEY_WRITE,&hkCheckCD)==ERROR_SUCCESS)
  217. {
  218. HKEY hkTips;
  219. TCHAR szClass[64];
  220. char szCheckCD[MAX_PATH];
  221. DWORD dwType=REG_SZ;
  222. DWORD dwSize;
  223. DWORD dwRes;
  224. dwSize = sizeof(szCheckCD);
  225. if(RegQueryValueEx(hkCheckCD,"DeleteWelcome",NULL,&dwType,szCheckCD,&dwSize)==ERROR_SUCCESS)
  226. {
  227. DeleteFile(szCheckCD);
  228. RegDeleteValue(hkCheckCD, "DeleteWelcome");
  229. if(RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Tips", 0, szClass,
  230. REG_OPTION_NON_VOLATILE,KEY_READ|KEY_WRITE,NULL,&hkTips,&dwRes)
  231. == ERROR_SUCCESS)
  232. {
  233. DWORD K0 = 0;
  234. RegSetValueEx(hkTips, "ShowIE4", 0, REG_DWORD,(LPBYTE) &K0, 4);
  235. RegCloseKey(hkTips);
  236. }
  237. }
  238. dwSize = sizeof(szCheckCD);
  239. if(RegQueryValueEx(hkCheckCD,"CDForcedOn",NULL,&dwType,szCheckCD,&dwSize)==ERROR_SUCCESS)
  240. {
  241. RegDeleteValue(hkCheckCD,"CDForcedOn");
  242. if(RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Tips", 0, szClass,
  243. 0,KEY_READ|KEY_WRITE,NULL,&hkTips,NULL)
  244. == ERROR_SUCCESS)
  245. {
  246. DWORD K0 = 0;
  247. RegSetValueEx(hkTips, "ShowIE4", 0, REG_DWORD,(LPBYTE) &K0, 4);
  248. RegCloseKey(hkTips);
  249. }
  250. }
  251. RegCloseKey(hkCheckCD);
  252. }
  253. RegisterMe( );
  254. return TRUE;
  255. }
  256. int _stdcall ModuleEntry(void)
  257. {
  258. int i;
  259. STARTUPINFO si;
  260. LPSTR pszCmdLine = GetCommandLine();
  261. if ( *pszCmdLine == '\"' ) {
  262. /*
  263. * Scan, and skip over, subsequent characters until
  264. * another double-quote or a null is encountered.
  265. */
  266. while ( *++pszCmdLine && (*pszCmdLine != '\"') )
  267. ;
  268. /*
  269. * If we stopped on a double-quote (usual case), skip
  270. * over it.
  271. */
  272. if ( *pszCmdLine == '\"' )
  273. pszCmdLine++;
  274. }
  275. else {
  276. while (*pszCmdLine > ' ')
  277. pszCmdLine++;
  278. }
  279. /*
  280. * Skip past any white space preceeding the second token.
  281. */
  282. while (*pszCmdLine && (*pszCmdLine <= ' ')) {
  283. pszCmdLine++;
  284. }
  285. si.dwFlags = 0;
  286. GetStartupInfoA(&si);
  287. i = WinMain(GetModuleHandle(NULL), NULL, pszCmdLine,
  288. si.dwFlags & STARTF_USESHOWWINDOW ? si.wShowWindow : SW_SHOWDEFAULT);
  289. ExitProcess(i);
  290. return i; // We never comes here.
  291. }