Changeset 41008 in vbox for trunk/src/VBox/HostDrivers/VBoxNetFlt
- Timestamp:
- Apr 20, 2012 1:15:17 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetAdpInstall.cpp
r40993 r41008 22 22 #include <devguid.h> 23 23 24 #define VBOX_NETADP_INF L".\\VBoxNetAdp.inf" 25 26 static VOID winNetCfgLogger (LPCSTR szString) 27 { 28 printf("%s", szString); 29 } 30 31 static int VBoxNetAdpInstall() 32 { 33 int r = 1; 34 VBoxNetCfgWinSetLogging(winNetCfgLogger); 35 36 HRESULT hr = CoInitialize(NULL); 37 if(hr == S_OK) 38 { 39 #if 0 //ndef DEBUG_misha 40 printf("not implemented yet, please use device manager for Host-Only net interface installation.. sorry :( \n"); 41 #else 42 GUID guid; 43 BSTR name, errMsg; 24 #define VBOX_NETADP_INF L"VBoxNetAdp.inf" 25 26 static VOID winNetCfgLogger(LPCSTR szString) 27 { 28 printf("%s\n", szString); 29 } 30 31 static int VBoxNetAdpInstall(void) 32 { 33 VBoxNetCfgWinSetLogging(winNetCfgLogger); 34 35 HRESULT hr = CoInitialize(NULL); 36 if (SUCCEEDED(hr)) 37 { 44 38 printf("adding host-only interface..\n"); 45 DWORD WinEr; 39 40 DWORD dwErr = ERROR_SUCCESS; 46 41 WCHAR MpInf[MAX_PATH]; 47 GetFullPathNameW(VBOX_NETADP_INF, sizeof(MpInf)/sizeof(MpInf[0]), MpInf, NULL); 48 WinEr = GetLastError(); 49 if(WinEr == ERROR_SUCCESS) 50 { 42 43 if (!GetFullPathNameW(VBOX_NETADP_INF, sizeof(MpInf)/sizeof(MpInf[0]), MpInf, NULL)) 44 dwErr = GetLastError(); 45 46 if (dwErr == ERROR_SUCCESS) 47 { 48 GUID guid; 49 BSTR name, errMsg; 50 51 51 hr = VBoxNetCfgWinCreateHostOnlyNetworkInterface (MpInf, true, &guid, &name, &errMsg); 52 if (hr == S_OK)52 if (SUCCEEDED(hr)) 53 53 { 54 54 ULONG ip, mask; 55 55 hr = VBoxNetCfgWinGenHostOnlyNetworkNetworkIp(&ip, &mask); 56 if (hr == S_OK)56 if (SUCCEEDED(hr)) 57 57 { 58 58 /* ip returned by VBoxNetCfgWinGenHostOnlyNetworkNetworkIp is a network ip, … … 60 60 ip = ip | (1 << 24); 61 61 hr = VBoxNetCfgWinEnableStaticIpConfig(&guid, ip, mask); 62 if (hr != S_OK)62 if (SUCCEEDED(hr)) 63 63 { 64 printf(" VBoxNetCfgWinEnableStaticIpConfig failed: hr = 0x%x\n", hr);64 printf("installation successful\n"); 65 65 } 66 66 else 67 { 68 r = 0; 69 } 67 printf("VBoxNetCfgWinEnableStaticIpConfig failed: hr = 0x%x\n", hr); 70 68 } 71 69 else 72 {73 70 printf("VBoxNetCfgWinGenHostOnlyNetworkNetworkIp failed: hr = 0x%x\n", hr); 74 }75 71 } 76 72 else 73 printf("VBoxNetCfgWinCreateHostOnlyNetworkInterface failed: hr = 0x%x\n", hr); 74 } 75 else 76 { 77 printf("GetFullPathNameW failed: winEr = %d\n", dwErr); 78 hr = HRESULT_FROM_WIN32(dwErr); 79 80 } 81 CoUninitialize(); 82 } 83 else 84 printf("Error initializing COM (0x%x)\n", hr); 85 86 VBoxNetCfgWinSetLogging(NULL); 87 88 return SUCCEEDED(hr) ? 0 : 1; 89 } 90 91 static int VBoxNetAdpUninstall(void) 92 { 93 VBoxNetCfgWinSetLogging(winNetCfgLogger); 94 95 printf("uninstalling all host-only interfaces..\n"); 96 97 HRESULT hr = CoInitialize(NULL); 98 if (SUCCEEDED(hr)) 99 { 100 hr = VBoxNetCfgWinRemoveAllNetDevicesOfId(L"sun_VBoxNetAdp"); 101 if (SUCCEEDED(hr)) 102 { 103 hr = VBoxDrvCfgInfUninstallAllSetupDi(&GUID_DEVCLASS_NET, L"Net", L"sun_VBoxNetAdp", 0/* could be SUOI_FORCEDELETE */); 104 if (SUCCEEDED(hr)) 77 105 { 78 printf("VBoxNetCfgWinCreateHostOnlyNetworkInterface failed: hr = 0x%x\n", hr); 79 } 80 } 81 else 82 { 83 printf("GetFullPathNameW failed: winEr = %d\n", WinEr); 84 } 85 #endif 86 87 CoUninitialize(); 88 } 89 else 90 { 91 wprintf(L"Error initializing COM (0x%x)\n", hr); 92 } 93 94 VBoxNetCfgWinSetLogging(NULL); 95 96 return r; 97 } 98 99 static int VBoxNetAdpUninstall() 100 { 101 int r = 1; 102 VBoxNetCfgWinSetLogging(winNetCfgLogger); 103 104 printf("uninstalling all Host-Only interfaces..\n"); 105 106 HRESULT hr = CoInitialize(NULL); 107 if(hr == S_OK) 108 { 109 hr = VBoxNetCfgWinRemoveAllNetDevicesOfId(L"sun_VBoxNetAdp"); 110 if(hr == S_OK) 111 { 112 hr = VBoxDrvCfgInfUninstallAllSetupDi(&GUID_DEVCLASS_NET, L"Net", L"sun_VBoxNetAdp", 0/* could be SUOI_FORCEDELETE */); 113 if(hr == S_OK) 114 { 115 printf("uninstalled successfully\n"); 106 printf("uninstallation successful\n"); 116 107 } 117 108 else 118 {119 109 printf("uninstalled successfully, but failed to remove infs\n"); 120 } 121 r = 0; 122 } 123 else 124 { 110 } 111 else 125 112 printf("uninstall failed, hr = 0x%x\n", hr); 126 } 127 128 CoUninitialize(); 129 } 130 else 131 { 132 wprintf(L"Error initializing COM (0x%x)\n", hr); 133 } 134 135 VBoxNetCfgWinSetLogging(NULL); 136 137 return r; 138 } 139 140 static int VBoxNetAdpUpdate() 141 { 142 int r = 1; 143 VBoxNetCfgWinSetLogging(winNetCfgLogger); 144 145 printf("uninstalling all Host-Only interfaces..\n"); 146 147 HRESULT hr = CoInitialize(NULL); 148 if(hr == S_OK) 113 CoUninitialize(); 114 } 115 else 116 printf("Error initializing COM (0x%x)\n", hr); 117 118 VBoxNetCfgWinSetLogging(NULL); 119 120 return SUCCEEDED(hr) ? 0 : 1; 121 } 122 123 static int VBoxNetAdpUpdate(void) 124 { 125 VBoxNetCfgWinSetLogging(winNetCfgLogger); 126 127 printf("uninstalling all host-only interfaces..\n"); 128 129 HRESULT hr = CoInitialize(NULL); 130 if (SUCCEEDED(hr)) 149 131 { 150 132 BOOL fRebootRequired = FALSE; 151 133 hr = VBoxNetCfgWinUpdateHostOnlyNetworkInterface(VBOX_NETADP_INF, &fRebootRequired); 152 if (hr == S_OK)134 if (SUCCEEDED(hr)) 153 135 { 154 136 if (fRebootRequired) 155 137 printf("!!REBOOT REQUIRED!!\n"); 156 138 printf("updated successfully\n"); 157 r = 0; 158 } 159 else 160 { 139 } 140 else 161 141 printf("update failed, hr = 0x%x\n", hr); 162 } 163 164 CoUninitialize(); 165 } 166 else 167 { 168 wprintf(L"Error initializing COM (0x%x)\n", hr); 169 } 170 171 VBoxNetCfgWinSetLogging(NULL); 172 173 return r; 174 } 175 176 static int VBoxNetAdpDisable() 177 { 178 int r = 1; 179 VBoxNetCfgWinSetLogging(winNetCfgLogger); 180 181 printf("disabling all Host-Only interfaces..\n"); 182 183 HRESULT hr = CoInitialize(NULL); 184 if(hr == S_OK) 142 143 CoUninitialize(); 144 } 145 else 146 printf("Error initializing COM (0x%x)\n", hr); 147 148 VBoxNetCfgWinSetLogging(NULL); 149 150 return SUCCEEDED(hr) ? 0 : 1; 151 } 152 153 static int VBoxNetAdpDisable(void) 154 { 155 VBoxNetCfgWinSetLogging(winNetCfgLogger); 156 157 printf("disabling all host-only interfaces..\n"); 158 159 HRESULT hr = CoInitialize(NULL); 160 if (SUCCEEDED(hr)) 185 161 { 186 162 hr = VBoxNetCfgWinPropChangeAllNetDevicesOfId(L"sun_VBoxNetAdp", VBOXNECTFGWINPROPCHANGE_TYPE_DISABLE); 187 if(hr == S_OK) 188 { 189 printf("disable succeeded!\n"); 190 r = 0; 191 } 192 else 193 { 163 if (SUCCEEDED(hr)) 164 { 165 printf("disabling successful\n"); 166 } 167 else 194 168 printf("disable failed, hr = 0x%x\n", hr); 195 } 196 197 CoUninitialize(); 198 } 199 else 200 { 201 wprintf(L"Error initializing COM (0x%x)\n", hr); 202 } 203 204 VBoxNetCfgWinSetLogging(NULL); 205 206 return r; 207 } 208 209 static int VBoxNetAdpEnable() 210 { 211 int r = 1; 212 VBoxNetCfgWinSetLogging(winNetCfgLogger); 213 214 printf("enabling all Host-Only interfaces..\n"); 215 216 HRESULT hr = CoInitialize(NULL); 217 if(hr == S_OK) 169 170 CoUninitialize(); 171 } 172 else 173 printf("Error initializing COM (0x%x)\n", hr); 174 175 VBoxNetCfgWinSetLogging(NULL); 176 177 return SUCCEEDED(hr) ? 0 : 1; 178 } 179 180 static int VBoxNetAdpEnable(void) 181 { 182 VBoxNetCfgWinSetLogging(winNetCfgLogger); 183 184 printf("enabling all host-only interfaces..\n"); 185 186 HRESULT hr = CoInitialize(NULL); 187 if (SUCCEEDED(hr)) 218 188 { 219 189 hr = VBoxNetCfgWinPropChangeAllNetDevicesOfId(L"sun_VBoxNetAdp", VBOXNECTFGWINPROPCHANGE_TYPE_ENABLE); 220 if(hr == S_OK) 221 { 222 printf("disable succeeded!\n"); 223 r = 0; 224 } 225 else 226 { 227 printf("disable failed, hr = 0x%x\n", hr); 228 } 229 230 CoUninitialize(); 231 } 232 else 233 { 234 wprintf(L"Error initializing COM (0x%x)\n", hr); 235 } 236 237 VBoxNetCfgWinSetLogging(NULL); 238 239 return r; 240 } 241 242 static void printUsage() 243 { 244 printf("Host-Only network adapter configuration tool\n" 190 if (SUCCEEDED(hr)) 191 { 192 printf("enabling successful\n"); 193 } 194 else 195 printf("enabling failed, hr = 0x%x\n", hr); 196 197 CoUninitialize(); 198 } 199 else 200 printf("Error initializing COM (0x%x)\n", hr); 201 202 VBoxNetCfgWinSetLogging(NULL); 203 204 return SUCCEEDED(hr) ? 0 : 1; 205 } 206 207 static void printUsage(void) 208 { 209 printf("host-only network adapter configuration tool\n" 245 210 " Usage: VBoxNetAdpInstall [cmd]\n" 246 211 " cmd can be one of the following values:\n" … … 263 228 } 264 229 230 #if 0 265 231 __debugbreak(); 232 #endif 266 233 267 234 if (!strcmp(argv[1], "i"))
Note:
See TracChangeset
for help on using the changeset viewer.