VirtualBox

Ignore:
Timestamp:
Apr 19, 2012 2:25:38 PM (13 years ago)
Author:
vboxsync
Message:

NetCfg/win: disable/enable/update HostOnly

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetAdpInstall.cpp

    r36184 r40993  
    1717
    1818#include <VBox/VBoxNetCfg-win.h>
     19#include <VBox/VBoxDrvCfg-win.h>
    1920#include <stdio.h>
     21
     22#include <devguid.h>
    2023
    2124#define VBOX_NETADP_INF L".\\VBoxNetAdp.inf"
     
    9497}
    9598
     99static 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");
     116            }
     117            else
     118            {
     119                printf("uninstalled successfully, but failed to remove infs\n");
     120            }
     121            r = 0;
     122        }
     123        else
     124        {
     125            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
     140static 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)
     149    {
     150        BOOL fRebootRequired = FALSE;
     151        hr = VBoxNetCfgWinUpdateHostOnlyNetworkInterface(VBOX_NETADP_INF, &fRebootRequired);
     152        if(hr == S_OK)
     153        {
     154            if (fRebootRequired)
     155                printf("!!REBOOT REQUIRED!!\n");
     156            printf("updated successfully\n");
     157            r = 0;
     158        }
     159        else
     160        {
     161            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
     176static 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)
     185    {
     186        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        {
     194            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
     209static 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)
     218    {
     219        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
     242static void printUsage()
     243{
     244    printf("Host-Only network adapter configuration tool\n"
     245            "  Usage: VBoxNetAdpInstall [cmd]\n"
     246            "    cmd can be one of the following values:\n"
     247            "       i  - install a new host-only interface\n"
     248            "       u  - uninstall all host-only interfaces\n"
     249            "       a  - update the host-only driver\n"
     250            "       d  - disable all host-only interfaces\n"
     251            "       e  - enable all host-only interfaces\n"
     252            "       h  - print this message\n");
     253}
     254
    96255int __cdecl main(int argc, char **argv)
    97256{
    98     return VBoxNetAdpInstall();
    99 }
     257    if (argc < 2)
     258        return VBoxNetAdpInstall();
     259    if (argc > 2)
     260    {
     261        printUsage();
     262        return 1;
     263    }
     264
     265    __debugbreak();
     266
     267    if (!strcmp(argv[1], "i"))
     268        return VBoxNetAdpInstall();
     269    if (!strcmp(argv[1], "u"))
     270        return VBoxNetAdpUninstall();
     271    if (!strcmp(argv[1], "a"))
     272        return VBoxNetAdpUpdate();
     273    if (!strcmp(argv[1], "d"))
     274        return VBoxNetAdpDisable();
     275    if (!strcmp(argv[1], "e"))
     276        return VBoxNetAdpEnable();
     277
     278    printUsage();
     279    return !strcmp(argv[1], "h");
     280}
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