VirtualBox

Ignore:
Timestamp:
Sep 1, 2022 8:36:22 PM (2 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
153448
Message:

HostDrives,Installer/win: Reworked the windows installer related code for no-CRT mode, where applicable, and changed the XxxxInstall.exe/XxxxUninstall.exe utilities to link against VBoxRT.dll instead of being statically linked. Lot's of cleanup. The change is uncomfortably large, but difficult to detangle these things. bugref:10261

Location:
trunk/src/VBox/HostDrivers/VBoxNetFlt/win/tools
Files:
6 edited

Legend:

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

    r96407 r96572  
    4141#include <VBox/VBoxNetCfg-win.h>
    4242#include <VBox/VBoxDrvCfg-win.h>
    43 #include <stdio.h>
    4443#include <devguid.h>
     44
     45#include <iprt/initterm.h>
     46#include <iprt/message.h>
     47#include <iprt/process.h>
     48#include <iprt/stream.h>
    4549
    4650
     
    6064static DECLCALLBACK(void) winNetCfgLogger(const char *pszString)
    6165{
    62     printf("%s\n", pszString);
     66    RTMsgInfo("%s", pszString);
    6367}
    6468
     
    109113static int VBoxNetAdpInstall(void)
    110114{
    111     VBoxNetCfgWinSetLogging(winNetCfgLogger);
    112 
    113     HRESULT hr = CoInitialize(NULL);
    114     if (SUCCEEDED(hr))
    115     {
    116         wprintf(L"adding host-only interface..\n");
    117 
     115    RTMsgInfo("Adding host-only interface...");
     116    VBoxNetCfgWinSetLogging(winNetCfgLogger);
     117
     118    HRESULT hr = CoInitialize(NULL);
     119    if (SUCCEEDED(hr))
     120    {
    118121        WCHAR wszInfFile[MAX_PATH];
    119122        DWORD cwcInfFile = MyGetfullPathNameW(VBOX_NETADP_INF, RT_ELEMENTS(wszInfFile), wszInfFile);
     
    129132
    130133                if (hr == S_OK)
    131                     wprintf(L"installed successfully\n");
     134                    RTMsgInfo("Installed successfully!");
    132135                else
    133                     wprintf(L"error installing VBoxNetAdp (%#lx)\n", hr);
     136                    RTMsgError("failed to install VBoxNetAdp: %Rhrc", hr);
    134137
    135138                VBoxNetCfgWinReleaseINetCfg(pnc, TRUE);
    136139            }
    137140            else
    138                 wprintf(L"VBoxNetCfgWinQueryINetCfg failed: hr=%#lx\n", hr);
     141                RTMsgError("VBoxNetCfgWinQueryINetCfg failed: %Rhrc", hr);
    139142            /*
    140143            hr = VBoxDrvCfgInfInstall(MpInf);
     
    171174        {
    172175            DWORD dwErr = GetLastError();
    173             wprintf(L"GetFullPathNameW failed: winEr = %lu\n", dwErr);
     176            RTMsgError("MyGetfullPathNameW failed: %Rwc", dwErr);
    174177            hr = HRESULT_FROM_WIN32(dwErr);
    175178        }
     
    177180    }
    178181    else
    179         wprintf(L"Error initializing COM (%#lx)\n", hr);
     182        RTMsgError("Failed initializing COM: %Rhrc", hr);
    180183
    181184    VBoxNetCfgWinSetLogging(NULL);
     
    186189static int VBoxNetAdpUninstall(void)
    187190{
    188     VBoxNetCfgWinSetLogging(winNetCfgLogger);
    189 
    190     printf("uninstalling all host-only interfaces..\n");
     191    RTMsgInfo("Uninstalling all host-only interfaces...");
     192    VBoxNetCfgWinSetLogging(winNetCfgLogger);
    191193
    192194    HRESULT hr = CoInitialize(NULL);
     
    198200            hr = VBoxDrvCfgInfUninstallAllSetupDi(&GUID_DEVCLASS_NET, L"Net", VBOX_NETADP_HWID, 0/* could be SUOI_FORCEDELETE */);
    199201            if (SUCCEEDED(hr))
    200                 printf("uninstallation successful\n");
     202                RTMsgInfo("Uninstallation successful!");
    201203            else
    202                 printf("uninstalled successfully, but failed to remove infs\n");
    203         }
    204         else
    205             printf("uninstall failed, hr=%#lx\n", hr);
    206         CoUninitialize();
    207     }
    208     else
    209         printf("Error initializing COM (%#lx)\n", hr);
     204                RTMsgWarning("uninstalled successfully, but failed to remove infs (%Rhrc)\n", hr);
     205        }
     206        else
     207            RTMsgError("uninstall failed: %Rhrc", hr);
     208        CoUninitialize();
     209    }
     210    else
     211        RTMsgError("Failed initializing COM: %Rhrc", hr);
    210212
    211213    VBoxNetCfgWinSetLogging(NULL);
     
    216218static int VBoxNetAdpUpdate(void)
    217219{
    218     VBoxNetCfgWinSetLogging(winNetCfgLogger);
    219 
    220     printf("uninstalling all host-only interfaces..\n");
     220    RTMsgInfo("Uninstalling all host-only interfaces...");
     221    VBoxNetCfgWinSetLogging(winNetCfgLogger);
    221222
    222223    HRESULT hr = CoInitialize(NULL);
     
    235236        {
    236237            if (fRebootRequired)
    237                 printf("!!REBOOT REQUIRED!!\n");
    238             printf("updated successfully\n");
    239         }
    240         else
    241             printf("update failed, hr=%#lx\n", hr);
    242 
    243         CoUninitialize();
    244     }
    245     else
    246         printf("Error initializing COM (%#lx)\n", hr);
     238                RTMsgWarning("!!REBOOT REQUIRED!!");
     239            RTMsgInfo("Updated successfully!");
     240        }
     241        else
     242            RTMsgError("update failed: %Rhrc", hr);
     243
     244        CoUninitialize();
     245    }
     246    else
     247        RTMsgError("Failed initializing COM: %Rhrc", hr);
    247248
    248249    VBoxNetCfgWinSetLogging(NULL);
     
    253254static int VBoxNetAdpDisable(void)
    254255{
    255     VBoxNetCfgWinSetLogging(winNetCfgLogger);
    256 
    257     printf("disabling all host-only interfaces..\n");
     256    RTMsgInfo("Disabling all host-only interfaces...");
     257    VBoxNetCfgWinSetLogging(winNetCfgLogger);
    258258
    259259    HRESULT hr = CoInitialize(NULL);
     
    262262        hr = VBoxNetCfgWinPropChangeAllNetDevicesOfId(VBOX_NETADP_HWID, VBOXNECTFGWINPROPCHANGE_TYPE_DISABLE);
    263263        if (SUCCEEDED(hr))
    264             printf("disabling successful\n");
    265         else
    266             printf("disable failed, hr=%#lx\n", hr);
    267 
    268         CoUninitialize();
    269     }
    270     else
    271         printf("Error initializing COM (%#lx)\n", hr);
     264            RTMsgInfo("Disabling successful");
     265        else
     266            RTMsgError("disable failed: %Rhrc", hr);
     267
     268        CoUninitialize();
     269    }
     270    else
     271        RTMsgError("Failed initializing COM: %Rhrc", hr);
    272272
    273273    VBoxNetCfgWinSetLogging(NULL);
     
    278278static int VBoxNetAdpEnable(void)
    279279{
    280     VBoxNetCfgWinSetLogging(winNetCfgLogger);
    281 
    282     printf("enabling all host-only interfaces..\n");
     280    RTMsgInfo("Enabling all host-only interfaces...");
     281    VBoxNetCfgWinSetLogging(winNetCfgLogger);
    283282
    284283    HRESULT hr = CoInitialize(NULL);
     
    287286        hr = VBoxNetCfgWinPropChangeAllNetDevicesOfId(VBOX_NETADP_HWID, VBOXNECTFGWINPROPCHANGE_TYPE_ENABLE);
    288287        if (SUCCEEDED(hr))
    289             printf("enabling successful\n");
    290         else
    291             printf("enabling failed, hr=%#lx\n", hr);
    292 
    293         CoUninitialize();
    294     }
    295     else
    296         printf("Error initializing COM (%#lx)\n", hr);
     288            RTMsgInfo("Enabling successful!");
     289        else
     290            RTMsgError("enabling failed: %hrc", hr);
     291
     292        CoUninitialize();
     293    }
     294    else
     295        RTMsgError("Failed initializing COM: %Rhrc", hr);
    297296
    298297    VBoxNetCfgWinSetLogging(NULL);
     
    303302static void printUsage(void)
    304303{
    305     printf("host-only network adapter configuration tool\n"
    306             "  Usage: VBoxNetAdpInstall [cmd]\n"
    307             "    cmd can be one of the following values:\n"
    308             "       i  - install a new host-only interface (default command)\n"
    309             "       u  - uninstall all host-only interfaces\n"
    310             "       a  - update the host-only driver\n"
    311             "       d  - disable all host-only interfaces\n"
    312             "       e  - enable all host-only interfaces\n"
    313             "       h  - print this message\n");
     304    RTPrintf("host-only network adapter configuration tool\n"
     305             "  Usage: %s [cmd]\n"
     306             "    cmd can be one of the following values:\n"
     307             "       i  - install a new host-only interface (default command)\n"
     308             "       u  - uninstall all host-only interfaces\n"
     309             "       a  - update the host-only driver\n"
     310             "       d  - disable all host-only interfaces\n"
     311             "       e  - enable all host-only interfaces\n"
     312             "       h  - print this message\n",
     313             RTProcShortName());
    314314}
    315315
    316316int __cdecl main(int argc, char **argv)
    317317{
     318    RTR3InitExe(argc, &argv, 0);
     319
    318320    if (argc < 2)
    319321        return VBoxNetAdpInstall();
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetAdpUninstall.cpp

    r96407 r96572  
    3535 */
    3636
     37
     38/*********************************************************************************************************************************
     39*   Header Files                                                                                                                 *
     40*********************************************************************************************************************************/
    3741#include <VBox/VBoxNetCfg-win.h>
    3842#include <VBox/VBoxDrvCfg-win.h>
    39 #include <stdio.h>
    4043
    4144#include <devguid.h>
    4245
     46#include <iprt/initterm.h>
     47#include <iprt/message.h>
     48
     49
     50/*********************************************************************************************************************************
     51*   Defined Constants And Macros                                                                                                 *
     52*********************************************************************************************************************************/
    4353#ifdef NDIS60
    4454# define VBOX_NETADP_HWID L"sun_VBoxNetAdp6"
     
    4757#endif
    4858
     59
    4960static DECLCALLBACK(void) winNetCfgLogger(const char *pszString)
    5061{
    51     printf("%s", pszString);
     62    RTMsgInfo("%s", pszString);
    5263}
    5364
    5465static int VBoxNetAdpUninstall(void)
    5566{
     67    RTMsgInfo("Uninstalling all Host-Only interfaces ...");
     68
    5669    int rcExit = RTEXITCODE_FAILURE;
    5770    VBoxNetCfgWinSetLogging(winNetCfgLogger);
    58 
    59     printf("uninstalling all Host-Only interfaces..\n");
    6071
    6172    HRESULT hr = CoInitialize(NULL);
     
    6778            hr = VBoxDrvCfgInfUninstallAllSetupDi(&GUID_DEVCLASS_NET, L"Net", VBOX_NETADP_HWID, 0/* could be SUOI_FORCEDELETE */);
    6879            if (hr == S_OK)
    69                 printf("uninstalled successfully\n");
     80                RTMsgInfo("Uninstalled successfully!");
    7081            else
    71                 printf("uninstalled successfully, but failed to remove infs\n");
     82                RTMsgError("uninstalled successfully, but failed to remove infs (%Rhrc)\n", hr);
    7283            rcExit = RTEXITCODE_SUCCESS;
    7384        }
    7485        else
    75             printf("uninstall failed, hr=%#lx\n", hr);
     86            RTMsgError("uninstall failed: %Rhrc", hr);
    7687
    7788        CoUninitialize();
    7889    }
    7990    else
    80         wprintf(L"Error initializing COM (%#lx)\n", hr);
     91        RTMsgError("Failed initializing COM: %Rhrc", hr);
    8192
    8293    VBoxNetCfgWinSetLogging(NULL);
     
    8798int __cdecl main(int argc, char **argv)
    8899{
    89     RT_NOREF2(argc, argv);
     100    RTR3InitExeNoArguments(0);
     101    if (argc != 1)
     102        return RTMsgErrorExit(RTEXITCODE_SYNTAX, "This utility takes no arguments\n");
     103    NOREF(argv);
     104
    90105    return VBoxNetAdpUninstall();
    91106}
     107
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetFltInstall.cpp

    r96407 r96572  
    3535 */
    3636
     37
     38/*********************************************************************************************************************************
     39*   Header Files                                                                                                                 *
     40*********************************************************************************************************************************/
    3741#include <VBox/VBoxNetCfg-win.h>
    3842#include <devguid.h>
    3943#include <stdio.h>
    4044
     45#include <iprt/initterm.h>
     46#include <iprt/message.h>
     47
     48
     49/*********************************************************************************************************************************
     50*   Header Files                                                                                                                 *
     51*********************************************************************************************************************************/
    4152#define NETFLT_ID L"sun_VBoxNetFlt"
    4253#define VBOX_NETCFG_APP_NAME L"NetFltInstall"
     
    181192int __cdecl main(int argc, char **argv)
    182193{
    183     RT_NOREF2(argc, argv);
     194    RTR3InitExeNoArguments(0);
     195    if (argc != 1)
     196        return RTMsgErrorExit(RTEXITCODE_SYNTAX, "This utility takes no arguments\n");
     197    NOREF(argv);
     198
    184199    return VBoxNetFltInstall();
    185200}
     201
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetFltUninstall.cpp

    r96407 r96572  
    3535 */
    3636
     37
     38/*********************************************************************************************************************************
     39*   Header Files                                                                                                                 *
     40*********************************************************************************************************************************/
    3741#include <VBox/VBoxNetCfg-win.h>
    3842#include <stdio.h>
    3943
     44#include <iprt/initterm.h>
     45#include <iprt/message.h>
     46
     47
     48/*********************************************************************************************************************************
     49*   Defined Constants And Macros                                                                                                 *
     50*********************************************************************************************************************************/
    4051#define NETFLT_ID L"sun_VBoxNetFlt"
    4152#define VBOX_NETCFG_APP_NAME L"NetFltUninstall"
     
    4354#define VBOX_NETFLT_MP_INF L".\\VBoxNetFltM.inf"
    4455#define VBOX_NETFLT_RETRIES 10
     56
    4557
    4658static DECLCALLBACK(void) winNetCfgLogger(const char *pszString)
     
    112124int __cdecl main(int argc, char **argv)
    113125{
    114     RT_NOREF2(argc, argv);
     126    RTR3InitExeNoArguments(0);
     127    if (argc != 1)
     128        return RTMsgErrorExit(RTEXITCODE_SYNTAX, "This utility takes no arguments\n");
     129    NOREF(argv);
     130
    115131    return VBoxNetFltUninstall();
    116132}
     133
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetLwfInstall.cpp

    r96407 r96572  
    3535 */
    3636
     37
     38/*********************************************************************************************************************************
     39*   Header Files                                                                                                                 *
     40*********************************************************************************************************************************/
    3741#include <VBox/VBoxNetCfg-win.h>
    3842#include <devguid.h>
    39 #include <stdio.h>
    4043
     44#include <iprt/initterm.h>
     45#include <iprt/message.h>
     46#include <iprt/utf16.h>
     47
     48
     49/*********************************************************************************************************************************
     50*   Defined Constants And Macros                                                                                                 *
     51*********************************************************************************************************************************/
    4152#define VBOX_NETCFG_APP_NAME L"NetLwfInstall"
    4253#define VBOX_NETLWF_INF L".\\VBoxNetLwf.inf"
     
    4657static DECLCALLBACK(void) winNetCfgLogger(const char *pszString)
    4758{
    48     printf("%s", pszString);
     59    RTMsgInfo("%s", pszString);
    4960}
    5061
     
    116127                    if (hr == S_OK)
    117128                    {
    118                         wprintf(L"installed successfully\n");
     129                        RTMsgInfo("Installed successfully!");
    119130                        rcExit = RTEXITCODE_SUCCESS;
    120131                    }
    121132                    else
    122                         wprintf(L"error installing VBoxNetLwf (%#lx)\n", hr);
     133                        RTMsgError("Failed installing VBoxNetLwf: %Rhrc", hr);
    123134                }
    124135                else
    125136                {
    126137                    hr = HRESULT_FROM_WIN32(GetLastError());
    127                     wprintf(L"error getting full inf path for VBoxNetLwf.inf (%#lx)\n", hr);
     138                    RTMsgError("Failed getting full inf path for VBoxNetLwf.inf: %Rhrc", hr);
    128139                }
    129140
     
    134145            if (hr == NETCFG_E_NO_WRITE_LOCK && pwszLockedBy)
    135146            {
    136                 if (i < VBOX_NETLWF_RETRIES && !wcscmp(pwszLockedBy, L"6to4svc.dll"))
     147                if (i < VBOX_NETLWF_RETRIES && RTUtf16ICmpAscii(pwszLockedBy, "6to4svc.dll") == 0)
    137148                {
    138                     wprintf(L"6to4svc.dll is holding the lock, retrying %d out of %d\n", i + 1, VBOX_NETLWF_RETRIES);
     149                    RTMsgInfo("6to4svc.dll is holding the lock - retrying %d out of %d\n", i + 1, VBOX_NETLWF_RETRIES);
    139150                    CoTaskMemFree(pwszLockedBy);
    140151                }
    141152                else
    142153                {
    143                     wprintf(L"Error: write lock is owned by another application (%s), close the application and retry installing\n",
    144                             pwszLockedBy);
     154                    RTMsgError("write lock is owned by another application (%ls), close the application and retry installing",
     155                               pwszLockedBy);
    145156                    CoTaskMemFree(pwszLockedBy);
    146157                    break;
     
    149160            else
    150161            {
    151                 wprintf(L"Error getting the INetCfg interface (%#lx)\n", hr);
     162                RTMsgError("Failed getting the INetCfg interface: %Rhrc", hr);
    152163                break;
    153164            }
     
    157168    }
    158169    else
    159         wprintf(L"Error initializing COM (%#lx)\n", hr);
     170        RTMsgError("Failed initializing COM: %Rhrc", hr);
    160171
    161172    VBoxNetCfgWinSetLogging(NULL);
     
    166177int __cdecl main(int argc, char **argv)
    167178{
    168     RT_NOREF2(argc, argv);
     179    RTR3InitExeNoArguments(0);
     180    if (argc != 1)
     181        return RTMsgErrorExit(RTEXITCODE_SYNTAX, "This utility takes no arguments\n");
     182    NOREF(argv);
     183
    169184    return VBoxNetLwfInstall();
    170185}
     186
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetLwfUninstall.cpp

    r96407 r96572  
    3535 */
    3636
     37
     38/*********************************************************************************************************************************
     39*   Header Files                                                                                                                 *
     40*********************************************************************************************************************************/
    3741#include <VBox/VBoxNetCfg-win.h>
    38 #include <stdio.h>
    3942
     43#include <iprt/initterm.h>
     44#include <iprt/message.h>
     45#include <iprt/utf16.h>
     46
     47
     48/*********************************************************************************************************************************
     49*   Defined Constants And Macros                                                                                                 *
     50*********************************************************************************************************************************/
    4051#define VBOX_NETCFG_APP_NAME L"NetLwfUninstall"
    4152#define VBOX_NETLWF_RETRIES 10
    4253
     54
    4355static DECLCALLBACK(void) winNetCfgLogger(const char *pszString)
    4456{
    45     printf("%s", pszString);
     57    RTMsgInfo("%s", pszString);
    4658}
    4759
    4860static int VBoxNetLwfUninstall()
    4961{
    50     INetCfg *pnc;
    5162    int rcExit = RTEXITCODE_FAILURE;
    5263
     
    5970        {
    6071            LPWSTR pwszLockedBy = NULL;
     72            INetCfg *pnc = NULL;
    6173            hr = VBoxNetCfgWinQueryINetCfg(&pnc, TRUE, VBOX_NETCFG_APP_NAME, 10000, &pwszLockedBy);
    6274            if (hr == S_OK)
     
    6577                if (hr == S_OK)
    6678                {
    67                     wprintf(L"uninstalled successfully\n");
     79                    RTMsgInfo("uninstalled successfully!");
    6880                    rcExit = RTEXITCODE_SUCCESS;
    6981                }
    7082                else
    71                     wprintf(L"error uninstalling VBoxNetLwf (%#lx)\n", hr);
     83                    RTMsgError("error uninstalling VBoxNetLwf: %Rhrc");
    7284
    7385                VBoxNetCfgWinReleaseINetCfg(pnc, TRUE);
     
    7789            if (hr == NETCFG_E_NO_WRITE_LOCK && pwszLockedBy)
    7890            {
    79                 if (i < VBOX_NETLWF_RETRIES && !wcscmp(pwszLockedBy, L"6to4svc.dll"))
     91                if (i < VBOX_NETLWF_RETRIES && RTUtf16ICmpAscii(pwszLockedBy, "6to4svc.dll") == 0)
    8092                {
    81                     wprintf(L"6to4svc.dll is holding the lock, retrying %d out of %d\n", i + 1, VBOX_NETLWF_RETRIES);
     93                    RTMsgInfo("6to4svc.dll is holding the lock - retry %d out of %d ...", i + 1, VBOX_NETLWF_RETRIES);
    8294                    CoTaskMemFree(pwszLockedBy);
    8395                }
    8496                else
    8597                {
    86                     wprintf(L"Error: write lock is owned by another application (%s), close the application and retry uninstalling\n",
    87                              pwszLockedBy);
     98                    RTMsgError("Write lock is owned by another application (%ls), close the application and retry uninstalling",
     99                               pwszLockedBy);
    88100                    CoTaskMemFree(pwszLockedBy);
    89101                    break;
     
    92104            else
    93105            {
    94                 wprintf(L"Error getting the INetCfg interface (%#lx)\n", hr);
     106                RTMsgError("Failed getting the INetCfg interface: %Rhrc", hr);
    95107                break;
    96108            }
     
    100112    }
    101113    else
    102         wprintf(L"Error initializing COM (%#lx)\n", hr);
     114        RTMsgError("Failed initializing COM: %Rhrc", hr);
    103115
    104116    VBoxNetCfgWinSetLogging(NULL);
     
    109121int __cdecl main(int argc, char **argv)
    110122{
    111     RT_NOREF2(argc, argv);
     123    RTR3InitExeNoArguments(0);
     124    if (argc != 1)
     125        return RTMsgErrorExit(RTEXITCODE_SYNTAX, "This utility takes no arguments\n");
     126    NOREF(argv);
     127
    112128    return VBoxNetLwfUninstall();
    113129}
     130
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