How do I create a link in Windows 7 home premium as a regular user?

69

45

I am a Linux guy and as such I am very lost when I try and do anything is Windows. I am trying to create the following link:

mklink /d C:\backup\data \\myth\backup\data

But I do not have sufficient privilege to preform this operation. How do I get sufficient privileges in Windows 7?

UPDATE:

Right clicked on C:\backup\data and changed the permissions to full access for authenticated user, restarted the machine and tried the command again with no luck. Anyone have any further suggestions?

stephenmm

Posted 2010-03-27T05:50:49.927

Reputation: 1 197

Question was closed 2015-05-15T15:20:25.997

Make sure c:\backup\data doesn't already exist when you are trying to create the link as administrator. – David d C e Freitas – 2011-04-08T18:52:31.113

Answers

113

As stated here,

Creation of symbolic links requires the SeCreateSymbolicLinkPrivilege (“Create symbolic links”), which is granted only to administrators by default (but you can change that using security policy).

To change the policies:

  1. Right click on StartRun and launch secpol.msc.

  2. Open Security Settings → Local Policies → User Rights Assignment and select Create symbolic links (that represents SeCreateSymbolicLinkPrivilege).

enter image description here

  1. Double-click on the item and add yourself (or the whole Users group) to the list.

The changes will apply when you log out and log in again.

Hugh Allen

Posted 2010-03-27T05:50:49.927

Reputation: 8 620

this works for creating junctions but if creating sym links i still get the error message about not having sufficient permissions – vlad_tepesch – 2015-05-27T10:22:49.060

Why is windows so hard to automate? Where's the command line way to give the permission? – mjaggard – 2017-09-29T10:56:12.193

To enable GP_EDIT, see this: https://superuser.com/a/105381/249349

– T.Todua – 2018-10-11T11:03:51.713

2Note that on Win7, the 'Users' group wasn't visible for me until, from the dialog "Select Users or Groups", I clicked the "Object Types" button and added 'groups'. – Jonathan Hartley – 2012-01-08T18:19:03.467

7This doesn't work for me, regardless of whether I add my user, "Users", or "Everyone". I logged out, and I rebooted, but in my home dir, the command "mklink /D docs Dropbox" still gives me "You do not have sufficient privilege to perform this operation." Same result if I try on files instead of directories. – Jonathan Hartley – 2012-01-08T18:19:42.937

3My problem solved by Brandon Donnelson's answer: In addition to the above, the user running "mklink" cannot be an administrator. – Jonathan Hartley – 2012-01-08T18:42:37.350

@Jonathan. didn't work for me. And it seems silly, or maybe I'm misunderstanding. Windows 7 doesn't allow an administrator to create symbolic links, but only non-administrators after an administrator gives them privledges??? – Ben – 2012-03-19T13:26:42.853

4@Ben I agree it seems barmy. On reflection though, I think I solved my problem by running the 'cmd' window by right clicking and choosing 'run as admin'. Someone explained to me that when launching a process, Windows strips admin privs from it, unless you choose 'run as admin'. At that point, if you are not an admin, you have to enter an admin password. If you are already admin, then you don't have to enter anything. Perhaps that allowed me to run 'mklink' from within the cmd window. – Jonathan Hartley – 2012-03-19T23:17:44.280

@Johnathan, I think you're correct. I've made a little progress on this for my own need here: http://superuser.com/q/402390/123731 but I'm running into other problems now (if you care to take a look :) )

– Ben – 2012-03-20T13:43:23.057

19

I just discovered that I can create a 'Junction' even when I can't create a symlink:

mklink [/D] /J junctionname filename

where /J indicates 'create a junction', and the /D is, I believe, for if the named file is a directory. (my user is currently an administrator)

However, a junction to a 'bat' file doesn't seem to be executable, so this isn't actually any use.

Does anyone understand why this is, or how it can be fixed to provide an alternative approach to the OP's problem?

Jonathan Hartley

Posted 2010-03-27T05:50:49.927

Reputation: 736

11You can create a hardlink (mklink /H) without admin privileges, and that will be executable. Hardlinks are for files, junctions are for directories, symlinks are for both (and /D is used to indicate that a symlink is for a directory). – Brilliand – 2013-01-03T20:49:11.103

3Junctions and hardlinks are both useless for the example in the OP, though, because neither of them can point to a network drive (hardlinks are limited to same partition, junctions are limited to local drives); only a symlink or Windows shortcut can do that. – Brilliand – 2013-01-03T21:29:05.447

