windows-7windows-10phantomjsmaven-javadoc-plugin

Windows10 cmd.exe default directory different to Windows7


I am seeing a difference in behaviour on the default directory when you execute cmd.exe when you are already inside a shell between Win7 and Win10.

Windows 7:

C:\projects\test>ver

Microsoft Windows [Version 6.1.7601]
     
C:\projects\test>cmd.exe
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
     
C:\projects\test>exit
     
C:\projects\test>

Windows 10:

C:\projects\test>ver
 
Microsoft Windows [Version 10.0.18363.1316]
 
C:\projects\test>cmd.exe
Microsoft Windows [Version 10.0.18363.1316]
(c) 2019 Microsoft Corporation. All rights reserved.
 
C:\Users\john>exit
 
C:\projects\test>

The problem I am facing is that, this difference in behaviour is causing some 3rd-party scripts to fail, as it assumed that when cmd.exe is executed, it was running in whatever was the default directory instead of the user's home directory or C:\Users\xxxx

For example:

  1. yarn install when the directory contains a package.json that has a dependency on phantomjs-prebuilt. It ends up looking for install.js in C:\Users\xxxx instead of in the node_modules\karma-phantomjs-launcher\node_modules\phantomjs_prebuilt directory.
  1. Maven's maven-javadoc-plugin when executing the jar goal dynamically creates a javadoc.bat and that BAT file specifically calls cmd.exe to execute javadoc. Essentially, the javadoc execution from the maven build fails in Windows10 due to this behaviour.

Solution

  • Found out the reason. There is a registry setting at the place I work that is applied corporate-wide to all Windows10 devices.

    An Autorun key in HKEY_CURRENT_USER\Software\Microsoft\Command Processor that changes the directory to the user's home directory.

    Delete this key and the behaviour is then consistent.