Network Authentication when running exe from WMI

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

    Having followed the link suggested by Isalamon above (thanks) I followed Jestro's advice and have rewritten using psexec.exe (which can be downloaded from http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx) instead of WMI. It feels like a bit of a kludge to do it this way, but it seems to work.

    New code for anyone who is experiencing similar problems:

    Process proc = new Process();
    proc.StartInfo.FileName = "PsExec.exe";
    proc.StartInfo.Arguments = string.Format("\\\\{0} -d -u {1}\\{2} -p {3} {4}",
                                             remoteHost,
                                             domain,
                                             username,
                                             password,
                                             commandLine);
    proc.StartInfo.CreateNoWindow = true;
    proc.StartInfo.UseShellExecute = false;
    proc.Start();
    

提交回复
热议问题