Source code of Windows XP (NT5)
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.

139 lines
3.2 KiB

  1. //
  2. // NetCli.cpp
  3. //
  4. // Code to install, uninstall, and bind clients such as Client for
  5. // Microsoft Networks (VREDIR).
  6. //
  7. // History:
  8. //
  9. // 2/02/1999 KenSh Created for JetNet
  10. // 9/29/1999 KenSh Repurposed for Home Networking Wizard
  11. //
  12. #include "stdafx.h"
  13. #include "NetConn.h"
  14. #include "nconnwrap.h"
  15. #include "TheApp.h"
  16. #include "ParseInf.h"
  17. #include "HookUI.h"
  18. // IsClientInstalled
  19. //
  20. // Returns TRUE if the given client (e.g. "VREDIR") is currently installed.
  21. //
  22. BOOL WINAPI IsClientInstalled(LPCSTR pszClientDeviceID, BOOL bExhaustive)
  23. {
  24. BOOL bResult = FALSE;
  25. TCHAR szRegKey[50];
  26. wsprintf(szRegKey, "Enum\\Network\\%s", pszClientDeviceID);
  27. CRegistry reg;
  28. if (reg.OpenKey(HKEY_LOCAL_MACHINE, szRegKey, KEY_READ))
  29. {
  30. DWORD cSubKeys;
  31. if (ERROR_SUCCESS == RegQueryInfoKey(reg.m_hKey, NULL, NULL, NULL, &cSubKeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL))
  32. {
  33. if (cSubKeys != 0)
  34. bResult = TRUE;
  35. }
  36. }
  37. if (bResult && bExhaustive)
  38. {
  39. TCHAR szInfSection[50];
  40. wsprintf(szInfSection, "%s.Install", pszClientDeviceID);
  41. if (!CheckInfSectionInstallation("netcli.inf", szInfSection))
  42. bResult = FALSE;
  43. }
  44. return bResult;
  45. }
  46. BOOL WINAPI IsMSClientInstalled(BOOL bExhaustive)
  47. {
  48. if (!FindValidNetEnumKey(SZ_CLASS_CLIENT, SZ_CLIENT_MICROSOFT, NULL, 0))
  49. return FALSE;
  50. if (bExhaustive)
  51. {
  52. if (!CheckInfSectionInstallation("netcli.inf", "VREDIR.Install"))
  53. return FALSE;
  54. }
  55. return TRUE;
  56. }
  57. // Installs Client for Microsoft Networking, or fixes a broken installation
  58. HRESULT WINAPI InstallMSClient(HWND hwndParent, PROGRESS_CALLBACK pfnProgress, LPVOID pvProgressParam)
  59. {
  60. HRESULT hr = NETCONN_SUCCESS;
  61. // Remove any broken bindings
  62. RemoveBrokenNetItems(SZ_CLASS_CLIENT, SZ_CLIENT_MICROSOFT);
  63. if (IsMSClientInstalled(FALSE))
  64. {
  65. // Client is set up in registry, but check for missing files
  66. if (!CheckInfSectionInstallation("netcli.inf", "VREDIR.Install"))
  67. {
  68. if (InstallInfSection("netcli.inf", "VREDIR.Install", TRUE))
  69. {
  70. hr = NETCONN_NEED_RESTART;
  71. }
  72. }
  73. }
  74. else
  75. {
  76. BeginSuppressNetdiUI(hwndParent, pfnProgress, pvProgressParam);
  77. DWORD dwResult = CallClassInstaller16(hwndParent, SZ_CLASS_CLIENT, SZ_CLIENT_MICROSOFT);
  78. EndSuppressNetdiUI();
  79. hr = HresultFromCCI(dwResult);
  80. if (g_bUserAbort)
  81. {
  82. hr = NETCONN_USER_ABORT;
  83. }
  84. else if (SUCCEEDED(hr))
  85. {
  86. hr = NETCONN_NEED_RESTART;
  87. }
  88. }
  89. return hr;
  90. }
  91. // pszServiceBinding contains a service to list in the new client's Bindings subkey
  92. // pszBuf is filled with the new binding's enum key, e.g. "VREDIR\0001"
  93. HRESULT CreateNewClientForMSNet(LPSTR pszBuf, int cchBuf, LPCSTR pszServiceBinding)
  94. {
  95. HRESULT hr;
  96. if (FAILED(hr = FindAndCloneNetEnumKey(SZ_CLASS_CLIENT, SZ_CLIENT_MICROSOFT, pszBuf, cchBuf)))
  97. {
  98. ASSERT(FALSE);
  99. return hr;
  100. }
  101. // Now pszBuf contains a string of the form "VREDIR\0001"
  102. CRegistry regBindings;
  103. TCHAR szBindingsKey[200];
  104. wsprintf(szBindingsKey, "Enum\\Network\\%s\\Bindings", pszBuf);
  105. if (!regBindings.CreateKey(HKEY_LOCAL_MACHINE, szBindingsKey, KEY_ALL_ACCESS))
  106. {
  107. ASSERT(FALSE);
  108. return NETCONN_UNKNOWN_ERROR;
  109. }
  110. // Delete existing bindings
  111. regBindings.DeleteAllValues();
  112. // Add the service binding
  113. if (pszServiceBinding != NULL && *pszServiceBinding != '\0')
  114. regBindings.SetStringValue(pszServiceBinding, "");
  115. return NETCONN_SUCCESS;
  116. }