C# 用户名和密码放在哪里;远程计算机允许从桌面应用程序访问文件所需的密码

C# 用户名和密码放在哪里;远程计算机允许从桌面应用程序访问文件所需的密码,c#,C#,请勾选这个插图 在哪里放置桌面应用程序通过IP访问本地网络中服务器共享目录中的文件所需的用户名和密码 string var_main_dir = @"\\192.168.1.244\c$\repository"; 在这一行之后,应用程序连接到服务器,但停止,并显示有关的调试错误消息 用户名和密码无效 An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll 附加信息:用户名和密码在连接到服

请勾选这个插图

在哪里放置桌面应用程序通过IP访问本地网络中服务器共享目录中的文件所需的用户名和密码

string var_main_dir = @"\\192.168.1.244\c$\repository";
在这一行之后,应用程序连接到服务器,但停止,并显示有关的调试错误消息

用户名和密码无效

An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll

附加信息:用户名和密码在连接到服务器之前,您需要使用您拥有的用户名和密码模拟登录。以下堆栈溢出应该对编写该代码有所帮助:

缩写版本为:

    public Impersonation(string domain, string username, string password)
    {
        var ok = LogonUser(username, domain, password,
                       LOGON32_LOGON_NEW_CREDENTIALS, 0, out this._handle);
        if (!ok)
        {
            var errorCode = Marshal.GetLastWin32Error();
            throw new ApplicationException(string.Format("Could not impersonate the elevated user.  LogonUser returned error code {0}.", errorCode));
        }

        this._context = WindowsIdentity.Impersonate(this._handle.DangerousGetHandle());
    }

祝你好运

还有我曾经写过的。@Uwe Kiem,如何使用你的类。我是否创建了新类?然后贴在那里?