How to provide user name and password when connecting to a network share

后端 未结 11 1698
不知归路
不知归路 2020-11-22 00:34

When connecting to a network share for which the current user (in my case, a network enabled service user) has no rights, name and password have to be provided.

I kn

11条回答
  •  情话喂你
    2020-11-22 01:26

    One option that might work is using WindowsIdentity.Impersonate (and change the thread principal) to become the desired user, like so. Back to p/invoke, though, I'm afraid...

    Another cheeky (and equally far from ideal) option might be to spawn a process to do the work... ProcessStartInfo accepts a .UserName, .Password and .Domain.

    Finally - perhaps run the service in a dedicated account that has access? (removed as you have clarified that this isn't an option).

提交回复
热议问题