问题与创建到目录的符号链接

问题描述:

我一直致力于开发一个程序来管理符号链接到文件夹中,这伟大的工作,直到我搬到继续在Windows 8机器上工作(从Windows 7)。因为这样做,我的 CreateSymbolicLink()方法返回的2错误code。

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.

这是方法我有一个被称为每当我想链接的目录。在此之前被调用时,原来的文件夹已被移动到什么 destDirName

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() + ")"); 
    }
}

这是从KERNEL32.DLL导入的方法:

This is the imported method from kernel32.dll:

[DllImport("kernel32.dll")]
static extern bool CreateSymbolicLink(string lpSymlinkFileName, 
    string lpTargetFileName, int dwFlags); 

和逻辑:

FileFunctions.MoveDirectory(gameOriginalSaveFolder, gameGatheredSaveFolder);
FileFunctions.LinkDirectory(gameOriginalSaveFolder, gameGatheredSaveFolder);
FileFunctions.HideDirectory(gameOriginalSaveFolder);

使用断点,这是发送上述逻辑当地人:的http://我。 imgur.com/T2Xahsq.png

要注意,这code工作得很好,当我开发它在Windows 7下,却突然停止工作至今。我希望这是足够的信息,以清除一些东西了,否则,请询问。

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.

本新的玩弄后,我设法找到了,这是一个权限问题,因为你不能把用户账户控制完全关闭在Windows 8。这样,开发环境Visual Studio的用途并没有升高,无法运行该程序。

After playing around with this further, I managed to find out that this is a permissions issue, as you cannot turn User Account Control off entirely in Windows 8. As such, the development environment that Visual Studio uses was not elevated and could not run the program.

我设法按照这里介绍的步骤来解决问题:http://stackoverflow.com/a/12859334/1862405

I managed to solve the issue by following the steps outlined here: http://stackoverflow.com/a/12859334/1862405