[RESOLVED] Get the GUID of the Application
How can I get the GUID of an application?
I found this code on the net:
VB Code:
System.Runtime.InteropServices.GuidAttribute guid = (System.Runtime.InteropServices.GuidAttribute)System.Reflection.Assembly.GetExecutingAssembly().GetCustomAttributes(System.Runtime.InteropServices.GuidAttribute, false);
guid.ToString();
The space is for GetCustomAttributes(). No idea why vBull breaks up a line in code tags via HTML so it inserts a space :sick:
However, it gives me an error stating GetCustomAttributes requires a Type in the first parameter. I thought I was giving it a type?
Is there a better way to do this or what is the problem with my code?
Also, if I put this code into a DLL, will it give me the GUID of my DLL or the Application calling the DLL?
Re: Get the GUID of the Application
It needs an instance of the Type class, which means you need to pass it typeof(System.Runtime.InteropServices.GuidAttribute).
Re: Get the GUID of the Application
If I'm not mistaken, the assembly itself gets the GUID of the type it has. Have you checked the Type.Guid property?
VB Code:
Dim myType As Type = GetType(YOURCLASSNAME)
' Get the object of the Guid.
Dim myGuid As Guid = CType(myType.GUID, Guid)
Console.WriteLine(("The name of the class is " + myType.ToString()))
Console.WriteLine(("The ClassId of MyClass is " + myType.GUID.ToString()))
That's from MSDN. Sure you can convert it.
Re: Get the GUID of the Application