2

If I understand this doc correctly: https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=cmd all calls should work with long path. I have Windows 10 version 1909 and the registry key Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled set to 1, I am unable to start a process in a long path:

In C#

using var process = new Process();
var processInfo = new ProcessStartInfo
{
    WorkingDirectory = "C:\\Long\\Path", // Or "\\\\?\\C:\\Long\\Path"
    FileName = "powershell",
};
process.StartInfo = processInfo;

process.Start();

Or in java

ProcessBuilder pb = new ProcessBuilder("cmd", "/c", "start", "powershell");
pb.directory("C:\\Long\\Path");
Process myProcess = pb.start();

I end up having an IOException: 'The directory name is invalid'

Also, git doesn't work when the current directory is the long path: I see a new console for half a sec. But all file manipulations are working fine (create, move, copy, delete)

Am I doing something wrong? Am I missing the doc section about the current directory? Is it a bug / missing feature?

Milad Dastan Zand
  • 1,062
  • 1
  • 10
  • 21
Olivier D
  • 64
  • 4
  • Did you include longPathAware to the application manifest? – Klaus Gütter Oct 25 '21 at 12:59
  • Use the fully-qualified filename or add the path to the PATH environment variable for the process (`ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.EnvironmentVariables["PATH"] = ...` – Tu deschizi eu inchid Oct 25 '21 at 13:04
  • For Powershell, it's not necessary to use Process. Download/install the NuGet package. (ex: Microsoft.PowerShell.5.1.ReferenceAssemblies , Microsoft.PowerShell... , System.Management.Automation , ...) – Tu deschizi eu inchid Oct 25 '21 at 13:11
  • @KlausGütter Yes user9938 This is not possible, I want to run powershell script and all path are relative to the current directory. – Olivier D Oct 25 '21 at 13:13

0 Answers0