2017-05-21 19 views
0

異なるユーザーでプロセスを実行しようとしています。私は通常の "notepad.exe"を実行すると正常に動作します。しかし、ファイルをフルパス(C:\\ Program Files \\ Microsoft Office \\ Office15 \\ Excel.exe)または(C:\\ Program Files(x86)\\ Adob​​e \\ Acrobat Reader DC \\ Reader \\ AcroRd32.exe)は動作しません。代わりに写真に添付されたようなエラーを出します。C#プロセスの開始偽装エラー

提案がありますか?

enter image description hereenter image description here

static void Main(string[] args) 
     { 
      SecureString securePwd = new SecureString(); 

      string password = "[email protected]"; 
      SecureString sec_pass = new SecureString(); 
      Array.ForEach(password.ToArray(), sec_pass.AppendChar); 
      sec_pass.MakeReadOnly(); 

      Process p = new Process(); 

      ProcessStartInfo ps = new ProcessStartInfo(); 

      p.StartInfo.FileName = "notepad.exe"; 
      p.StartInfo.Arguments = "C:\\Program Files (x86)\\Adobe\\Acrobat Reader DC\\Reader\\welcome.pdf"; 
      p.StartInfo.WorkingDirectory = "C:\\Program Files (x86)\\Adobe\\Acrobat Reader DC\\Reader\\"; 
      p.StartInfo.ErrorDialog = true; 
      p.StartInfo.EnvironmentVariables.Add("TempPath", "C:\\Temp"); 
      p.StartInfo.Domain = "testdom"; 
      p.StartInfo.UserName = "testuser"; 
      p.StartInfo.Password = sec_pass; 
      p.StartInfo.RedirectStandardError = false; 
      p.StartInfo.RedirectStandardOutput = true; 
      p.StartInfo.UseShellExecute = false; 
      p.Start(); 

      StreamReader myStreamReader = p.StandardOutput; 
      // Read the standard error of net.exe and write it on to console. 
      Console.WriteLine(myStreamReader.ReadLine()); 
      p.Close(); 

     } 
+0

助手席.... .... –

答えて

1

をチェックします。私はすべてのOffice製品がそうであると確信しています。Acrobatでもそうであれば驚くことはありません。

まず、ProcessStartInfoLoadUserProfiletrueに設定されていることを確認してください。そので十分です。

ただし、アプリケーションによっては、その後の起動とはまったく異なる動作が行われることもあります。そのため、これらのアプリケーションをそれぞれ対象とするターゲットユーザーとして少なくとも1回は起動していることを確認してくださいあなたは実際にマシンとしてというユーザーにログオンしています(そのユーザーとして単一のプロセスを起動するのではなく)。

+0

はい。 LoadUserProfile = trueを設定すると問題が解決しました。ありがとう。 –

0

あなたがメモ帳でPDF文書を開こうとすると、あなたのコード例で。

ただのメモ帳は、任意のユーザー固有の設定を保存しない代わりにnotepad.exeをの(あなたはexeファイルへのパスを追加する必要があるかもしれません)は、Adobe exeファイルにファイル名を変更したときに何が起こるか、

関連する問題