Network Authentication when running exe from WMI

前端 未结 4 1882
一整个雨季
一整个雨季 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:08

    I know you've sorted it by using PSEXEC, which is a fantastic program, but if you did want to go back to WMI, have you tried enabling the following in your ConnectionOptions:

    • The flag EnablePrivileges
    • setting the Impersonation to ImpersonationLevel.Impersonate

    Which does the following:

    Gets or sets a value indicating whether user privileges need to be enabled for the connection operation. This property should only be used when the operation performed requires a certain user privilege to be enabled (for example, a machine restart).

    http://msdn.microsoft.com/en-us/library/system.management.connectionoptions.enableprivileges.aspx


    Gets or sets the COM impersonation level to be used for operations in this connection.

    http://msdn.microsoft.com/en-us/library/system.management.connectionoptions.impersonation.aspx

    I think they should tell your WMI to actually allow the program to have the correct credentials and thus access your network share

提交回复
热议问题