VirtualBox

Ignore:
Timestamp:
Sep 3, 2019 2:34:21 PM (5 years ago)
Author:
vboxsync
Message:

Main: bugref:9341: Added VM autostart during boot support for windows host

File:
1 edited

Legend:

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

    r76592 r80569  
    3131#include <iprt/critsect.h>
    3232#include <iprt/mem.h>
     33#include <iprt/process.h>
    3334#include <iprt/system.h>
    3435
     
    3738#include <sddl.h>
    3839#include <lmcons.h> /* UNLEN */
     40
     41#include "MachineLaunchVMCommonWorker.h"
     42
     43
     44/*********************************************************************************************************************************
     45*   Defined Constants And Macros                                                                                                 *
     46*********************************************************************************************************************************/
     47#define INTERACTIVE_SID_FLAG 0x1
     48#define LOCAL_SID_FLAG       0x2
     49#define LOGON_SID_FLAG       0x4
     50#define IS_INTERACTIVE       (LOCAL_SID_FLAG|INTERACTIVE_SID_FLAG|LOGON_SID_FLAG)
    3951
    4052
     
    388400        hrc = E_INVALIDARG;
    389401    LogRel2(("VirtualBoxSDS::deregisterVBoxSVC: returns %Rhrc\n", hrc));
     402    return hrc;
     403}
     404
     405
     406STDMETHODIMP VirtualBoxSDS::LaunchVMProcess(IN_BSTR aMachine, IN_BSTR aComment, IN_BSTR aFrontend, IN_BSTR aEnvironmentChanges,
     407                                            IN_BSTR aCmdOptions, ULONG aSessionId, ULONG *aPid)
     408{
     409    /*
     410     * Convert parameters to UTF-8.
     411     */
     412    Utf8Str strMachine(aMachine);
     413    Utf8Str strComment(aComment);
     414    Utf8Str strFrontend(aFrontend);
     415    Utf8Str strEnvironmentChanges(aEnvironmentChanges);
     416    Utf8Str strCmdOptions(aCmdOptions);
     417
     418    /*
     419     * Impersonate the caller.
     420     */
     421    HRESULT hrc = CoImpersonateClient();
     422    if (SUCCEEDED(hrc))
     423    {
     424        try
     425        {
     426            /*
     427             * Try launch the VM process as the client.
     428             */
     429            RTPROCESS pid;
     430            AssertCompile(sizeof(aSessionId) == sizeof(uint32_t));
     431            int vrc = ::MachineLaunchVMCommonWorker(strMachine, strComment, strFrontend, strEnvironmentChanges,
     432                                                    strCmdOptions, Utf8Str(),
     433                                                    RTPROC_FLAGS_AS_IMPERSONATED_TOKEN | RTPROC_FLAGS_SERVICE
     434                                                    | RTPROC_FLAGS_PROFILE | RTPROC_FLAGS_DESIRED_SESSION_ID,
     435                                                    &aSessionId, pid);
     436            if (RT_SUCCESS(vrc))
     437            {
     438                *aPid = (ULONG)pid;
     439                LogRel(("VirtualBoxSDS::LaunchVMProcess: launchVM succeeded\n"));
     440            }
     441            else if (vrc == VERR_INVALID_PARAMETER)
     442            {
     443                hrc = E_INVALIDARG;
     444                LogRel(("VirtualBoxSDS::LaunchVMProcess: launchVM failed: %Rhrc\n", hrc));
     445            }
     446            else
     447            {
     448                hrc = VBOX_E_IPRT_ERROR;
     449                LogRel(("VirtualBoxSDS::LaunchVMProcess: launchVM failed: %Rhrc (%Rrc)\n", hrc));
     450            }
     451        }
     452        catch (...)
     453        {
     454            hrc = E_UNEXPECTED;
     455        }
     456        CoRevertToSelf();
     457    }
     458    else
     459        LogRel(("VirtualBoxSDS::LaunchVMProcess: CoImpersonateClient failed: %Rhrc\n", hrc));
    390460    return hrc;
    391461}
     
    592662}
    593663
     664
    594665#ifdef WITH_WATCHER
    595666/**
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