none
CreateSymbolicLink & SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE RRS feed

  • Question

  • Hi All,

    I am a beginner in C#. I have a problem with SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE flag in CreateSymbolicLink(). When I enable Developer Mode in my Windows 10 Enterprise (Version 1709 Build 16299.19) then I can create symbolic link without admins rights, but when I disable Dev Mode - this flag doesn't work ;/ I can't run this script without admin rights ;/

    So could I ask you to help me with this problem - do I need Developer Mode enable to use SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE flag ? 

    Below is my code - maybe there is some problem ? 

    using System;
    using System.Runtime.InteropServices;
    using System.IO;
    
    namespace link
    {
        public class symlink
        {
            [DllImport("kernel32.dll")]
            public static extern bool CreateSymbolicLink(string lpSymlinkFileName, string lpTargetFileName, int dwFlags);
            static int SYMBOLIC_LINK_FLAG_DIRECTORY = 0x1;
            static int SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE = 0x2;
            static int flag = 0x0;
            static void Main(string[] args)
            {
    
                string link = @"symlink_path";
                string directory = @"target_directory_path";
    
                flag = SYMBOLIC_LINK_FLAG_DIRECTORY | SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE;
                Console.WriteLine(flag);
                Console.ReadLine();
    
                CreateSymbolicLink(link, directory, flag);
                if (Directory.Exists(@"symlink_path"))
                {
                    Console.WriteLine("SYMLINK created for {0} <------> {1}", link, directory);
                    Console.ReadLine();
                }
                else
                {
                    Console.WriteLine("Symlink doesn't exist", link, directory);
                    Console.ReadLine();
                    Console.WriteLine();
                }
            }
        }
    }


    Thanks a lot for help!

    Regards,

    Kamil


    Thursday, October 26, 2017 3:32 PM

All replies

  • Hello kamilzelazny,

    >>Do I need Developer Mode enable to use SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE flag ?

    No, it also was possible for administrator users to create symbolic Link without dev model.

    In Developer Mode, a user account with any level of privileges can create symbolic links. Because setting Dev mode will reduce Symbolic Link Restrictions. Symbolic links are often used by developers , Setting dev model makes it possible for development tools to create and work with symbolic links without Administrator level.

    There are more details about setting enable dev model.

    https://www.howtogeek.com/292914/what-is-developer-mode-in-windows-10/

    Sincerely,

    Neil Hu

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, October 27, 2017 7:17 AM
    Moderator
  • Hello Kamil,

    Is there anything updated? If you have any issues about the replies , please feel free to contact me .

    Sincerely,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Sunday, October 29, 2017 4:53 AM
    Moderator