0

I am trying to create symbolic links. My development platform is Windows. In my groovy script I used createSymbolicLink() method of java.nio.file.Files class to accomplish this.

However, it is required (perhaps by Windows) that I run the script from within an admin command prompt, otherwise I get below exception :

> Exception in thread "main" java.nio.file.FileSystemException:
> C:\Users\...\Desktop\SymLinkPOC\...\symlinkOfabc\abc.txt: A required
> privilege is not held by the client.

Is there any way I can get this script to work without needing to run it from within the administrator command prompt.

I also have a gradle task from which this script will be executed(using task type JavaExec). I can execute the gradle task successfully ,but only from within the admin command prompt.

gradle task :

task runScript (dependsOn: 'classes', type: JavaExec) {
    main = 'myscript'
    classpath = sourceSets.main.runtimeClasspath    
}

Is there a way I can make the gradle task execute with admin privilege, without needing to provide admin credentials manually(by manually I mean, the script asking me to enter the credentials at the command prompt)?

If not, then is there a way to provide admin credentials(inside the task or script or at least tell the script how to get it) and then tell it to run ?

I can sense my requirements might be going against the best coding practices I'm not sure how to get around this.

My main concern is how to get the script to run without any human intervention, as this script is going to be part of the Jenkins pipeline.

Looked all over the internet, but no luck.

Let me know if I missed out on any details.

Thanks in advance.

Asif Kamran Malick
  • 2,409
  • 3
  • 25
  • 47
  • Does the comment on [this question](https://stackoverflow.com/questions/8228030/getting-filesystemexception-a-required-privilege-is-not-held-by-the-client-usi) help: _"...Run "secpol.msc" and change "Security Settings|Local Policies|User Rights Assignment|Create symbolic links""_ – tim_yates Jan 08 '20 at 08:14
  • ie: change the policy for the user jenkins is running under to allow them to create symbolic links? – tim_yates Jan 08 '20 at 08:14
  • 1
    Does this answer your question? [How to create Soft symbolic Link using java.nio.Files](https://stackoverflow.com/questions/23217460/how-to-create-soft-symbolic-link-using-java-nio-files) – thokuest Jan 08 '20 at 08:15
  • @thokuest,@tim_yates I came across that solution earlier. but was hesitant to try it. I always though I had admin privileges as I could run any program as administrator. Anyways, this worked. I no longer have to run the script through admin command prompt. – Asif Kamran Malick Jan 08 '20 at 09:11
  • for Jenkins, I haven't tried it yet.Will let you know once I am done testing it – Asif Kamran Malick Jan 08 '20 at 09:12

0 Answers0