[DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool LogonUser(String lpszUsername, String lpszDomain, String lpszPassword,
    int dwLogonType, int dwLogonProvider, out SafeTokenHandle phToken);
...
LogonUser(userName, domainName, password,
            LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT,
            out safeTokenHandle);
...
using (WindowsIdentity newId = new WindowsIdentity(safeTokenHandle.DangerousGetHandle()))
            {
                using (WindowsImpersonationContext impersonatedUser = newId.Impersonate())
                {                    // Check the identity.
                    Console.WriteLine("After impersonation: "
                        + WindowsIdentity.GetCurrent().Name);                    //Do your coping here                }
            }
  
*****************************************************************************
签名档: http://feiyun0112.cnblogs.com/

解决方案 »

  1.   

    如果图省事的话我是否可以先在键盘上敲入:\100.110.120.155\AVS_FilePort\Input,等到输入用户名和密码窗口弹出时分别输入用户名和密码,再把"记住密码"打上勾,这样在程序代码中就可以不必再考虑有关输入用户名和密码的问题了?
    网址格式应采用哪种方式才算正确呢?
      

  2.   

    \\100.110.120.155\AVS_FilePort\Input
    这种格式对。
    另外,你在同事机器上共享一个文件夹,设置一个密码,测试一下就好了。
    不用什么都问的。