3

I have registered a custom protocol handler in the windows registry so I can launch my application with specific arguments from my Internet-Browser. So far the registration works fine. Both IE and Chrome are launching my application.

I used Erwinus answer in this question to register the protocol handler: how do I create my own URL protocol? (e.g. so://...)

Strangely the working directory is not set correctly by both browsers. Chrome seems to default the Working directory to an empty string whereas IE defaults the working directory to "C:\Users\User-X\Desktop".

Is this behaviour intended?
Is there any way to specify the working directory for my application in the registry?

Thanks in advance for any leads on this issue.

Community
  • 1
  • 1
Pete
  • 41
  • 3
  • In your mind, what is the correct working directory for a URL protocol? – Anders Apr 26 '17 at 21:30
  • Can you not make your application simply not care about the working directory? – Alex K. Apr 27 '17 at 11:31
  • @Anders The working directory is not related to the URL protocol itself but the browser (or OS's) job to set the working directory correctly when launching the application. So in my mind the working directory should just be set to the directory my *.exe resides in. – Pete Apr 27 '17 at 11:43
  • @Pete did you managed to find answer for this problem. Seems I am in the same state. Have raised query https://stackoverflow.com/questions/68577785/how-to-make-url-protocol-to-launch-application-from-its-own-directory-instead – user1066231 Jul 29 '21 at 15:04

2 Answers2

0

The working directory is connected to the command line arguments to resolve paths like .\file.ext and since there is no relative path parameter the working directory should not matter.

Your application should not depend on the working directory to load libraries and other application specific files.

There is a undocumented value named NoWorkingDirectory that can be set on file type registrations but I'm not sure if it applies to URL protocols.

Anders
  • 97,548
  • 12
  • 110
  • 164
0

Its been a while since no one correct answer is here, I was facing same issue and had found the answer. So , posting it here so, it is helpful for others.

Include change directory in the URL protocol(registry entry), so that working directory is changed before launching the application. Lets say if you had created URL protocol named "ProtoTest2", and wanted to run your application from directory "C:\Source\For Ref\URL Protocol\BatchTest", then the command below updates the command entry of the URL protocol in registry. First change the directory to desired location and launch the application. Detailed example is available in this question How to make "URL Protocol" to launch application from its own directory instead of launching from c:\windows\system32?

reg add HKEY_CLASSES_ROOT\ProtoTest2\shell\open\command /t REG_EXPAND_SZ /d "%ComSpec% /C \"cd /D \"C:\Source\For Ref\URL Protocol\BatchTest\" ^& showPath.bat\"" /f
user1066231
  • 551
  • 1
  • 7
  • 27