10

i'm creating symbolic links on Windows using a command like this :

cmd /c mklink /J "${linkName.canonicalPath}" "${targetFolder.canonicalPath}"

From Groovy and using Runtime.getRuntime().exec() method

It's working fine but i want do the same using java.nio.Files.createSymbolicLink() method. But I always obtain the same error message:

java.nio.file.FileSystemException: A required privilege is not held by the client.

The mklink /J command works for the current user and i want avoid elevate privileges

Bass
  • 4,977
  • 2
  • 36
  • 82
F.Rosado
  • 487
  • 4
  • 20
  • 2
    http://stackoverflow.com/questions/8228030/getting-filesystemexception-a-required-privilege-is-not-held-by-the-client-usi – tim_yates Apr 22 '14 at 10:58
  • You can also use the Java `Files` class: [`Files.createSymbolicLink( ... )`](https://docs.oracle.com/javase/8/docs/api/java/nio/file/Files.html#createSymbolicLink-java.nio.file.Path-java.nio.file.Path-java.nio.file.attribute.FileAttribute...-) – will Jan 15 '18 at 01:55

1 Answers1

20

With Windows (W7), you can add a user to the list of who may create symbolic links (without disabling UAC) using security policies.

  • Run secpol.msc
  • Go to Security Settings|Local Policies|User Rights Assignment|Create symbolic links
  • Add your user name.
  • Restart your session (logoff+login, no need to restart Windows).
mins
  • 6,478
  • 12
  • 56
  • 75
  • Thanks, it's the solution that i was looking for. – F.Rosado Jun 26 '14 at 06:49
  • 3
    *Win10 with UAC turned off* - I had to set `Local Policies > Security Options > User Account Control: Run all administrators in Admin Approval Mode` = `Disabled` - otherwise - same `FileSystemException: A required privilege is not held by the client` – Xtra Coder Aug 16 '17 at 22:43
  • jbang brought me here – Begui Oct 12 '21 at 19:12