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.

122 lines
2.9 KiB

  1. //
  2. // This code obtained from KennT 2-June-1999
  3. //
  4. #include "precomp.h"
  5. #pragma hdrstop
  6. // Use the C macros for simpler coding
  7. #define COBJMACROS
  8. #include "remras.h"
  9. #include <objbase.h>
  10. // {1AA7F844-C7F5-11d0-A376-00C04FC9DA04}
  11. const GUID CLSID_RemoteRouterConfig
  12. = { 0x1aa7f844, 0xc7f5, 0x11d0, { 0xa3, 0x76, 0x0, 0xc0, 0x4f, 0xc9, 0xda, 0x4 } };
  13. // {66A2DB1b-D706-11d0-A37B-00C04FC9DA04}
  14. const GUID IID_IRemoteNetworkConfig =
  15. { 0x66a2db1b, 0xd706, 0x11d0, { 0xa3, 0x7b, 0x0, 0xc0, 0x4f, 0xc9, 0xda, 0x4 } };
  16. HRESULT CoCreateRouterConfig(LPCTSTR pszMachine,
  17. REFIID riid,
  18. IUnknown **ppUnk);
  19. HRESULT RouterReset(LPCTSTR pszMachineName);
  20. #ifdef STANDALONE
  21. void main(int argc, char *argv[])
  22. {
  23. LPCTSTR pszMachineName = NULL;
  24. HRESULT hr;
  25. if (argc > 1)
  26. pszMachineName = argv[1];
  27. hr = RouterReset(pszMachineName);
  28. printf("hr=%d\n", hr);
  29. }
  30. #endif
  31. HRESULT RouterReset(LPCTSTR pszMachineName)
  32. {
  33. IRemoteNetworkConfig * pNetwork = NULL;
  34. HRESULT hr = S_OK;
  35. // CoInitialize unless it's already been done
  36. // ----------------------------------------------------------------
  37. if (CoInitialize(NULL) == S_OK)
  38. {
  39. // Create the router configuration object
  40. // ------------------------------------------------------------
  41. hr = CoCreateRouterConfig(pszMachineName,
  42. &IID_IRemoteNetworkConfig,
  43. (IUnknown **) &pNetwork);
  44. if (hr == S_OK)
  45. {
  46. // Ok we succeeded in creating the object, now let's
  47. // have it do the upgrade.
  48. // --------------------------------------------------------
  49. IRemoteNetworkConfig_UpgradeRouterConfig(pNetwork);
  50. IRemoteNetworkConfig_Release(pNetwork);
  51. pNetwork = NULL;
  52. }
  53. CoUninitialize();
  54. }
  55. return hr;
  56. }
  57. /*!--------------------------------------------------------------------------
  58. CoCreateRouterConfig
  59. -
  60. Author: KennT
  61. ---------------------------------------------------------------------------*/
  62. HRESULT CoCreateRouterConfig(LPCTSTR pszMachine,
  63. REFIID riid,
  64. IUnknown **ppUnk)
  65. {
  66. HRESULT hr = S_OK;
  67. MULTI_QI qi;
  68. *ppUnk = NULL;
  69. if ((pszMachine == NULL) || (*pszMachine == 0))
  70. {
  71. // Hmmm.. this points to a security hole, can anyone
  72. // create this object? I need to check for the proper
  73. // access rights.
  74. // ------------------------------------------------------------
  75. hr = CoCreateInstance(&CLSID_RemoteRouterConfig,
  76. NULL,
  77. CLSCTX_SERVER,
  78. riid,
  79. (LPVOID *) &(qi.pItf));
  80. }
  81. else
  82. {
  83. qi.pIID = riid;
  84. qi.pItf = NULL;
  85. qi.hr = 0;
  86. hr = CoCreateInstanceEx(&CLSID_RemoteRouterConfig,
  87. NULL,
  88. CLSCTX_SERVER,
  89. NULL,
  90. 1,
  91. &qi);
  92. }
  93. if (hr == S_OK)
  94. {
  95. *ppUnk = qi.pItf;
  96. qi.pItf = NULL;
  97. }
  98. return hr;
  99. }