[C#] VAMT Reflection Help

Discussion in 'Mixed Languages' started by CODYQX4, Sep 25, 2011.

  1. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,812
    45,440
    150
    #1 CODYQX4, Sep 25, 2011
    Last edited by a moderator: Apr 20, 2017
    OK, I've looked into VAMTrt.dll, and saw how to send a MAK for remaining count check. However, I want to do this via reflection on the DLL.

    The Program.cs code if you have VAMTrt.dll code is:
    Code:
                // Create a new ProductKey structure
                ProductKey MAK = new ProductKey();
                MAK.Value = "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX"; // This is some MAK for Project Standard
                MAK.Id = "XXXXX-XXXXX-XXX-XXXXXX-XX-XXXX-XXXX.XXXX-XXXXXXX1"; // This is its PID.
    
                // Create a new instance of the background worker
                AcquireRemainingActivationCountWorker getInfo = new AcquireRemainingActivationCountWorker();
    
                // Add the MAK to a Product key collection and send it to the worker to be processed
                Collection<ProductKey> argument = new Collection<ProductKey>();
                argument.Add(MAK);
                getInfo.RunWorkerSync(argument);
    
                // Spit out the results
                Console.WriteLine("Key:" + argument[0].Value);
                Console.WriteLine("Count:" + argument[0].RemainingActivationCount);
    How can I achieve this by using reflection on the DLL? Thing to keep in mind is ProductKey is a type defined in the DLL.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,812
    45,440
    150
    #2 CODYQX4, Apr 7, 2012
    Last edited by a moderator: Apr 20, 2017
    (OP)
    In case anyone want to know this, if you want to test MAK activation count, then add that VAMTrt.dll as a reference and use the following code to call the right function.

    Code:
    using Microsoft.SoftwareLicensing.Vamt;
    using System.Collections.ObjectModel;
    namespace VAMT
    {
        public static class GetRemainingActivationCount
        {
            public static int GetRemainingActivations(string PID)
            {
                return GetRemainingActivations(PID, "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX");
            }
            public static int GetRemainingActivations(string PID, string Key)
            {
                // Create a new ProductKey structure to
                ProductKey MAK = new ProductKey {Value = Key, Id = PID};
    
                // Create a new instance of the background worker
                AcquireRemainingActivationCountWorker getInfo = new AcquireRemainingActivationCountWorker();
    
                // Add the MAK to a Product key collection and send it to the worker to be processed
                Collection<ProductKey> argument = new Collection<ProductKey> {MAK};
                getInfo.RunWorkerSync(argument);
    
                // return the results
                return argument[0].RemainingActivationCount;
            }
        }
    }
    
    You use this in a PIDX check, and pass the PID got from that check. If you notice, you don't need the key, only the PID, so I allow only sending the PID. VAMT wants the key set to something though, so I set it to all XXXXX, and set the PID to whatever you got in the check.

    I call it like this
    Code:
                                    
    try
    {
         int RemainingUses = VAMT.GetRemainingActivationCount.GetRemainingActivations(pid);
         if (RemainingUses == -2)
         {
              output += Environment.NewLine + "Remaining Activation Count: 0 (Blocked)";
         }
         else
         {
              output += Environment.NewLine + "Remaining Activation Count: " + RemainingUses;
         }
    }
    catch (Exception ex)
    {
         output += Environment.NewLine + "Remaining Activation Count: Couldn't determine due to error: " + ex.Message;
    }
    PS: You'll have to include that DLL with your app.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,812
    45,440
    150
    I use SmartAssembly to merge all my .NET Dlls, but this doesn't work on VAMTrt.dll.

    What I do to not have the DLL is add it as a reference, disable copying VAMTrt.dll to output directory, and then use the method described on this site to make the program get this DLL from a resource file

    http://blog.magenic.com/blogs/brante/archive/2008/04/14/Embedded-Assembly-Linker.aspx

    Basically, I create a Resource file called Assemblies.resx, then add VAMTrt as a file, then add that code, which gets the DLL from resources instead of a file.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...