3

I have this method which generates a license by running an exe program on our server:

/// <summary>
/// Generate a new license
/// </summary>
public static void GenerateLicense(string Name, string EmailAddress, Licensing.Types.LicenseType Type, Licensing.Types.ProductTypes Product)
{
    string Params = "\"" + Licensing.Types.LicenseTypeToString(Type) + "\" \""
        + Licensing.Types.ProductTypeToString(Product)
        + "\" \"" + Name + "\" \""
        + EmailAddress + "\"";

    // Start license executable and pass in all the params
    Process.Start(Settings.LicenseExecutableLocation, Params);

}

It's not throwing any errors, and it's not apparently running the program (it should be making some files on the server). The location of the executable (Settings.LicenseExecutableLocation) is C:\inetpub\wwwroot\licensegen.exe which is correct, and the paramaters are also correct (I've printed them out).

I'm running IIS7, it's not throwing any errors at all, do I need to change something in IIS7?

Tom Gullen
  • 61,249
  • 84
  • 283
  • 456
  • Is the file not running at all (verified by checking the process explorer), or just not outputting the files? – Kyle Trauberman Aug 05 '11 at 22:32
  • Are you using Server 2008? Have you tried running the process from the command line? – John Kalberer Aug 05 '11 at 22:33
  • Who's calling this method? Each web request (probably not) or the startup code? – Philipp Schmid Aug 05 '11 at 22:33
  • 5
    possible duplicate of [System.Diagnostics.Process.Start not work fom an IIS](http://stackoverflow.com/questions/4679561/system-diagnostics-process-start-not-work-fom-an-iis) – Kyle Trauberman Aug 05 '11 at 22:33
  • @Kyle I keep the task manager up and it's not popping up, it's a very quick process so I might miss it, not sure how to see what it's doing really – Tom Gullen Aug 05 '11 at 22:33
  • @John I'm on windows 7 but the live server is 2008 which I haven't tried it on yet – Tom Gullen Aug 05 '11 at 22:34
  • 1
    @Tom I think Process Explorer (http://technet.microsoft.com/en-us/sysinternals/bb896653) will track if a process opens then closes quickly, so you can see if its actually getting started or not. – Kyle Trauberman Aug 05 '11 at 22:35
  • @Kyle the question you linked I tried to go through it but the instructions don't work for me, that's for XP and below, I'm on Windows 7 and there is no `IIS Admin Service.` – Tom Gullen Aug 05 '11 at 22:40
  • Hmm... try modifying execute permissions to allow scripts and executables. I also named a few other suggestions below as well. – James Johnson Aug 05 '11 at 22:46

2 Answers2

3

Since you're not getting an exception when launching the process, you need to find out what it is actually doing. I would change your last line to

var pLicenseGenerator =  Process.Start(Settings.LicenseExecutableLocation, Params);

And then investigate the properties of the pLicenseGenerator object in a debug session after waiting a few seconds for the process to do its thing. This object will be of the Process class and I would pay special attention to the .ExitCode property. In a well-designed console application, this will be set to a non-zero value if the program encountered an error (like the old DOS %ERRORLEVEL% variable.)

If .ExitCode doesn't help, I'd recommend dumping .StandardOutput to the web page or to a file for debugging.

When I've run into similar issues in the past, it's always been a problem with the way I formatted the process's input parameters. Sometimes if a parameter is a long file path, you need to pay special attention to the way you wrap it in double-quotes.

One simple step would be to spit out the exact path and parameters you are passing to Process.Start() and then see what happens when you run them yourself from the command line. If they work fine, then it is probably some sort of permission-related issue, as another poster speculated.

Jordan Rieger
  • 3,025
  • 3
  • 30
  • 50
1

You might be running into a permissions issue. Does the executable reside in the same directory as the web application? If not, you may need to modify permissions or look into using impersonation. If it does reside in the same directory, you should try using a relative path. You may also need to suppress the console dialog - I've experienced problems with that.

Hope this helps.

James Johnson
  • 45,496
  • 8
  • 73
  • 110