12

I found only a non administrator can do it. Add non administrator to create symbolic links and runas non administrator. You'll have to add a person of with non admin privileges. Then you give permission to the target for the non admin, so he can do the runas mklink.

Brandon Donnelson

Posted 2010-03-27T05:50:49.927

Reputation: 121

1This totally solved my problem: My user is an adminstrator, but "mklink" would not work until I enabled the "guest" account, call "runas /user:guest cmd" and then run mklink from that new cmd session. It also required temporarily granting perms so that the guest account could cd into and modify my home directory, where I wanted the symlink, which causes a flurry of error dialogs, but they seemed harmles. – Jonathan Hartley – 2012-01-08T18:41:35.243

For the record, "mklink" doesn't work for my regular user which is an administrator, but does work either when launched from a cmd which has been "runas /user:guest cmd" (I couldn't figure out the quoting required to directly run the mklink command as user guest) or when I remove my own account from the 'administrators' group. – Jonathan Hartley – 2012-01-10T00:49:59.327

3It also worth noting that it is possible to run mklink successfully with an account that has admin rights. But that requires UAC to be turned off. – Vladimir Sizikov – 2013-08-14T21:47:46.293

2

Came across this problem today as well. I had a NAnt build task trying to create symbolic links on a computer. Was getting rejected for lack of privileges. I found this post which helped solve my problem: http://josh.mainelan.net/tag/mklink/.

The relevant section:

  1. Bring up your run box, type “secpol.msc” and click OK.
  2. Navigate under the Security Settings \ Local Policies \ User Rights Assignment folder.
  3. Find “Create symbolic links” and add the Users group to it.

I think you need to restart your computer or something after doing this.

Matt

Posted 2010-03-27T05:50:49.927

Reputation: 1 857

2

The above solutions didn't work for me because not only could I not create a "guest" user on my machine, I can't possibly ask all the users of my tools to do so too on their machines. Nor is it reasonable to require they use Administrator consoles.

My solution is to use: elevate.cmd and elevate.vbs

  1. Download from: http://technet.microsoft.com/en-us/magazine/2008.06.elevation.aspx
  2. Put those two files on your system path (or somewhere convenient on the network)
  3. elevate.cmd cmd /c "cd /d LINK_DIR && mklink /D LINK_NAME LINK_TARGET_PATH"

Cons: elevate.cmd returns immediately but answering the UAC dialog takes time. This forced me to add a "did you ok the UAC dialog yet?" question to my script. It is possible to skip "elevate.cmd" by checking the exit code for the following command: whoami /groups | find "S-1-16-12288" (exit code 0 means you have an Adminstrator console).

Denkkar

Posted 2010-03-27T05:50:49.927

Reputation: 21

1

Run the command prompt as administrator to execute this command.

Type cmd (or command) in the start menu and right click on it and choose "run as an administrator".

Now any command that you execute will be executed with administrator privileges.

teknikqa

Posted 2010-03-27T05:50:49.927

Reputation: 412

As others have mentioned, SeCreateSymbolicLinkPrivilege is what is required. However, even if you are the administrator in Windows 7, most programs are not run with administrative privileges. To get administrative privileges for a program, follow the steps I mentioned above. – teknikqa – 2010-04-03T23:49:06.543

I think he knows about running as administrator that's why he is asking the question – barlop – 2018-01-21T09:45:13.480

-6

I'd recommend Ultimate Windows Tweaker. Use it to Select "Show Take Ownership" to get around the permissions issue, and "Show Open Command Window Here" to open command prompt at the correct folder.

alt text

outsideblasts

Posted 2010-03-27T05:50:49.927

Reputation: 6 297

Installed, opened explorer and right clicked on the folder to be linked and "took ownership" then opened command window from here. Ran the above mklink command and got the same error again. – stephenmm – 2010-03-28T03:14:57.980

Aw well, worth a try. As a recent Windows -> Linux user, I can sympathize fully about things not working and not knowing why. Good luck. – outsideblasts – 2010-03-28T06:38:37.017

1-1 Try trying it yourself before posting it then you'd see it doesn't work – barlop – 2018-01-21T09:46:18.737

6Ironically enough, neither taking ownership nor Show Command prompt gives you admin privileges. Just like in Linux. – surfasb – 2011-07-06T22:22:48.470