Reputation: 1
My C++ program is in a directory (A
). After running ShellExecute()
through this program, I open an application XShell, close my C++ program, and then I find that in the resource monitor, the A
directory is occupied by the program XShell I enabled. How to solve it?
ShellExecuteW(NULL, L"open", L"D:\\Program Files\\NetSarang\\Xshell 6\\Xshell.exe", NULL, NULL, SW_SHOWDEFAULT)
After the C++ program exits, XShell occupies my C++ program directory.
I hope that after opening an application through ShellExecute()
, this application does not occupy the directory of the C++ program.
Upvotes: 0
Views: 123
Reputation: 13582
The directory is occupied because the secondary program is inheriting that directory as its working directory. To avoid that, you can specify the desired working directory that the secondary program should use in the lpDirectory
parameter of ShellExecuteW()
:
https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecutew
[in, optional] lpDirectory
Type:
LPCTSTR
A pointer to a null-terminated string that specifies the default (working) directory for the action. If this value is
NULL
, the current working directory is used. If a relative path is provided at lpFile, do not use a relative path for lpDirectory.
For example, you can specify "C:\\"
(which should always exist and be accessible).
Upvotes: 3