Last active
January 31, 2016 15:53
-
-
Save pipiscrew/45f4094fb09a0df9245a to your computer and use it in GitHub Desktop.
Winlicense - WLGenLicenseDynSmartKey Call ASP.NET
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ Page Language="C#" %> | |
<%@ import Namespace="System.Runtime.InteropServices" %> | |
<script runat="server"> | |
/****************************************************************** | |
WLGenLicenseSmartKey rev1 - sample code contributed by Sanjay Kanade, AvniTech.com in 2008. | |
WLGenLicenseDynSmartKey rev2- sample code by PipisCrew in 2016 | |
You are responsible for making any changes, testing and using it as per your | |
requirement. The author assumes no responsibility for any bugs or problems | |
arising from the use of the code. | |
This is an ASP.NET example of WinLicense DynSmartKey generation. | |
It has been tested with ASP.NET v2/v4 and WinLicense v2.3.4.14. | |
*WARNING* HOSTING REQUIREMENT *WARNING*: | |
Since this uses InteropServices, it needs asp.net accounts in #full trust# (http://stackoverflow.com/a/2617483). | |
If your hosting provider does not allow full trust (not available on shared host), | |
you will need to use a VPS type account. Please test it first and then consult | |
your hosting company if it doesn't work. | |
CUSTOMIZE THESE BEFORE USE: | |
You will need to customize the following items before using this script. | |
Use Search to find the items in this source. | |
* Actual hosted path of WinLicnseSDK.DLL in DllImport statement. | |
* LicenseHash variable: put the License Unique Key as string constant from | |
your WinLicense project. The string constant may need to be split on | |
multiple lines. | |
******************************************************************/ | |
class WinlicenseSDK | |
{ | |
[StructLayout(LayoutKind.Sequential)] | |
public class SystemTime | |
{ | |
public short wYear; | |
public short wMonth; | |
public short wDayOfWeek; | |
public short wDay; | |
public short wHour; | |
public short wMinute; | |
public short wSecond; | |
public short wMilliseconds; | |
} | |
[StructLayout(LayoutKind.Sequential)] | |
public class sLicenseFeatures | |
{ | |
public int cb; | |
public int NumDays; | |
public int NumExec; | |
public SystemTime ExpDate; | |
public int CountryId; | |
public int Runtime; | |
public int GlobalMinutes; | |
public SystemTime InstallDate; | |
public int NetInstances; | |
public int EmbedLicenseInfoInKey; | |
public int EmbedCreationDate; | |
} | |
[DllImport(@"c:\inetpub\WinlicenseSDK.dll", EntryPoint = "WLGenLicenseDynSmartKey", CallingConvention = CallingConvention.StdCall)] | |
public static extern int WLGenLicenseDynSmartKey( | |
string pLicenseHash, | |
string pUserName, | |
string pOrganization, | |
string pCustomData, | |
string pMachineID, | |
sLicenseFeatures pLicenseFeatures, | |
StringBuilder pBufferOut); | |
} | |
string getCodes(string machineID) | |
{ | |
//PRJ - License Unique Key | |
string LicenseHash = "x"; | |
string pName = "costas"; //pass it on URL? | |
string pCompany = "pipiscrew"; //pass it on URL? | |
StringBuilder LicenseKeyBuff = new StringBuilder(4000); | |
//for the license expiration date - todo make it dynamic | |
WinlicenseSDK.SystemTime t = new WinlicenseSDK.SystemTime(); | |
t.wDay = 31; | |
t.wMonth=1; | |
t.wYear=2016; | |
t.wDayOfWeek=7; //sunday is 7 | |
t.wHour=10; | |
t.wMilliseconds=1; | |
t.wMinute=1; | |
t.wSecond=1; | |
//for the license creation date - todo make it dynamic | |
WinlicenseSDK.SystemTime t2 = new WinlicenseSDK.SystemTime(); | |
t2.wDay = short.Parse (DateTime.Now.Day.ToString()); | |
t2.wMonth = 1; | |
t2.wYear = 2016; | |
t2.wDayOfWeek = 6; //saturday is 6 | |
t2.wHour = 10; | |
t2.wMilliseconds = 1; | |
t2.wMinute = 1; | |
t2.wSecond = 1; | |
WinlicenseSDK.sLicenseFeatures x= new WinlicenseSDK.sLicenseFeatures(); | |
x.EmbedLicenseInfoInKey = 1; | |
x.EmbedCreationDate = 1; | |
x.NetInstances = 0; | |
x.GlobalMinutes = 0; | |
x.Runtime = 0; | |
x.NumExec = 0; | |
x.NumDays = 0; | |
x.CountryId = 0; //0 - no country restriction | |
x.ExpDate = t; | |
x.InstallDate = t2; | |
//Returns the size of an unmanaged type in bytes. - http://stackoverflow.com/a/8744600 | |
x.cb = Marshal.SizeOf(typeof(WinlicenseSDK.sLicenseFeatures)); | |
WinlicenseSDK.WLGenLicenseDynSmartKey(LicenseHash, pName, pCompany, "1", machineID, x, LicenseKeyBuff); | |
return LicenseKeyBuff.ToString().Trim();// "<softshop>Name: " + name + "\r\nCompany: " + company + "\r\nCode: " + LicenseKeyBuff.ToString().Trim() + "</softshop>"; | |
} | |
//*********************************************** | |
void Page_Load (object sender, EventArgs e) { | |
string machineID = Request.QueryString["machine"]; | |
if (machineID == null || machineID == "") | |
Response.Write("Invalid request"); | |
else | |
Response.Write(getCodes(machineID)); | |
Response.End(); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment