0

I'm getting mad with what (in my mind) should be an easy task: On my desktop (but could be anywhere) I have a folder "project", a "console.msc" and another folder "files" inside.

"console.msc" have a task that runs file1.bat and it works if I use full paths but it doesn't with relative ones.

c:\users\user1\Desktop\project\files\file1.bat WORKS

.\files\file1.bat DOESN'T WORK

I see that all the time, the custom mmc is lauched with elevated privileges (good, I want it) but the relative path used to call file1.bat just doesn't work and the error returned is "Windows cannot find [..]"

Does anybody know how to tell Windows to keep the current folder the mmc is run? Any clues welcomed! :-)

1 Answers1

0

Running a process with elevated privileges might result in different working directory for that process, that's why relative paths are not working.

If you do not want to use absolute paths, you have to find a way to get path to a directory where your application is located, and then append the relative paths to that.

You don't specify how you are running your tasks, but if it's from another .BAT file, then full path to the batch file's directory is stored under %~dp0 variable. You can look up answers to this question for more details.

And you can also always use tool like Process Explorer to view information about your running process, including working directory (it's called Current directory there).

michalk
  • 526
  • 3
  • 13
  • Hi and thanks for the tips ! I knew about %~dp0 and yes, it works if you run a batch file, but the problem comes from the MMC GUI. Anyway, I'll try the other variables you suggested ASAP :-) – Francesco Papini Sep 04 '18 at 12:15