I am working in a C++ project. I need to obtain the path of a installed software. (Eg. skype.exe) Is there any way to find the path via C++ coding or via Widows command prompt
Depends what you are needing it for, and how generic you want it.
You can use GetEnvironmentVariable to get the PATH variable, and search these paths.
You can use the App Paths registry key, as Gabe says. See also...
Usually there are pretty clear application-specific ways to find the path via the registry. Either via the HKLM/Software key or Uninstall. Careful with localization and hard-coding application names...
If you are just trying to launch the app, ShellExecute doesn't need the full path, it works almost like the "run" dialog box in the start menu.
It's in the App Paths registry key. For skype.exe you would look in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\skype.exe
You can call the standard Win32 API RegQueryValue to read it.
Related
I have an application which is installed and run as a Windows service. In a given time, I need to locate the current application path (that is, the installation path) where other, needed files are located.
Unfortunately I'm being unable to find this directory using the traditional methods (QCoreApplication::applicationDirPath(), dir.absolutePath(), QDir::currentPath()). Every time this functions are called, they either return blank or the system32 folder.
I tried to improvise using QStandardPaths::findExecutable, but it didn't solve my problems. My last resort for now is creating a script that creates an entry in the registry telling the service where to look for, but since the installation is supposed to be just an "extract from compressed file", I'd like to avoid this option.
So which other method Qt makes available to make this specific circunstancial task?
How to convert ï¼…USERPROFILE% path to file path in C++? It should work on Windows XP and later versions.
I need it because when I'm trying to launch .jar file with CreateProcessW method using javaw.exe, the file is not found.
You can use a function that expands environment variables. For instance getenv, or on Windows you could choose to use GetEnvironmentVariable.
However, the right way to find the user profile directory is to use the Windows API for it. If you need to support XP then you need to use the CSIDL for that folder: CSIDL_PROFILE. Use SHGetSpecialFolderPath to read out the path associated with a particular CSIDL value.
This is how to get the user profile directory, although I must admit to struggling to understand how that would help you launch javaw.exe.
Update
In the comments you indicate that you actually want the temporary directory. Use GetTempPath to obtain that.
I have an application that requires that a DLL be able to create various directories in it's current location. However, from looking around, I have found that windows 7 apparently restricts the ability of programs to write in a lot of places. I cannot redesign the application, as the DLL is injected into a process and creates log files that the user would view. I don't want to shove them in appdata, is there any other way to do what I want?
You can try to change the current working directory with SetCurrentDirectory
I'm using Qt, and it has a really helpful QSettings class that allows to easily access the Windows registry:
QSettings s("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\.html\\OpenWithList", QSettings::NativeFormat);
s.value("a").toString() returns "chrome.exe".
Chrome is not in my computer's PATH. Running chrome.exe in the terminal results in a not found error. So I can't just run it in my C++ app.
I also can't get the icon for it, as I need full path.
So how do I find this full path? (In case of Chrome it's C:\Users\Administrator\AppData\Local\Google\Chrome\Application\chrome.exe)
Don't mess with the registry directly -- FindExecutable is designed to produce exactly what you want/need.
I am developing a non-GUI application for Linux. At some point I ask the user to input a directory path, which will be used to store files.
It there a way to have behaviour similar to the console (eg. when pressing TAB, the path is automatically filled for you, or available directory paths are printed)?
What is the usual solution for this kind of problem, in case what I am looking for doesn't exist?
The usual solution is to use readline's completion facility, just like the shell does.
What you are looking for is the readline library