<project name="typelibfunctions">
<script language="C#" prefix="typelib">
<references>
<include name="C:\Program Files\nant\bin\Interop.TLBINF32.dll" />
</references>
<imports>
<import namespace="Microsoft.Win32" />
</imports>
<code><![CDATA[
[Function("guid")]
public static string GetCLSIDFromFile( string pFileName )
{
TLI.TypeLibInfo t;
TLI.TLIApplicationClass tli = new TLI.TLIApplicationClass();
t = tli.TypeLibInfoFromFile(pFileName);
return t.GUID;
}
[Function("major-version")]
public static string GetMajVerFromFile( string pFileName )
{
TLI.TypeLibInfo t;
TLI.TLIApplicationClass tli = new TLI.TLIApplicationClass();
try {
t = tli.TypeLibInfoFromFile(pFileName);
} catch(Exception e) {
Console.WriteLine("An error occurred: '{0}' on {1}", e, pFileName);
throw new SystemException("Error in GetMajVerFromFile");
}
return t.MajorVersion.ToString("x");
}
[Function("minor-version")]
public static string GetMinVerFromFile( string pFileName )
{
TLI.TypeLibInfo t;
TLI.TLIApplicationClass tli = new TLI.TLIApplicationClass();
t = tli.TypeLibInfoFromFile(pFileName);
return t.MinorVersion.ToString("x");
}
[Function("reg-remove-clsid")]
public static string RegRemoveCLSID(string pFileName)
{
string clsid = GetCLSIDFromFile(pFileName);
// search CLSID
RegistryKey root = Registry.ClassesRoot.OpenSubKey("CLSID", true);
string[] rootnames = root.GetSubKeyNames();
for(int i = 0; i < rootnames.Length; i++)
{
RegistryKey m = root.OpenSubKey(rootnames[i]);
RegistryKey t = m.OpenSubKey("TypeLib");
if (t != null)
{
if (t.GetValue("").ToString() == clsid)
{
root.DeleteSubKeyTree(rootnames[i]);
}
}
}
// search Interface
root = Registry.ClassesRoot.OpenSubKey("Interface", true);
rootnames = root.GetSubKeyNames();
for(int i = 0; i < rootnames.Length; i++)
{
RegistryKey m = root.OpenSubKey(rootnames[i]);
RegistryKey t = m.OpenSubKey("TypeLib");
if (t != null)
{
if (t.GetValue("").ToString() == clsid)
{
root.DeleteSubKeyTree(rootnames[i]);
}
}
}
RegistryKey r = Registry.ClassesRoot.OpenSubKey(@"TypeLib", true);
RegistryKey rm = r.OpenSubKey(clsid);
if(rm != null) r.DeleteSubKeyTree(clsid);
return clsid;
}
]]>
</code>
</script>
</project>