Esempio n. 1
0
void CMfcieView::OnInitialUpdate()
{
	// Go to the home page initially
	CHtmlView::OnInitialUpdate();
	CString strCmdLine(AfxGetApp()->m_lpCmdLine);
	if(strCmdLine == _T(""))
	{
		GoHome();
	}
	else
	{
		Navigate(strCmdLine);
	}
}
Esempio n. 2
0
STDMETHODIMP CVideoViewControl::OnInitialized(IServiceProvider *pServiceProvider)
{
	CHECK_E_POINTER(pServiceProvider);
	m_pServiceProvider = pServiceProvider;

	CComPtr<IUnknown> pUnk;
	RETURN_IF_FAILED(QueryInterface(__uuidof(IUnknown), (LPVOID*)&pUnk));

	STARTUPINFO si = { 0 };
	PROCESS_INFORMATION pi = { 0 };
	auto wstrParams = std::to_wstring((long long)m_hWnd);
	CString strCmdLine(L"minitwivp.exe");
	strCmdLine += CString(L" ") + wstrParams.c_str();
	TCHAR lpszCmdLine[100];
	wcscpy(lpszCmdLine, strCmdLine);
	auto res = CreateProcess(
		NULL,
		lpszCmdLine,
		NULL,
		NULL,
		FALSE,
		NULL,
		NULL,
		NULL,
		&si,
		&pi
		);
	
	if (!res)
	{
		HRESULT hr = HRESULT_FROM_WIN32(GetLastError());
		HandleError(hr);
	}

    CloseHandle(pi.hThread);
	m_hProcess = pi.hProcess;
	SetTimer(1, 10 * 1000); //waiting for child process init

	return S_OK;
}
Esempio n. 3
0
int Host::ShellEx(const OOBase::CmdArgs::results_t& args)
{
    OOBase::LocalString strAppName(args.get_allocator());
    if (!args.find("@0",strAppName))
        LOG_ERROR_RETURN(("No arguments passed with --shellex"),EXIT_FAILURE);

    OOBase::TempPtr<wchar_t> wszAppName(args.get_allocator());
    int err = OOBase::Win32::utf8_to_wchar_t(strAppName.c_str(),wszAppName);
    if (err)
        LOG_ERROR_RETURN(("Failed to convert string: %s",OOBase::system_error_text(err)),EXIT_FAILURE);

    OOBase::LocalString strCmdLine(args.get_allocator());
    for (size_t i = 1;; ++i)
    {
        OOBase::LocalString strId(args.get_allocator());
        int err = strId.printf("@%u",i);
        if (err)
            LOG_ERROR_RETURN(("Failed to format string: %s",OOBase::system_error_text(err)),EXIT_FAILURE);

        OOBase::LocalString strArg(args.get_allocator());
        if (!args.find(strId,strArg))
            break;

        err = strCmdLine.append(strArg.c_str());
        if (!err && i != 0)
            err = strCmdLine.append(" ");
        if (err)
            LOG_ERROR_RETURN(("Failed to append string: %s",OOBase::system_error_text(err)),EXIT_FAILURE);
    }

    OOBase::TempPtr<wchar_t> wszCmdLine(args.get_allocator());
    if (!strCmdLine.empty())
    {
        err = OOBase::Win32::utf8_to_wchar_t(strCmdLine.c_str(),wszCmdLine);
        if (err)
            LOG_ERROR_RETURN(("Failed to convert string: %s",OOBase::system_error_text(err)),EXIT_FAILURE);
    }

    HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
    if (FAILED(hr))
        LOG_ERROR_RETURN(("CoInitializeEx failed: %s",OOBase::system_error_text()),EXIT_FAILURE);

    SHELLEXECUTEINFOW sei = {0};
    sei.cbSize = sizeof(sei);
    sei.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_NOASYNC | SEE_MASK_FLAG_NO_UI | SEE_MASK_NO_CONSOLE;
    sei.lpFile = wszAppName;
    sei.lpParameters = wszCmdLine;
    sei.nShow = SW_SHOWDEFAULT;

    if (!ShellExecuteExW(&sei))
        LOG_ERROR_RETURN(("ShellExecuteExW failed: %s",OOBase::system_error_text()),EXIT_FAILURE);

    if (sei.hProcess)
    {
        WaitForSingleObject(sei.hProcess,INFINITE);
        CloseHandle(sei.hProcess);
    }

    CoUninitialize();

    return EXIT_SUCCESS;
}
Esempio n. 4
0
BOOL CConfigFrame::DisplayContextBranch()
{   TCHAR p;
    int i, iPos, iLen, iLeft, iChars=0;
    CString strCmdLine(_T("")), strContext(_T(""));
    CString strItem(_T("")), strClass(_T("")), strSubItem(_T("")); 
    HTREEITEM hTreeItem=NULL, hChildItem=NULL, hShowItem=NULL;

    // Check for command line option
    CVcbfApp *theApp = (CVcbfApp *)AfxGetApp();
    if (!theApp)
       return FALSE;

    if (theApp->m_lpCmdLine)
      strCmdLine = theApp->m_lpCmdLine;

    strCmdLine.MakeLower();
    //
    // DBCS Compliant:
    iPos = strCmdLine.Find(_T("/c=\""));
    if (iPos != -1)
    { 
      iLen = strCmdLine.GetLength();
      iLeft = iPos + 4;
      for (i=iLeft; i<iLen; i++)
      { 
        p = strCmdLine.GetAt(i);
        if (p == _T('\"'))
        { 
          break;
        }
        iChars++;
      }
      
      strContext=strCmdLine.Mid(iLeft, iChars);
    }
    else
      strContext=_T("Name Server");

    // Take the context string and divide it into Branch and Sub-Branch
    // If no subitem is specified, "(default)" is used
       
    if (strContext.IsEmpty())
       return FALSE;    

    iPos = strContext.Find(_T("\\"));
    if (iPos != -1)
    { strClass = strContext.Left(iPos);
      strSubItem = strContext.Right(strContext.GetLength() - iPos - 1);
    }
    else
    { strClass = strContext;
      strSubItem = GetLocDefConfName();
    }

    CConfLeftDlg* pLeftDlg = GetCConfLeftDlg();
	if (!pLeftDlg) 
       return FALSE;

    // Search through the first level of the tree
    hTreeItem = pLeftDlg->m_tree_ctrl.GetChildItem(pLeftDlg->m_tree_ctrl.GetRootItem());
  
    while (hTreeItem)
    { 
      strItem = pLeftDlg->m_tree_ctrl.GetItemText(hTreeItem);
	
	  if (strItem.CompareNoCase(strClass) == 0)
      { pLeftDlg->m_tree_ctrl.Expand(hTreeItem, TVE_EXPAND);
        hShowItem=hTreeItem;
        break;
      }

      hTreeItem = pLeftDlg->m_tree_ctrl.GetNextSiblingItem(hTreeItem);
    }

    // Search through child items if necessary
    hChildItem = pLeftDlg->m_tree_ctrl.GetChildItem(hTreeItem);
    
    while (hChildItem)
    { 
      strItem = pLeftDlg->m_tree_ctrl.GetItemText(hChildItem);
	
	  if (strItem.CompareNoCase(strSubItem) == 0)
      { hShowItem=hChildItem;
        break;
      }
      
      hChildItem = pLeftDlg->m_tree_ctrl.GetNextSiblingItem(hChildItem);
    }

    // Select the item that was found and display the right pane 
    if (hShowItem)
       pLeftDlg->m_tree_ctrl.Select(hShowItem,TVGN_CARET);
 
    return TRUE;
}
Esempio n. 5
0
void ConsoleHandler::CreateShellProcess
(
	const wstring& strShell,
	const wstring& strInitialDir,
	const UserCredentials& userCredentials,
	const wstring& strInitialCmd,
	const wstring& strConsoleTitle,
	PROCESS_INFORMATION& pi
)
{
	std::unique_ptr<void, DestroyEnvironmentBlockHelper> userEnvironment;
	std::unique_ptr<void, CloseHandleHelper>             userToken;

	if (userCredentials.strUsername.length() > 0)
	{
		if (!userCredentials.netOnly)
		{
			// logon user
			HANDLE hUserToken = NULL;
			if( !::LogonUser(
				userCredentials.strUsername.c_str(),
				userCredentials.strDomain.length() > 0 ? userCredentials.strDomain.c_str() : NULL,
				userCredentials.password.c_str(),
				LOGON32_LOGON_INTERACTIVE,
				LOGON32_PROVIDER_DEFAULT,
				&hUserToken) || !::ImpersonateLoggedOnUser(hUserToken) )
			{
				Win32Exception err(::GetLastError());
				throw ConsoleException(boost::str(boost::wformat(Helpers::LoadStringW(IDS_ERR_CANT_START_SHELL_AS_USER)) % L"?" % userCredentials.user % err.what()));
			}
			userToken.reset(hUserToken);

			/*
			// load user's profile
			// seems to be necessary on WinXP for environment strings' expainsion to work properly
			PROFILEINFO userProfile;
			::ZeroMemory(&userProfile, sizeof(PROFILEINFO));
			userProfile.dwSize = sizeof(PROFILEINFO);
			userProfile.lpUserName = const_cast<wchar_t*>(userCredentials.strUsername.c_str());

			::LoadUserProfile(userToken.get(), &userProfile);
			userProfileKey.reset(userProfile.hProfile, bind<BOOL>(::UnloadUserProfile, userToken.get(), _1));
			*/

			// load user's environment
			void*	pEnvironment = nullptr;
			if( !::CreateEnvironmentBlock(&pEnvironment, userToken.get(), FALSE) )
			{
				Win32Exception err(::GetLastError());
				::RevertToSelf();
				throw ConsoleException(boost::str(boost::wformat(Helpers::LoadStringW(IDS_ERR_CANT_START_SHELL_AS_USER)) % L"?" % userCredentials.user % err.what()));
			}
			userEnvironment.reset(pEnvironment);
		}
	}

	wstring	strShellCmdLine(strShell);

	if (strShellCmdLine.length() == 0)
	{
		wchar_t	szComspec[MAX_PATH];

		::ZeroMemory(szComspec, MAX_PATH*sizeof(wchar_t));

		if (userEnvironment.get())
		{
			// resolve comspec when running as another user
			wchar_t* pszComspec = reinterpret_cast<wchar_t*>(userEnvironment.get());

			while ((pszComspec[0] != L'\x00') && (_wcsnicmp(pszComspec, L"comspec", 7) != 0)) pszComspec += wcslen(pszComspec)+1;

			if (pszComspec[0] != L'\x00')
			{
				strShellCmdLine = (pszComspec + 8);
			}

			if (strShellCmdLine.length() == 0) strShellCmdLine = L"cmd.exe";
		}
		else
		{
			if (::GetEnvironmentVariable(L"COMSPEC", szComspec, MAX_PATH) > 0)
			{
				strShellCmdLine = szComspec;
			}

			if (strShellCmdLine.length() == 0) strShellCmdLine = L"cmd.exe";
		}
	}

	if (strInitialCmd.length() > 0)
	{
		strShellCmdLine += L" ";
		strShellCmdLine += strInitialCmd;
	}

	wstring	strStartupTitle(strConsoleTitle);

	if (strStartupTitle.length() == 0)
	{
		strStartupTitle = L"Console2 command window";
		//		strStartupTitle = boost::str(boost::wformat(L"Console2 command window 0x%08X") % this);
	}

	wstring strStartupDir(
		userToken.get() ?
		Helpers::ExpandEnvironmentStringsForUser(userToken.get(), strInitialDir) :
		Helpers::ExpandEnvironmentStrings(strInitialDir));

	if (strStartupDir.length() > 0)
	{
		if ((*(strStartupDir.end() - 1) == L'\"') && (*strStartupDir.begin() != L'\"'))
		{
			// startup dir name ends with ", but doesn't start with ", the user passed
			// something like "C:\" as the parameter, it got parsed to C:", remove the trailing "
			//
			// This is a common mistake, thus the check...
			strStartupDir = strStartupDir.substr(0, strStartupDir.length()-1);
		}

		// startup dir doesn't end with \, add it
		if (*(strStartupDir.end() - 1) != L'\\') strStartupDir += L'\\';

		// check if startup directory exists
		DWORD dwDirAttributes = ::GetFileAttributes(strStartupDir.c_str());

		if ((dwDirAttributes == INVALID_FILE_ATTRIBUTES) ||
			(dwDirAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
		{
			// no directory, use Console.exe directory
			strStartupDir = Helpers::GetModulePath(NULL);
		}
	}

	wstring strCmdLine(
		userToken.get() ?
		Helpers::ExpandEnvironmentStringsForUser(userToken.get(), strShellCmdLine) :
		Helpers::ExpandEnvironmentStrings(strShellCmdLine));

	if( userToken.get() )
		::RevertToSelf();

	// setup the startup info struct
	STARTUPINFO si;
	::ZeroMemory(&si, sizeof(STARTUPINFO));

	si.cb			= sizeof(STARTUPINFO);
	si.lpTitle		= const_cast<wchar_t*>(strStartupTitle.c_str());

	if (g_settingsHandler->GetConsoleSettings().bStartHidden)
	{
		// Starting Windows console window hidden causes problems with 
		// some GUI apps started from Console that use SW_SHOWDEFAULT to 
		// initially show their main window (i.e. the window inherits our 
		// SW_HIDE flag and remains invisible :-)
		si.dwFlags		= STARTF_USESHOWWINDOW;
		si.wShowWindow	= SW_HIDE;
	}
	else
	{
		// To avoid invisible GUI windows, default settings will create
		// a Windows console window far offscreen and hide the window
		// after it has been created.
		//
		// This approach can flash console window's taskbar button and
		// taskbar button can sometimes remain visible, but nothing is perfect :)
		si.dwFlags		= STARTF_USEPOSITION;
		si.dwX			= 0x7FFF;
		si.dwY			= 0x7FFF;
	}

	// we must use CREATE_UNICODE_ENVIRONMENT here, since s_environmentBlock contains Unicode strings
	DWORD dwStartupFlags = CREATE_NEW_CONSOLE|CREATE_SUSPENDED|CREATE_UNICODE_ENVIRONMENT;

	// TODO: not supported yet
	//if (bDebugFlag) dwStartupFlags |= DEBUG_PROCESS;

	if (userCredentials.strUsername.length() > 0)
	{
		if( !::CreateProcessWithLogonW(
			userCredentials.strUsername.c_str(),
			userCredentials.strDomain.length() > 0 ? userCredentials.strDomain.c_str() : NULL,
			userCredentials.password.c_str(), 
			userCredentials.netOnly? LOGON_NETCREDENTIALS_ONLY : LOGON_WITH_PROFILE,
			NULL,
			const_cast<wchar_t*>(strCmdLine.c_str()),
			dwStartupFlags,
			s_environmentBlock.get(),
			(strStartupDir.length() > 0) ? const_cast<wchar_t*>(strStartupDir.c_str()) : NULL,
			&si,
			&pi))
		{
			Win32Exception err(::GetLastError());
			throw ConsoleException(boost::str(boost::wformat(Helpers::LoadStringW(IDS_ERR_CANT_START_SHELL_AS_USER)) % strShellCmdLine % userCredentials.user % err.what()));
		}
	}
	else
	{
		if (!::CreateProcess(
			NULL,
			const_cast<wchar_t*>(strCmdLine.c_str()),
			NULL,
			NULL,
			FALSE,
			dwStartupFlags,
			s_environmentBlock.get(),
			(strStartupDir.length() > 0) ? const_cast<wchar_t*>(strStartupDir.c_str()) : NULL,
			&si,
			&pi))
		{
			Win32Exception err(::GetLastError());
			throw ConsoleException(boost::str(boost::wformat(Helpers::LoadString(IDS_ERR_CANT_START_SHELL)) % strShellCmdLine % err.what()));
		}
	}
}