Skip to content

Instantly share code, notes, and snippets.

@lpalli
Created Apr 28, 2011
Embed
What would you like to do?
Utility to work with ESRIRegAsm.exe tool.
/// <summary>
/// The ArcGIS products.
/// </summary>
public enum Product {
/// <summary>
/// ArcGIS Desktop
/// </summary>
Desktop,
/// <summary>
/// ArcGIS Engine
/// </summary>
Engine
}
/// <summary>
/// Register or unregister an assembly.
/// </summary>
/// <param name="register"><code>true</code> to register, <code>false</code> to unregister the class</param>
/// <param name="assemply">the assembly</param>
/// <param name="product">the product for witch the assembly must be registred</param>
/// <param name="timeout">the timeout</param>
public static void Execute(bool register, Assembly assemply,
Product product = Product.Desktop, int timeout = 10000)
{
// Configure the process to execute the command
Process process = new Process();
process.StartInfo.FileName = Path.Combine(
Environment.GetFolderPath(
Environment.SpecialFolder.CommonProgramFiles),
"ArcGIS\\bin\\ESRIRegAsm.exe");
process.StartInfo.Arguments = string.Format(
register ? "\"{0}\" /p:{1} /s" : "\"{0}\" /p:{1} /u /s",
assemply.Location, product);
// Invoke the process
process.Start();
process.WaitForExit(timeout);
// Finish
int exitCode = process.ExitCode;
process.Close();
if (exitCode != 0)
{
throw new Exception(register ? "ESRI registration failed" :
"ESRI unregistration failed");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment