Adding a Application specific paths, so it works f

2020-03-22 07:01发布

问题:

Following the guide from Microsoft, http://msdn.microsoft.com/en-us/library/ee872121(VS.85).aspx , I am able to get my program to be able to make a program resolve the dynamic libraries that are required in order for it to work.

So I add a value with the full name and path to my executable, and add subkey to this entry (named path) with the full path the directory of the DLL files.

And magic. It works. I go the start menu, and types myprogram.exe and it starts up and is now able to locate the dll files correctly.

However, if I start the command prompt using the command cmd.exe, and then try to run myprogram.exe is not able to resolve the DLL's anymore. For some reason the command prompt do not seems to respect/read the values of the registry when it is set under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths

Any suggestion to how I can get this behavior to work from within the command prompt as well as from the start menu?

回答1:

It is correct. HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths is used by ShellExecuteEx and not by CreateProcess. So not all programs will use the settings from App Paths of your application. If you want to define PATH for cmd.exe you can either use subkey of App Paths with the name cmd.exe or use an old %SystemRoot%\System32\autoexec.nt file to modify PATH environment variable.



回答2:

It's also possible to use "START /WAIT app.exe" from command line which uses ShellExecuteEx.



回答3:

I'll give it my best shot.

First, notice that both the cmd & the run\start menu options are running everything in C:\WINDOWS\system32.

If you're dll was there then it would work.

if you don't want to put it there, you can change the "environmental variables" by clicking right mouse button on "my computer"-> "properties" -> "Advanced" -> "environmental variables".

good luck.