I had a simple batch file I would use in Windows XP to create a set of specific subfolders inside a folder. I had it set up as a Right-Click context menu so that when I right-clicked on a folder within Windows Explorer, I could execute the batch file and have the 10 specific folders created inside it.

I moved the same batch file to Windows 7. I can run the batch file manually and it works fine, however when I run it from the Right-click context menu, the folders are all created in the \Windows\System32\ directory, not in the colder that I had right-clicked upon.

I know that the "Current Directory" in Windows XP used to carry the value of the right-clicked folder, now in Windows 7 the Current Directory value seems to change to the System32 folder.

I was trying to find a way to read the current directory that the mouse right-clicked on, but cannot find that value. "CD" is the System32 folder at the start of the batch execution.

Any suggestions?

  • How are you adding it to the right-click menu? – nhinkle Apr 4 '11 at 17:31
  • Are you using relative paths or absolute paths in the script? Windows 7 changed a lot of the paths, so it may be defaulting to where the batch file executer is if it can't find the path. – beatgammit Apr 4 '11 at 17:35
  • It would help if you posted the script itself. I have a feeling that it has to do with the paths specified in the file and where the batch file is located. It also probably has a lot to do with the exact registry entries that were used to make it available in the right click context menu. In batch, %CD% will be the path that the batch file is run from. – MaQleod Apr 4 '11 at 18:54

You can change the command entry in the registry to add a parameter:

C:\Users\Me\Batches\make_dir.cmd "%1"

and then use that parameter in the batch file:

cd /d "%1"
md SomeDirectory
md SomeOtherDirectory

As for the confusion, I guess the working directory of the process that is started for a shell command was never really specified so it could be anything. And Windows 7 introduced libraries which probably could lead to folders residing in »non-paths«.

  • My registry entries were simply to HKCR\Directory\Shell\ where I added the Key "CreateFolders" and the command pointing to the batch file. It works, But it is only placing the folders in the System32 directory. It does not consider the "Current Directory" to be the folder that I am right-clicking on, which is what WinXP used to do. There are no paths in the script, only MD commands, so a very simple script. – Calvin Apr 4 '11 at 19:53
  • The suggestion by Joey worked. Thanks very much. Cal – Calvin Apr 4 '11 at 20:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.