3

I have the following code to create the screenshot, but the only issue I am facing that it opens the command prompt and make user to close it, can I hide/remove this command prompt?

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();
}

To run the above code, you need to place IECapt.exe in root folder.

oleksii
  • 35,458
  • 16
  • 93
  • 163
Zerotoinfinity
  • 6,290
  • 32
  • 130
  • 206

3 Answers3

2

try this

myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

also

To use ProcessWindowStyle.Hidden, the ProcessStartInfo.UseShellExecute property must be false.

from here http://msdn.microsoft.com/en-us/library/system.diagnostics.processwindowstyle.aspx

madmik3
  • 6,975
  • 3
  • 38
  • 60
1

Change the line

myProcess.StartInfo.CreateNoWindow = false;

with

myProcess.StartInfo.CreateNoWindow = true;

http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.createnowindow.aspx

CMPerez
  • 905
  • 1
  • 10
  • 25
  • It is not opening the command prompt but when I am trying to delete the image file after publishing I am getting this error, **The action can't be completed because the file is open in WebDev.WebServer40.exe** In that case, I have to manually open the task manager and close the task. – Zerotoinfinity Jan 20 '12 at 14:00
0

Try setting myproces.StartInfo.UseShellExecute = false;

mehul9595
  • 1,925
  • 7
  • 32
  • 55