Example C-Sharp source code
Previous Top Next


// The following simple example demonstrates how to retreive and store license variables in C-sharp
// The example imports the native Win32 API functions GetEnvironmentVariable and SetEnvironment Variable

using System;
using
System.Runtime.InteropServices;
using
System.Text;

namespace
license_test_namespace
{
class
license_test
{
[DllImport("kernel32.dll")]
static
extern int SetEnvironmentVariable( string varName, string varValue);

[DllImport("kernel32.dll")]
static
extern bool GetEnvironmentVariable( string varName, StringBuilder varValue);

static
void Main( string [] args)
{
StringBuilder key= new
StringBuilder(1000); // reserve 1000 bytes to hold key value

GetEnvironmentVariable("TS_CURRENT_KEY", key);
Console.WriteLine("The current license key is " + key);

Console.WriteLine("Enter a new License Key and press enter:");
string
new_key=Console.ReadLine();
int
result=SetEnvironmentVariable("TS_CURRENT_KEY", new_key);

if
(result==0)
Console.WriteLine("The key you entered was invalid");
else
Console.WriteLine("The key you entered has been accepted");
}
}
}


Program output (when packaged using Thinstall and License System 2 enabled)

clip0331