static void DoOpenExplore(ItemCmImpl *This, HWND hwnd, LPCSTR verb) { UINT i, bFolderFound = FALSE; LPITEMIDLIST pidlFQ; SHELLEXECUTEINFOA sei; /* Find the first item in the list that is not a value. These commands should never be invoked if there isn't at least one folder item in the list.*/ for(i = 0; i<This->cidl; i++) { if(!_ILIsValue(This->apidl[i])) { bFolderFound = TRUE; break; } } if (!bFolderFound) return; pidlFQ = ILCombine(This->pidl, This->apidl[i]); ZeroMemory(&sei, sizeof(sei)); sei.cbSize = sizeof(sei); sei.fMask = SEE_MASK_IDLIST | SEE_MASK_CLASSNAME; sei.lpIDList = pidlFQ; sei.lpClass = "Folder"; sei.hwnd = hwnd; sei.nShow = SW_SHOWNORMAL; sei.lpVerb = verb; ShellExecuteExA(&sei); SHFree(pidlFQ); }
void CmFile::RunProgram(CStr &fileName, CStr ¶meters, bool waiteF, bool showW) { string runExeFile = fileName; #ifdef _DEBUG runExeFile.insert(0, "..\\Debug\\"); #else runExeFile.insert(0, "..\\Release\\"); #endif // _DEBUG if (!CmFile::FileExist(_S(runExeFile))) runExeFile = fileName; SHELLEXECUTEINFOA ShExecInfo = {0}; ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; ShExecInfo.hwnd = NULL; ShExecInfo.lpVerb = NULL; ShExecInfo.lpFile = _S(runExeFile); ShExecInfo.lpParameters = _S(parameters); ShExecInfo.lpDirectory = NULL; ShExecInfo.nShow = showW ? SW_SHOW : SW_HIDE; ShExecInfo.hInstApp = NULL; ShellExecuteExA(&ShExecInfo); //printf("Run: %s %s\n", ShExecInfo.lpFile, ShExecInfo.lpParameters); if (waiteF) WaitForSingleObject(ShExecInfo.hProcess,INFINITE); }
HANDLE ExecuteProcess( const std::string & exe, const std::string &args, const std::string & WorkDir ) { std::string cmd="\""+exe+"\""; if( args!="" ) cmd+=" "+args; HANDLE h=ExecuteProcessO(cmd, WorkDir); if( h!=NULL ) return h; SHELLEXECUTEINFOA TempInfo = {0}; TempInfo.cbSize = sizeof(SHELLEXECUTEINFOA); TempInfo.fMask = 0; //SEE_MASK_NOCLOSEPROCESS TempInfo.hwnd = NULL; TempInfo.lpVerb = "runas"; TempInfo.lpFile = exe.c_str(); TempInfo.lpParameters = args.c_str(); TempInfo.lpDirectory = WorkDir.c_str(); TempInfo.nShow = SW_NORMAL; BOOL b=ShellExecuteExA(&TempInfo); if( b==TRUE ) { return (HANDLE)1; } else return NULL; }
void ResourcesPage::onCommandMenuSelected( wxCommandEvent& event ) { int id = event.GetId(); const ResourceHandle& handle = getResourceFromTreeId( menuItemId ); Resource* res = handle.Resolve(); const String& fullPath = getResourceFullPath(res); switch(id) { case ID_ResourceMenu_Open: { wxLaunchDefaultApplication(fullPath); break; } case ID_ResourceMenu_Browse: { #if 0 SHELLEXECUTEINFOA info; info.cbSize = sizeof(SHELLEXECUTEINFOA); info.fMask = 0; info.hwnd = nullptr; info.lpParameters = nullptr; info.lpDirectory = nullptr; info.nShow = SW_MAXIMIZE; info.hInstApp = nullptr; info.lpVerb = "explore"; info.lpFile = fullPath.c_str(); if( !ShellExecuteExA(&info) ) return; #endif wxString command = wxString("explorer.exe /select,") + fullPath; executeCommand(command); break; } case ID_ResourceMenu_VCS_Update: { wxString command = getTortoiseBaseCommand(res, "update"); executeCommand(command); break; } case ID_ResourceMenu_VCS_Commit: { wxString command = getTortoiseBaseCommand(res, "commit"); executeCommand(command); break; } case ID_ResourceMenu_VCS_ShowLog: { wxString command = getTortoiseBaseCommand(res, "log"); executeCommand(command); break; } } }
HANDLE startChild(const std::string& filename, const std::string& param, const std::string& directory){ SHELLEXECUTEINFOA info; info.cbSize=sizeof(info); info.fMask = SEE_MASK_NOCLOSEPROCESS; info.hwnd = 0; info.lpFile = filename.c_str(); // Application name info.lpVerb = "open"; info.lpParameters = param.c_str(); // Additional parameters if (directory.size()>0){ info.lpDirectory = directory.c_str(); // Default directory } info.nShow = SW_SHOWDEFAULT; info.hInstApp = 0; bool res = ShellExecuteExA(&info); if (res){ return info.hProcess; } return NULL; }
static HRESULT WINAPI IShellExecuteHookA_fnExecute(IShellExecuteHookA *iface, LPSHELLEXECUTEINFOA psei) { ICPanelImpl *This = impl_from_IShellExecuteHookA(iface); SHELLEXECUTEINFOA sei_tmp; PIDLCPanelStruct* pcpanel; char path[MAX_PATH]; BOOL ret; TRACE("(%p)->execute(%p)\n", This, psei); if (!psei) return E_INVALIDARG; pcpanel = _ILGetCPanelPointer(ILFindLastID(psei->lpIDList)); if (!pcpanel) return E_INVALIDARG; path[0] = '\"'; lstrcpyA(path+1, pcpanel->szName); /* pass applet name to Control_RunDLL to distinguish between applets in one .cpl file */ lstrcatA(path, "\" "); lstrcatA(path, pcpanel->szName+pcpanel->offsDispName); sei_tmp = *psei; sei_tmp.lpFile = path; sei_tmp.fMask &= ~SEE_MASK_INVOKEIDLIST; ret = ShellExecuteExA(&sei_tmp); if (ret) return S_OK; else return S_FALSE; }
/////////////////////////////////////////////////////////////// // // MyShellExecute // // Returns true if successful // /////////////////////////////////////////////////////////////// static bool MyShellExecute ( bool bBlocking, const SString& strAction, const SString& strInFile, const SString& strInParameters = "", const SString& strDirectory = "", int nShowCmd = SW_SHOWNORMAL ) { SString strFile = strInFile; SString strParameters = strInParameters; if ( strAction == "open" && strFile.BeginsWithI ( "http://" ) && strParameters.empty () ) { strParameters = "url.dll,FileProtocolHandler " + strFile; strFile = "rundll32.exe"; } if ( bBlocking ) { SHELLEXECUTEINFO info; memset( &info, 0, sizeof ( info ) ); info.cbSize = sizeof ( info ); info.fMask = SEE_MASK_NOCLOSEPROCESS; info.lpVerb = strAction; info.lpFile = strFile; info.lpParameters = strParameters; info.lpDirectory = strDirectory; info.nShow = nShowCmd; bool bResult = ShellExecuteExA( &info ) != FALSE; if ( info.hProcess ) { WaitForSingleObject ( info.hProcess, INFINITE ); CloseHandle ( info.hProcess ); } return bResult; } else { int iResult = (int)ShellExecute ( NULL, strAction, strFile, strParameters, strDirectory, nShowCmd ); return iResult > 32; } }
bool BootUtils::RunInstaller( vector<SharedDependency> missing, SharedApplication application, std::string updateFile, std::string installerPath, bool quiet, bool forceInstall) { if (installerPath.empty()) { installerPath = application->path; } string exec = FileUtils::Join( installerPath.c_str(), "installer", "Installer.exe", NULL); if (!FileUtils::IsFile(exec)) { return false; } vector<string> args; args.push_back("-appPath"); args.push_back(application->path); args.push_back("-exePath"); args.push_back(application->GetExecutablePath()); if (!updateFile.empty()) { args.push_back("-updateFile"); args.push_back(updateFile); } if (quiet) { args.push_back("-quiet"); } if (forceInstall) { args.push_back("-forceInstall"); } vector<string> jobs; vector<SharedDependency>::iterator mi = missing.begin(); while (mi != missing.end()) { SharedDependency d = *mi++; string url = application->GetURLForDependency(d); string job = d->name + "," + d->version + "," + url; jobs.push_back(job); } // A little bit of ugliness goes a long way: // Use ShellExecuteEx here with the undocumented runas verb // so that we can execute the installer executable and have it // properly do the UAC thing. Why isn't this in the API? // More ugliness: The path length for ShellExecuteEx is limited so just // pass a file name containing all the download jobs. :( string tempdir = FileUtils::GetTempDirectory(); string jobsFile = FileUtils::Join(tempdir.c_str(), "jobs", NULL); if (jobs.size() > 0) { FileUtils::CreateDirectory(tempdir); std::ofstream outfile(jobsFile.c_str()); for (size_t i = 0; i < jobs.size(); i++) { outfile << jobs[i] << "\n"; } outfile.close(); args.push_back(jobsFile); } string paramString = ""; for (size_t i = 0; i < args.size(); i++) { paramString.append(" \""); paramString.append(args.at(i)); paramString.append("\""); } printf("%s\n", paramString.c_str()); SHELLEXECUTEINFOA ShExecInfo = {0}; ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_DDEWAIT; ShExecInfo.hwnd = NULL; if (!IsWindowsXP()) { ShExecInfo.lpVerb = "runas"; } ShExecInfo.lpFile = exec.c_str(); ShExecInfo.lpParameters = paramString.c_str(); ShExecInfo.lpDirectory = NULL; ShExecInfo.nShow = SW_SHOW; ShExecInfo.hInstApp = NULL; ShellExecuteExA(&ShExecInfo); WaitForSingleObject(ShExecInfo.hProcess, INFINITE); DWORD returnCode; GetExitCodeProcess(ShExecInfo.hProcess, &returnCode); if (FileUtils::IsDirectory(tempdir)) { FileUtils::DeleteDirectory(tempdir); } if (returnCode != 0) { return false; } return true; }
JNIEXPORT jint JNICALL Java_org_gudy_azureus2_platform_win32_access_impl_AEWin32AccessInterface_shellExecAndWaitA( JNIEnv* env, jclass cla, jstring _file, jstring _params ) { char file[2048]; char params[2048]; if ( !jstringToCharsA( env, _file, file, sizeof( file ))){ return(0); } if ( !jstringToCharsA( env, _params, params, sizeof( params ))){ return(0); } SHELLEXECUTEINFOA shExecInfo; shExecInfo.cbSize = sizeof(SHELLEXECUTEINFOA); shExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_DDEWAIT; shExecInfo.hwnd = NULL; shExecInfo.lpVerb = "runas"; shExecInfo.lpFile = file; shExecInfo.lpParameters = params; shExecInfo.lpDirectory = NULL; shExecInfo.nShow = SW_SHOWNORMAL; shExecInfo.hInstApp = NULL; ShellExecuteExA(&shExecInfo); int res = (int)shExecInfo.hInstApp; if ( res <= 32 ){ throwException( env, "shellExec", "ShellExecA failed", res ); return( 0 ); }else{ HANDLE process = shExecInfo.hProcess; WaitForSingleObject( process, INFINITE ); DWORD result; if ( GetExitCodeProcess( process, &result ) == 0 ){ throwException( env, "shellExec", "GetExitCodeProcess failed", GetLastError()); } CloseHandle( process ); return((jint)result); } };