I've been working on developing a program to manage symbolic links to folders, which has worked great, until I moved to continuing the work on a Windows 8 machine (from Windows 7). Since doing that, my CreateSymbolicLink()
method has returned an error code of 2.
This is the method I have that is called whenever I want to link a directory. Before this is called, the original folder has been moved to what is destDirName
public static void LinkDirectory(string sourceDirName, string destDirName)
{
if (!CreateSymbolicLink(sourceDirName, destDirName, 0x1))
{
MessageBox.Show("Error: Unable to create symbolic link. " +
"(Error Code: " + Marshal.GetLastWin32Error() + ")");
}
}
This is the imported method from kernel32.dll:
[DllImport("kernel32.dll")]
static extern bool CreateSymbolicLink(string lpSymlinkFileName,
string lpTargetFileName, int dwFlags);
And the logic:
FileFunctions.MoveDirectory(gameOriginalSaveFolder, gameGatheredSaveFolder);
FileFunctions.LinkDirectory(gameOriginalSaveFolder, gameGatheredSaveFolder);
FileFunctions.HideDirectory(gameOriginalSaveFolder);
Using a breakpoint, this is the locals that are sent with the above logic: https://i.stack.imgur.com/zl2Ns.png
To note, this code worked fine when I was developing it under Windows 7, but has suddenly stopped working since. I hope this is enough info to clear some stuff up, otherwise, please ask.