Open a shared file under another user and domain?

前端 未结 3 1128
一生所求
一生所求 2020-12-06 03:47

I have a C# console application that needs to read a shared file on a machine in another domain. When the application tries to access the file an exception occurs as the loc

3条回答
  •  独厮守ぢ
    2020-12-06 04:32

    a) p/invoke LogonUser with LOGON32_LOGON_NEW_CREDENTIALS and create a new WindowsIdentity with the new token, then use normal file access.

    b) p/invoke WNetAddConnection3. Be advised that this makes your remote share accessible to every other process on your machine.

    c) WMI via System.Management and CIM_DataFile; you won't even need p/invoke. System.Management lets you specify credentials for remote machine.

提交回复
热议问题