What's the meaning of "NoWorkingDirectory" string value in Windows Registry?

8

3

Empty "NoWorkingDirectory" string value is often used in Windows Registry when user-defined Right-Click menu items are created. For example to be able to open PowerShell when right-clicking on folder backround in Windows Explorer (as opposed to right-clicking on folder itself, in that case "NoWorkingDirectory" is not used):

[HKEY_CLASSES_ROOT\Directory\Background\shell\powershell]
@="Open PowerShell Here"
"NoWorkingDirectory"=""

[HKEY_CLASSES_ROOT\Directory\Background\shell\powershell\command]
@="C:\\\\Windows\\\\System32\\\\WindowsPowerShell\\\\v1.0\\\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'"

However, I am not clear on actual purpose of this value. It is always used empty in all samples I found. What exactly does it signify?

Joe Schmoe

Posted 2014-01-17T20:40:31.133

Reputation: 575

I would imagine if there was a directory value it would only work in that directory. Do you have other examples? – Ramhound – 2014-01-17T20:48:10.260

http://www.randyrants.com/2007/02/vista_tip_eleva.html – Joe Schmoe – 2014-01-17T20:52:39.120

My guess is that it's the folder used to execute from if there's no Working Folder provided when the shell command is called (similar to the "Start In:" option in a Shortcut's properties). When empty it probably assumes the current folder. But again, this is just guessing. ;) – Ƭᴇcʜιᴇ007 – 2014-01-17T21:47:26.547

Answers

9

WorkingDirectory is a property of the System.Diagnostics.ProcessStartInfo, when you Right Click, you are starting a new process and this setting allows you to start a process without the current directory becoming the "Working Directory". It then defaults to the System32 for the command being run.

So you would use "NoWorkingDirectory" when you are not wanting the location right clicked to become part of the environmental path for the duration of the script. Useless setting in 90% of cases, unless you have similar named files in multiple path locations which could get sticky unless "NoWorkingDirectory" is specified.

See more details here.

http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.workingdirectory%28v=vs.110%29.aspx

Knuckle-Dragger

Posted 2014-01-17T20:40:31.133

Reputation: 1 817

For instance, if I have a copy of DISM in a folder and right click on it, "NoWorkingDirectory" would allow me to access the copy in System32 over the one in the directory I right clicked on. See, it's kinda useless because more often than not I want the copy in the folder I clicked on. – Knuckle-Dragger – 2014-01-21T13:32:56.483

1

The "NoWorkingDirectory" verb property is undocumented so this is just a guess:

Cmd.exe does not support remote shares (UNC) as the current directory and if you start Cmd.exe with such a working directory it will print a warning message to the console.

If you look at the "Open command window here" registration you will see that it starts Cmd.exe with the pushd command and pushd does support UNC paths. NoWorkingDirectory is just there to avoid displaying a warning message.

It is not really required for PowerShell.

Anders

Posted 2014-01-17T20:40:31.133

Reputation: 421