[Tutor] subprocess.Popen(..., cwd) and UNC paths

eryksun eryksun at gmail.com
Thu Apr 30 03:28:13 CEST 2015


On Wed, Apr 29, 2015 at 7:48 PM, eryksun <eryksun at gmail.com> wrote:
> cmd.exe was developed for OS/2 (1987) to replace COMMAND.COM (1981).

Actually, I stand corrected about the reason being cmd's 1980s
crustiness. Per [KB156276][1] this check was added to NT 4.0 (1996) to
address a vaguely described problem ("a UNC name may cause problems
with child processes launched from such a console when that console is
exited or halted"), which may not even be a problem nowadays (Windows
7+) since the console was moved out of CSRSS.EXE (the Windows session
server) into instances of conhost.exe that run in the security context
of the client. Try adding the registry setting to disable this check.
Probably nothing bad will happen. Here's a reg.exe command to disable
the check for the current user:

    reg add "HKCU\Software\Microsoft\Command Processor"
        /v DisableUNCCheck /t REG_DWORD /d 1

After disabling the check, my previous example should work fine:

    (test) C:\Temp>python
    Python 3.4.2 (v3.4.2:ab2c023a9432, Oct  6 2014, 22:16:31) [MSC
v.1600 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import os, subprocess
    >>> os.chdir(r'\\127.0.0.1\C$')
    >>> subprocess.call('cmd')
    Microsoft Windows [Version 6.1.7601]
    Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

    (test) \\127.0.0.1\C$>

[1]: https://support.microsoft.com/en-us/kb/156276


More information about the Tutor mailing list