VirtualBox

Changeset 17811 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Mar 13, 2009 11:37:42 AM (16 years ago)
Author:
vboxsync
Message:

NetAdp/win: rename connection on install

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/win/NetIfList-win.cpp

    r17774 r17811  
    12161216
    12171217
    1218 #define NETSHELL_LIBRARY _T("netshell.dll")
    1219 
    1220 /**
    1221  *  Use the IShellFolder API to rename the connection.
    1222  */
    1223 static HRESULT rename_shellfolder (PCWSTR wGuid, PCWSTR wNewName)
    1224 {
    1225     /* This is the GUID for the network connections folder. It is constant.
    1226      * {7007ACC7-3202-11D1-AAD2-00805FC1270E} */
    1227     const GUID CLSID_NetworkConnections = {
    1228         0x7007ACC7, 0x3202, 0x11D1, {
    1229             0xAA, 0xD2, 0x00, 0x80, 0x5F, 0xC1, 0x27, 0x0E
    1230         }
    1231     };
    1232 
    1233     LPITEMIDLIST pidl = NULL;
    1234     IShellFolder *pShellFolder = NULL;
    1235     HRESULT hr;
    1236 
    1237     /* Build the display name in the form "::{GUID}". */
    1238     if (wcslen (wGuid) >= MAX_PATH)
    1239         return E_INVALIDARG;
    1240     WCHAR szAdapterGuid[MAX_PATH + 2] = {0};
    1241     swprintf (szAdapterGuid, L"::%ls", wGuid);
    1242 
    1243     /* Create an instance of the network connections folder. */
    1244     hr = CoCreateInstance (CLSID_NetworkConnections, NULL,
    1245                            CLSCTX_INPROC_SERVER, IID_IShellFolder,
    1246                            reinterpret_cast <LPVOID *> (&pShellFolder));
    1247     /* Parse the display name. */
    1248     if (SUCCEEDED (hr))
    1249     {
    1250         hr = pShellFolder->ParseDisplayName (NULL, NULL, szAdapterGuid, NULL,
    1251                                              &pidl, NULL);
    1252     }
    1253     if (SUCCEEDED (hr))
    1254     {
    1255         hr = pShellFolder->SetNameOf (NULL, pidl, wNewName, SHGDN_NORMAL,
    1256                                       &pidl);
    1257     }
    1258 
    1259     CoTaskMemFree (pidl);
    1260 
    1261     if (pShellFolder)
    1262         pShellFolder->Release();
    1263 
    1264     return hr;
    1265 }
    1266 
    1267 static HRESULT netIfRenameConnection (PCWSTR GuidString, PCWSTR NewName)
    1268 {
    1269     typedef HRESULT (WINAPI *lpHrRenameConnection) (const GUID *, PCWSTR);
    1270     lpHrRenameConnection RenameConnectionFunc = NULL;
    1271     HRESULT status;
    1272 
    1273     /* First try the IShellFolder interface, which was unimplemented
    1274      * for the network connections folder before XP. */
    1275     status = rename_shellfolder (GuidString, NewName);
    1276     if (status == E_NOTIMPL)
    1277     {
    1278 /** @todo that code doesn't seem to work! */
    1279         /* The IShellFolder interface is not implemented on this platform.
    1280          * Try the (undocumented) HrRenameConnection API in the netshell
    1281          * library. */
    1282         CLSID clsid;
    1283         HINSTANCE hNetShell;
    1284         status = CLSIDFromString ((LPOLESTR) GuidString, &clsid);
    1285         if (FAILED(status))
    1286             return E_FAIL;
    1287         hNetShell = LoadLibrary (NETSHELL_LIBRARY);
    1288         if (hNetShell == NULL)
    1289             return E_FAIL;
    1290         RenameConnectionFunc =
    1291           (lpHrRenameConnection) GetProcAddress (hNetShell,
    1292                                                  "HrRenameConnection");
    1293         if (RenameConnectionFunc == NULL)
    1294         {
    1295             FreeLibrary (hNetShell);
    1296             return E_FAIL;
    1297         }
    1298         status = RenameConnectionFunc (&clsid, NewName);
    1299         FreeLibrary (hNetShell);
    1300     }
    1301     if (FAILED (status))
    1302         return status;
    1303 
    1304     return S_OK;
    1305 }
    1306 #define VBOX_CONNECTION_NAME L"Virtualbox Host-Only Network"
    1307 static HRESULT netIfGenConnectionName (PCWSTR DevName, WCHAR *pBuf, PULONG pcbBuf)
    1308 {
    1309     const WCHAR * pSuffix = wcsrchr( DevName, L'#' );
    1310     ULONG cbSize = sizeof(VBOX_CONNECTION_NAME);
    1311     ULONG cbSufSize = 0;
    1312 
    1313     if(pSuffix)
    1314     {
    1315         cbSize += (ULONG)wcslen(pSuffix) * 2;
    1316     }
    1317 
    1318     if(*pcbBuf < cbSize)
    1319     {
    1320         *pcbBuf = cbSize;
    1321         return E_FAIL;
    1322     }
    1323 
    1324     wcscpy(pBuf, VBOX_CONNECTION_NAME);
    1325     if(pSuffix)
    1326     {
    1327         wcscat(pBuf, pSuffix);
    1328     }
    1329 
    1330     return S_OK;
    1331 }
    1332 
    13331218#define DRIVERHWID _T("sun_VBoxNetAdp")
    13341219
     
    16351520                    ULONG cbBuf = sizeof(ConnectoinName);
    16361521
    1637                     /* return back the bracket */
    1638                     pCfgGuidString [_tcslen (pCfgGuidString)] = '}';
    1639 
    1640                     hr = netIfGenConnectionName (name, ConnectoinName, &cbBuf);
     1522                    hr = VBoxNetCfgWinGenHostonlyConnectionName (name, ConnectoinName, &cbBuf);
    16411523                    if(hr == S_OK)
    16421524                    {
    1643                         hr = netIfRenameConnection (pCfgGuidString, ConnectoinName);
     1525                        hr = VBoxNetCfgWinRenameConnection ((GUID*)aGUID.raw(), ConnectoinName);
    16441526                    }
    16451527
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette