Results 1 to 4 of 4

Thread: [RESOLVED] Get the GUID of the Application

  1. #1

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Resolved [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:
    1. System.Runtime.InteropServices.GuidAttribute guid = (System.Runtime.InteropServices.GuidAttribute)System.Reflection.Assembly.GetExecutingAssembly().GetCustomAttributes(System.Runtime.InteropServices.GuidAttribute, false);
    2. 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

    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?
    Last edited by Kasracer; Mar 4th, 2006 at 12:49 AM.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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).
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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:
    1. Dim myType As Type = GetType(YOURCLASSNAME)
    2.             ' Get the object of the Guid.
    3.             Dim myGuid As Guid = CType(myType.GUID, Guid)
    4.             Console.WriteLine(("The name of the class is " + myType.ToString()))
    5.             Console.WriteLine(("The ClassId of MyClass is " + myType.GUID.ToString()))

    That's from MSDN. Sure you can convert it.

  4. #4

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: Get the GUID of the Application

    Thanks guys
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width