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?

9
  • Is the file not running at all (verified by checking the process explorer), or just not outputting the files? Commented Aug 5, 2011 at 22:32
  • Are you using Server 2008? Have you tried running the process from the command line? Commented Aug 5, 2011 at 22:33
  • Who's calling this method? Each web request (probably not) or the startup code? Commented Aug 5, 2011 at 22:33
  • 5
    possible duplicate of System.Diagnostics.Process.Start not work fom an IIS Commented Aug 5, 2011 at 22:33
  • 1
    @Tom I think Process Explorer (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. Commented Aug 5, 2011 at 22:35

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.