VirtualBox

Ignore:
Timestamp:
Apr 29, 2011 5:00:37 PM (14 years ago)
Author:
vboxsync
Message:

Main/win/svcmain.cpp: Switch to the user's home directory if VBoxSVC is started through COM. Avoids dropping debug log files in the system32 directory. On manual start the current directory isn't changed.

File:
1 edited

Legend:

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

    r35722 r36900  
    55
    66/*
    7  * Copyright (C) 2006-2007 Oracle Corporation
     7 * Copyright (C) 2006-2011 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3131#include <VBox/err.h>
    3232#include <iprt/initterm.h>
     33#include <iprt/path.h>
    3334
    3435#include <atlbase.h>
     
    151152    HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int /*nShowCmd*/)
    152153{
     154    lpCmdLine = GetCommandLine(); /* this line necessary for _ATL_MIN_CRT */
     155
     156    /* Need to parse the command line before initializing the VBox runtime. */
     157    TCHAR szTokens[] = _T("-/");
     158    LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens);
     159    while (lpszToken != NULL)
     160    {
     161        if (WordCmpI(lpszToken, _T("Embedding")) == 0)
     162        {
     163            /* %HOMEDRIVE%%HOMEPATH% */
     164            wchar_t wszHome[RTPATH_MAX];
     165            DWORD cEnv = GetEnvironmentVariable(L"HOMEDRIVE", &wszHome[0], RTPATH_MAX);
     166            if (cEnv && cEnv < RTPATH_MAX)
     167            {
     168                DWORD cwc = cEnv; /* doesn't include NUL */
     169                cEnv = GetEnvironmentVariable(L"HOMEPATH", &wszHome[cEnv], RTPATH_MAX - cwc);
     170                if (cEnv && cEnv < RTPATH_MAX - cwc)
     171                {
     172                    /* If this fails there is nothing we can do. Ignore. */
     173                    SetCurrentDirectory(wszHome);
     174                }
     175            }
     176        }
     177
     178        lpszToken = FindOneOf(lpszToken, szTokens);
     179    }
     180
    153181    /*
    154182     * Initialize the VBox runtime without loading
     
    157185    RTR3Init();
    158186
    159     lpCmdLine = GetCommandLine(); /* this line necessary for _ATL_MIN_CRT */
    160 
    161187    HRESULT hRes = com::Initialize();
    162188
     
    164190    _Module.Init(ObjectMap, hInstance, &LIBID_VirtualBox);
    165191    _Module.dwThreadID = GetCurrentThreadId();
    166     TCHAR szTokens[] = _T("-/");
    167192
    168193    int nRet = 0;
    169194    BOOL bRun = TRUE;
    170     LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens);
     195    lpszToken = FindOneOf(lpCmdLine, szTokens);
    171196    while (lpszToken != NULL)
    172197    {
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