ever since they were first introduced, creating a symbolic link required a full administrator. Running from a normal or from a non-elevated process CreateSymbolicLink would fail.
In windows 10, CreateSymbolicLink fails as well in these circumstances, that is it doesn't create anything, however it returns a success code (!) and GetLastError is 0 too. So there's no way to detect the error other than checking if the symlink file exists
Looks like a bug in windows 10?
Have experienced the same. But: The success code you seem to get is an error code. So it seems the have changed the return type of CreateSymbolicLink from BOOLEAN to int
This workarround works for me:
Change the return value into an integer.
1 = success
for all other values call GetLastWin32Error
[DllImport("kernel32.dll", EntryPoint = "CreateSymbolicLinkW", CharSet = CharSet.Unicode, SetLastError = true)]
static extern int CreateSymbolicLink(string lpSymlinkFileName, string lpTargetFileName, SYMBOLIC_LINK_FLAG dwFlags);
public static int CreateSymbolicLinkFix(string lpSymlinkFileName, string lpTargetFileName, int dwFlags) {
var result = CreateSymbolicLink(lpSymlinkFileName, lpTargetFileName, dwFlags);
if (result == 1) return 0; // Success
return Marshal.GetLastWin32Error();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With