WNetAddConnection2 from a Windows Service

后端 未结 5 1129
一向
一向 2021-01-01 06:50

I\'m trying to connect to a remote password protected shared folder from a Windows service, which runs as LocalSystem account. It seems that the LocalSystem account is unabl

5条回答
  •  南方客
    南方客 (楼主)
    2021-01-01 07:32

    I just encountered this problem as well, and found that if I put the remote computer name into the user name, it worked. (I didn't actually figure this out, we had another place in the code already doing this that worked, so I knew it was possible, and finally figured out the difference.)

    So for example:

    WNetAddConnection2(&nr, "password", "SomeComputer\\Username", 0);
    

    I'm not doing any other special calls like LogonUser or ImpersonateLoggedOnUser.

    This is in a service running under the SYSTEM account.

    I haven't tried using the SomeComputer\Administrator account, but that's not exactly a good practice anyway. I'm using a normal user account on SomeComputer.

提交回复
热议问题