2012-01-20 9 views
3

スクリーンショットを作成するには次のコードがありますが、コマンドプロンプトを開いてユーザーを閉じるようにしている唯一の問題は、このコマンドプロンプトを非表示/ ?コマンドプロンプトスクリーンショットを取得中に非表示/削除する

private const int TIMEOUT = 30000; 
private const string TMP_NAME = "TMP_SHOT1.png"; 

protected void Page_Load(object sender, EventArgs e) 
{ 
    theImage.ImageUrl = GetImage("http://www.google.com", "MyImage", 
       Server.MapPath("~"), 
       Convert.ToInt32("400"), 
       Convert.ToInt32("400") 
      ); 
} 

public string GetImage(string url, string name, 
         string rootDir, int width, int height) 
{ 
    try 
    { 
     string fileName = rootDir + "\\" + TMP_NAME; 
     GenerateScreenShot1(url, rootDir); 
     System.Drawing.Image thumbImage = 
         System.Drawing.Image.FromFile(fileName); 
     fileName = rootDir + "\\" + name + ".png"; 
     if (File.Exists(fileName)) 
      File.Delete(fileName); 

     thumbImage.Save(fileName, ImageFormat.Png); 

     return name + ".png"; 
    } 
    catch (Exception ex) 
    { 
     return null; 
    } 
} 

public void GenerateScreenShot1(string url1, string rootDir1) 
{ 
    string arguments = url1 + " " + rootDir1 + "\\" + TMP_NAME; 
    Process myProcess = new Process(); 
    myProcess.EnableRaisingEvents = false; 
    myProcess.StartInfo.RedirectStandardOutput = false; 
    myProcess.StartInfo.CreateNoWindow = false; 
    myProcess.StartInfo.UseShellExecute = true; 
    myProcess.StartInfo.FileName = rootDir1 + "\\" + "IECapt.exe"; 
    myProcess.StartInfo.Arguments = arguments; 
    myProcess.Start(); 
    myProcess.WaitForExit(); 
    myProcess.Close(); 
    myProcess.Dispose(); 
} 

上記のコードを実行するには、IECapt.exeをルートフォルダに配置する必要があります。

+0

ここからのような文を含めないでください、あなたの質問に「*助けてくださいと、それは*緊急のです」。それはコミュニティによって威嚇される。 – jadarnel27

+0

@ jadarnel27私はそれをお詫び申し上げます。 – Zerotoinfinity

+0

問題はない、ちょうど私があなたに知らせると思った(時々downvotesを引き付ける傾向がある)=)+1、これは興味深い質問です! – jadarnel27

答えて

0

myproces.StartInfo.UseShellExecute = falseを設定してみてください。

+0

まだ、コマンドプロンプトを開く – Zerotoinfinity

1
+0

コマンドプロンプトが開きませんが、公開後にイメージファイルを削除しようとしているときにこのエラーが発生しています。** WebDevでファイルが開いているため、アクションを完了できません。 WebServer40.exe **その場合は、手動でタスクマネージャを開いてタスクを閉じる必要があります。 – Zerotoinfinity

関連する問題