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.

308 lines
7.8 KiB

  1. /* File: D:\WACKER\tdll\telnetck.c (Created: 26-Nov-1996 by cab)
  2. *
  3. * Copyright 1996 by Hilgraeve Inc. -- Monroe, MI
  4. * All rights reserved
  5. *
  6. * Description:
  7. * Implements the functions used to implement "telnet checking".
  8. * This is HyperTerminal's way of assuring that it is the
  9. * default telnet app for Internet Explorer and Netscape Navigator.
  10. *
  11. * $Revision: 5 $
  12. * $Date: 5/15/02 4:37p $
  13. */
  14. #include <windows.h>
  15. #pragma hdrstop
  16. #include "features.h"
  17. #ifdef INCL_DEFAULT_TELNET_APP
  18. #include "assert.h"
  19. #include "stdtyp.h"
  20. #include "globals.h"
  21. #include "htchar.h"
  22. #include "registry.h"
  23. #include "hlptable.h"
  24. // Control IDs for the dialog:
  25. //
  26. #define IDC_PB_YES IDOK
  27. #define IDC_PB_NO IDCANCEL
  28. #define IDC_CK_STOP_ASKING 200
  29. #define IDC_ST_QUESTION 201
  30. #define IDC_IC_EXCLAMATION 202
  31. // Registry key for HyperTerminal:
  32. //
  33. #ifndef NT_EDITION
  34. static const TCHAR g_achHyperTerminalRegKey[] =
  35. TEXT("SOFTWARE\\Hilgraeve Inc\\HyperTerminal PE\\3.0");
  36. #else
  37. static const TCHAR g_achHyperTerminalRegKey[] =
  38. TEXT("SOFTWARE\\Microsoft\\HyperTerminal");
  39. #endif
  40. // Registry value for telnet checking:
  41. //
  42. static const TCHAR g_achTelnetCheck[] = TEXT("Telnet Check");
  43. // Registry keys for the web browsers:
  44. //
  45. static const TCHAR g_achIERegKey[] =
  46. TEXT("SOFTWARE\\Classes\\telnet\\shell\\open\\command");
  47. static const TCHAR g_achNetscapeRegKey[] =
  48. TEXT("SOFTWARE\\Netscape\\Netscape Navigator\\Viewers");
  49. // Registry values for the browser telnet apps:
  50. //
  51. static const TCHAR g_achIERegValue[] = TEXT("");
  52. static const TCHAR g_achNetscapeRegValue[] = TEXT("telnet");
  53. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  54. * FUNCTION:
  55. * IsHyperTerminalDefaultTelnetApp
  56. *
  57. * DESCRIPTION:
  58. * Determines if HyperTerminal is the default telnet app for Internet
  59. * Explorer and Netscape Navigator.
  60. *
  61. * PARAMETERS:
  62. * None
  63. *
  64. * RETURNS:
  65. * TRUE or FALSE
  66. *
  67. * AUTHOR: C. Baumgartner, 11/26/96
  68. */
  69. BOOL IsHyperTerminalDefaultTelnetApp(void)
  70. {
  71. TCHAR acExePath[MAX_PATH];
  72. TCHAR acRegistryData[MAX_PATH * 2];
  73. long lRet = 0;
  74. DWORD dwSize = sizeof(acRegistryData);
  75. // Get the path name of HyperTerminal.
  76. //
  77. acExePath[0] = TEXT('\0');
  78. GetModuleFileName(glblQueryHinst(), acExePath, MAX_PATH);
  79. // Get IE's default telnet app.
  80. //
  81. acRegistryData[0] = TEXT('\0');
  82. if ( htRegQueryValue(HKEY_LOCAL_MACHINE, g_achIERegKey,
  83. g_achIERegValue, acRegistryData, &dwSize) == 0 )
  84. {
  85. if ( StrCharStrStr(acRegistryData, acExePath) == NULL )
  86. {
  87. return FALSE;
  88. }
  89. }
  90. // Get Netscape's default telnet app.
  91. //
  92. acRegistryData[0] = TEXT('\0');
  93. if ( htRegQueryValue(HKEY_CURRENT_USER, g_achNetscapeRegKey,
  94. g_achNetscapeRegValue, acRegistryData, &dwSize) == 0 )
  95. {
  96. if ( StrCharStrStr(acRegistryData, acExePath) == NULL )
  97. {
  98. return FALSE;
  99. }
  100. }
  101. return TRUE;
  102. }
  103. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  104. * FUNCTION:
  105. * QueryTelnetCheckFlag
  106. *
  107. * DESCRIPTION:
  108. * Returns the value of the "telnet checking" flag. If this is TRUE,
  109. * the app should check whether it is the default telnet app for IE
  110. * and Netscape. If it isn't the default telnet app, then display
  111. * the "Default Telnet App" dialog. The user can disable "telnet
  112. * checking" by checking the "Stop asking me this question" box.
  113. *
  114. * PARAMETERS:
  115. * None
  116. *
  117. * RETURNS:
  118. * TRUE or FALSE
  119. *
  120. * AUTHOR: C. Baumgartner, 11/26/96
  121. */
  122. BOOL QueryTelnetCheckFlag(void)
  123. {
  124. DWORD dwTelnetCheck = TRUE;
  125. DWORD dwSize = sizeof(dwTelnetCheck);
  126. if ( htRegQueryValue(HKEY_CURRENT_USER, g_achHyperTerminalRegKey,
  127. g_achTelnetCheck, (LPBYTE) &dwTelnetCheck, &dwSize) == 0 )
  128. {
  129. return dwTelnetCheck;
  130. }
  131. return TRUE;
  132. }
  133. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  134. * FUNCTION:
  135. * SetTelnetCheckFlag
  136. *
  137. * DESCRIPTION:
  138. * Sets the "telnet checking" flag which will either turn on or off
  139. * this feature the next time HyperTerminal starts.
  140. *
  141. * PARAMETERS:
  142. * fCheck - Check if HyperTerminal is the default telnet app?
  143. *
  144. * RETURNS:
  145. * 0 if successful, -1 if error
  146. *
  147. * AUTHOR: C. Baumgartner, 11/27/96
  148. */
  149. int SetTelnetCheckFlag(BOOL fCheck)
  150. {
  151. int iRet = 0;
  152. if ( regSetDwordValue(HKEY_CURRENT_USER, g_achHyperTerminalRegKey,
  153. g_achTelnetCheck, (DWORD)fCheck) != 0 )
  154. {
  155. iRet = -1;
  156. }
  157. return iRet;
  158. }
  159. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  160. * FUNCTION:
  161. * SetDefaultTelnetApp
  162. *
  163. * DESCRIPTION:
  164. * Sets the default telnet application for IE and Netscape to HyperTerminal.
  165. *
  166. * PARAMETERS:
  167. * None
  168. *
  169. * RETURNS:
  170. * 0 if successful, -1 if error
  171. *
  172. * AUTHOR: C. Baumgartner, 11/27/96
  173. */
  174. int SetDefaultTelnetApp(void)
  175. {
  176. int iRet = 0;
  177. TCHAR acExePath[MAX_PATH];
  178. TCHAR acRegistryData[MAX_PATH * 2];
  179. // Get the path name of HyperTerminal.
  180. //
  181. acExePath[0] = TEXT('\0');
  182. GetModuleFileName(glblQueryHinst(), acExePath, MAX_PATH);
  183. // Create the Netscape telnet command string.
  184. //
  185. acRegistryData[0] = TEXT('\0');
  186. wsprintf(acRegistryData, "%s /t", acExePath);
  187. // Write it to the registry.
  188. //
  189. if ( regSetStringValue(HKEY_CURRENT_USER, g_achNetscapeRegKey,
  190. g_achNetscapeRegValue, acRegistryData) != 0 )
  191. {
  192. // Just set the return flag to mark that we failed.
  193. //
  194. iRet = -1;
  195. }
  196. // Create the IE telnet command string.
  197. //
  198. acRegistryData[0] = TEXT('\0');
  199. wsprintf(acRegistryData, "%s /t %%1", acExePath);
  200. // Write it to the registry.
  201. //
  202. if ( regSetStringValue(HKEY_LOCAL_MACHINE, g_achIERegKey, g_achIERegValue,
  203. acRegistryData) != 0 )
  204. {
  205. // Just set the return flag to mark that we failed.
  206. //
  207. iRet = -1;
  208. }
  209. return iRet;
  210. }
  211. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  212. * FUNCTION:
  213. * DefaultTelnetAppDlgProc
  214. *
  215. * DESCRIPTION:
  216. * The dialog procedure for the "Default Telnet App" dialog.
  217. * This dialog asks the user if he/she wants HyperTerminal
  218. * to be the default telnet app for IE and NN. There also is
  219. * a check box to disable this potentially annoying feature.
  220. *
  221. * PARAMETERS:
  222. * hDlg - The dialog's window handle.
  223. * wMsg - The message being sent to the window.
  224. * wPar - The message's wParam.
  225. * lPar - The message's lParam.
  226. *
  227. * RETURNS:
  228. * TRUE or FALSE
  229. *
  230. * AUTHOR: C. Baumgartner, 11/26/96
  231. */
  232. INT_PTR CALLBACK DefaultTelnetAppDlgProc(HWND hDlg, UINT wMsg,
  233. WPARAM wPar, LPARAM lPar)
  234. {
  235. static DWORD aHlpTable[] = {IDC_CK_STOP_ASKING, IDH_TELNETCK_STOP_ASKING,
  236. IDC_PB_YES, IDH_TELNETCK_YES,
  237. IDC_PB_NO, IDH_TELNETCK_NO,
  238. 0, 0};
  239. switch (wMsg)
  240. {
  241. case WM_DESTROY:
  242. // Check the value of the "Stop asking me" checkbox.
  243. //
  244. SetTelnetCheckFlag(!(IsDlgButtonChecked(hDlg, IDC_CK_STOP_ASKING) == BST_CHECKED));
  245. break;
  246. case WM_HELP:
  247. doContextHelp(aHlpTable, wPar, lPar, FALSE, FALSE);
  248. break;
  249. case WM_COMMAND:
  250. switch (wPar)
  251. {
  252. case IDC_PB_YES:
  253. SetDefaultTelnetApp();
  254. EndDialog(hDlg, TRUE);
  255. break;
  256. case IDC_PB_NO:
  257. EndDialog(hDlg, FALSE);
  258. break;
  259. default:
  260. return FALSE;
  261. }
  262. break;
  263. default:
  264. return FALSE;
  265. }
  266. return TRUE;
  267. }
  268. #endif