2010-11-23 80 views
2

プロセスを使用してc#.netでexeファイルを実行しようとしています。Windowsサービスでプロセスが起動しない

System.InvalidOperationException:このオブジェクトに関連付けられているプロセスはありません。 System.Diagnostics.ProcessでSystem.Diagnostics.Process.GetProcessHandleでSystem.Diagnostics.Process.EnsureState(ステート状態) でSystem.Diagnostics.Process.EnsureState(ステート状態) (のInt32アクセス、ブールthrowIfExited) で 。 WaitForExit(のInt32ミリ秒)VideoHandlingWinService.VideoHandlingService.VideoHandling(文字列VideoNameでVideoHandlingWinService.VideoHandlingService.ConvertVideoToFlvでSystem.Diagnostics.Process.WaitForExit() (文字列関数savepath、文字WithOutExt、文字INPUTFILE、ストリングSPATH、のInt32 VideoQueueId) において、文字列SavePath、文字列InputFile、文字列WithOutExt、文字列spath、Int32 VideoQueueId、String VideoDescription、Int32 RegisteredUserId、Int32 CategoryId、String VideoTitle)at VideoHandlingWinService.V次のようにプロセスを開始するVideoHandlingWinService.VideoHandlingService.OnStart(文字列[] args)をでideoHandlingService.StartHandlingVideo()

私のコードは次のとおりです。

Process proc = new Process(); 
string spath = AppDomain.CurrentDomain.BaseDirectory.ToString(); 

try 
{ 
    proc.StartInfo.FileName = spath + "\\ffmpeg\\ffmpeg.exe"; 
    proc.StartInfo.Arguments = FilArgs; 
    proc.StartInfo.UseShellExecute = false; 
    proc.StartInfo.CreateNoWindow = false; 
    proc.StartInfo.RedirectStandardOutput = true; 
    proc.StartInfo.RedirectStandardError = true; 

    proc.Start(); 

    string StdOutVideo = proc.StandardOutput.ReadToEnd(); 
    string StdErrVideo = proc.StandardError.ReadToEnd();    
} 
catch { } 
finally 
{ 
    proc.WaitForExit(); 
    proc.Close(); 
} 

いずれこれを行う方法を教えてくださいWindowsサービス内。また、私はローカルアカウントとしてWindowsサービスを実行しており、exeの許可の問題がないことを願っています。私はエラーが

proc.WaitForExit(); 

で起こると考え

+2

空のキャッチブロックがあります。それを削除するか、そこにログインして実際に何が起こっているかを確認してください。 –

+0

多分あなたの空のキャッチが例外を飲み込み、プロセスが決して実行されなかったことを意味し、エラーメッセージを説明します。 – wj32

答えて

0

あなたはffmpegのが実行されていませんか?

MSDN

によればWaitForExit()()()オーバーロードを終了 関連プロセスまで、現在のスレッド ウェイトを製造するために使用 あります。このメソッドは、 プロセスの時間を無期限に待機し、 イベントハンドラを終了するように、プロセスコンポーネントに を指示します。

finally()ffmpegはすでに終了しています。

+0

put proc.WaitForExit(); proc.Close(); proc.start()の後に何かhppensを確認してください – Shoban

+0

例外は私のパスに起因していました.WSのサービスの場合、私はspathの完全な物理パスを与えることによって例外を取り除きました。 – Harun

1

とにかく使用​​

+0

例外は私のパスに起因していました.Windowsサービスの場合、私はspathの完全な物理パスを与えることで、outside.Nowで動作しているので、ルートパスを使用できません。 – Harun

関連する問題