我用c#写了一个Service,它会自动的打开一个局域网中的另一台机器上的Excel但是这个机器需要用户名和密码才能查看它的共享目录,有什么方法,可以让我的程序open那个excel前,先登陆一下。给个建议:)
我知道把那个目录设置为public全部可以读,就可以,但我想先用登陆的方法试试。

解决方案 »

  1.   

    [DllImport("advapi32.dll")]
            public static extern int LogonUserA(String lpszUserName,
                                                String lpszDomain,
                                                String lpszPassword,
                                                int dwLogonType,
                                                int dwLogonProvider,
                                                ref IntPtr phToken);
    -------------------------IntPtr admin_token = new IntPtr();
     LogonUserA(name, domain, password, 9, 0, ref admin_token);---------------admin_token 有些用处.
      

  2.   

    google 一下这个词  "Account Impersonate"
      

  3.   

    我用 account impersonation 可以用 LogonUserA ,总是返回 1 ,不知道为什么