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
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?
What I'm trying to achieve is to run a program, which thinks a folder exists within its own folder while actually the folder is somewhere else on the system.
So my program would launch a process and say to the process: Folder A which is at C:\A is within your own directory at C:\Program Files (x86)\SomeProgram\A
So the "virtual" directory would only be visible to that process.
I'm using Qt to program my program, so if there are any Qt functions I could use that would be great (in relation to portability). However, plan C++ or any windows-bound API's would be fine.
I was thinking about NTFS junctions or symbolic links but I would have no idea how to create either of those in C++, let alone bind them to a specific process.
Thanks in advance!
EDIT:
In relation to the above, I've found this question: https://superuser.com/questions/234422/does-windows7-support-symbolic-links-folder-shortcuts. However, it only shows how to perform the required actions from the command-line and it wouldn't be process bound.
EDIT 2:
Some extra information: I'm trying to create a virtual directory that is made up of a couple of other directories but then merged (I'm using a priority system to decide which files "win" from other files). These merged directories would then appear to the target process as one directory containing the merged files.
I think I'm going to stick with Window's mklink command. It seems to suit my needs the best.
What I'm going to do is use QFile::link() on all operating systems that aren't Windows, and QProcess with mklink on windows. This should work on every operating system.
For a good example look here: https://stackoverflow.com/a/21013935/979732
Such tasks are accomplished by use of a filesystem filter driver. The driver intercepts OS requests going to the filesystem and lets you insert your own virtual files and directories into the existing directory on the disk. Filter driver can be an overkill for your particular task, though.
Detours approach mentioned in comments requires system-wide hooking of file APIs and will slowdown the whole system(filesystem filter driver is attached to one disk and it's a documented approach, so it's faster and more robust).
I would like to have a single run configuration that I can use whether I'm testing on a Windows system or a Unix system.
Everything seems to be fine with the exception that in the run configurations dialog the field for C/C++ Application requires the extension of the application as well.
So in Windows, it is: Path/To/Application.exe
and on a Unix system, it is: Path/To/Application
If there was someway to automatically detect the OS and apply the appropriate extension, I can share the same *.launch file with everyone working on the project regardless of their operating system.
I've looked a little bit into using Variables to set the path and file name, but most of them require additional dialogs and user inputs. Wild cards don't seem to work here either.
Any ideas?
Thanks to Marc K. for pointing out the quick fix of simply adding ".exe" extensions to the unix executables. Though, as he mentions, this isn't a perfect fix to the problem.
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.
I have successfully divided a large MFC project into a couple of smaller DLL projects. Now I want to have a separate folder called "DLL" in my application's folder, where all the all the DLLs from the subprojects are placed.
Can anybody give me guidance in how to achieve this?
If you use LoadLibrary, you simply have to explicitly specify the full path of the DLLs you load.
If the DLLs are implicitly linked, you can do this in two ways.
Have the installer modify the PATH variable. This is intrusive and "bad form"
Write a "loader" application that locally modifies the path variable, then executes the real executable.
The best solution would be to simply put the DLLs in the same directory as the executable.
DLL redirection is a fairly new feature (Windows 2000 IIRC). Name your DLL directory <myapp>.exe.local, and Windows will check it first for anything loaded via LoadLibrary(Ex). This includes delay-loaded DLLs.
EDIT: As pointed out by Eric this doesn't work. Sorry.
See Dynamic-Link Library Search Order. In short you can do so using registry keys under the "HKEY_LOCAL_MACHINE\SORTWARE\Microsoft\Windows\CurrentVersion\App Paths" key.
A reg file like the following shows how:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\MyApp.exe]
#="C:\\Program Files\\MyCompany\\MyApp\\MyApp.exe"
"Path"="C:\\Program Files\\MyCompany\\MyApp\\MyDLLs"