Esempio n. 1
0
void CCmdCenter::onGetUserInput(std::string strInput )
{
	std::vector<std::string> vecSplit ;
	std::string strCur ;
	for ( char n : strInput )
	{
		if ( n != ' ' && n != '\t' )
		{
			strCur.push_back(n);
		}
		else
		{
			if ( strCur.empty() == false )
			{
				vecSplit.push_back(strCur) ;
			}
			strCur.clear() ;
		}
	}

	if ( strCur.empty() == false )
	{
		vecSplit.push_back(strCur) ;
	}
	strCur.clear() ;

	if ( vecSplit.empty() )
	{
		printf("parse input error , str = %s\n",strInput.c_str() ) ;
		return ;
	}

	// if is help commond 
	if ( "help" == vecSplit[0] )
	{
		vecSplit.erase(vecSplit.begin()) ;
		if ( vecSplit.empty() )
		{
			showModules();
			return;
		}

		if ( vecSplit.size() == 1 )
		{
			ShowModule(vecSplit[0]) ;
			return;
		}

		showCmd(vecSplit[0],vecSplit[1]) ;
		return ;
	}

	auto pcmd = getCmdByName(vecSplit[0]);
	if ( pcmd == nullptr )
	{
		printf("can not find cmd name = %s\n",vecSplit[0].c_str()) ;
		return ;
	}

	vecSplit.erase(vecSplit.begin()) ;

	stBufferItem * p = new stBufferItem(pcmd,vecSplit);
	m_tBufferLock.Lock() ;
	m_vWillSendBuffer.push_back(p) ;
	m_tBufferLock.Unlock() ;
}
Esempio n. 2
0
bool
LaunchUnelevated(int aArgc, wchar_t* aArgv[])
{
  // We require a single-threaded apartment to talk to Explorer.
  mscom::STARegion sta;
  if (!sta.IsValid()) {
    return false;
  }

  // NB: Explorer is a local server, not an inproc server
  RefPtr<IShellWindows> shellWindows;
  HRESULT hr = ::CoCreateInstance(CLSID_ShellWindows, nullptr,
                                  CLSCTX_LOCAL_SERVER, IID_IShellWindows,
                                  getter_AddRefs(shellWindows));
  if (FAILED(hr)) {
    return false;
  }

  // 1. Find the shell view for the desktop.
  _variant_t loc(CSIDL_DESKTOP);
  _variant_t empty;
  long hwnd;
  RefPtr<IDispatch> dispDesktop;
  hr = shellWindows->FindWindowSW(&loc, &empty, SWC_DESKTOP, &hwnd,
                                  SWFO_NEEDDISPATCH, getter_AddRefs(dispDesktop));
  if (FAILED(hr)) {
    return false;
  }

  RefPtr<IServiceProvider> servProv;
  hr = dispDesktop->QueryInterface(IID_IServiceProvider, getter_AddRefs(servProv));
  if (FAILED(hr)) {
    return false;
  }

  RefPtr<IShellBrowser> browser;
  hr = servProv->QueryService(SID_STopLevelBrowser, IID_IShellBrowser,
                              getter_AddRefs(browser));
  if (FAILED(hr)) {
    return false;
  }

  RefPtr<IShellView> activeShellView;
  hr = browser->QueryActiveShellView(getter_AddRefs(activeShellView));
  if (FAILED(hr)) {
    return false;
  }

  // 2. Get the automation object for the desktop.
  RefPtr<IDispatch> dispView;
  hr = activeShellView->GetItemObject(SVGIO_BACKGROUND, IID_IDispatch,
                                      getter_AddRefs(dispView));
  if (FAILED(hr)) {
    return false;
  }

  RefPtr<IShellFolderViewDual> folderView;
  hr = dispView->QueryInterface(IID_IShellFolderViewDual,
                                getter_AddRefs(folderView));
  if (FAILED(hr)) {
    return false;
  }

  // 3. Get the interface to IShellDispatch2
  RefPtr<IDispatch> dispShell;
  hr = folderView->get_Application(getter_AddRefs(dispShell));
  if (FAILED(hr)) {
    return false;
  }

  RefPtr<IShellDispatch2> shellDisp;
  hr = dispShell->QueryInterface(IID_IShellDispatch2, getter_AddRefs(shellDisp));
  if (FAILED(hr)) {
    return false;
  }

  // 4. Now call IShellDispatch2::ShellExecute to ask Explorer to re-launch us.

  // Omit argv[0] because ShellExecute doesn't need it in params
  UniquePtr<wchar_t[]> cmdLine(MakeCommandLine(aArgc - 1, aArgv + 1));
  if (!cmdLine) {
    return false;
  }

  _bstr_t exe(aArgv[0]);
  _variant_t args(cmdLine.get());
  _variant_t operation(L"open");
  _variant_t directory;
  _variant_t showCmd(SW_SHOWNORMAL);
  hr = shellDisp->ShellExecute(exe, args, operation, directory, showCmd);
  return SUCCEEDED(hr);
}