Network Authentication when running exe from WMI

前端 未结 4 1894
一整个雨季
一整个雨季 2021-02-04 12:01

I have a C# exe that needs to be run using WMI and access a network share. However, when I access the share I get an UnauthorizedAccessException. If I run the exe directly the s

4条回答
  •  面向向阳花
    2021-02-04 12:22

    WMI just uses impersonation when executing the remote process, which does not give you network access. If you are ok going outside managed code, you can just map a UNC path in the remote process WMI started using whatever credentials you want. Then, you have the network access you want. I use NetUseAdd and NetUseDel from netapi32.dll to map the UNC path. See http://pinvoke.net/ for details on the using the APIs.

提交回复
热议问题