Is there a way to detect if the running Window OS has a valid license? If the running Windows OS has not a valid license, I don't want to execute my program. Is any function or method in .Net 3.5 to get this info?
Asked
Active
Viewed 2,202 times
2
-
Interesting question, but why link your program to Windows licence? – user2586804 Sep 10 '13 at 11:14
-
1See this: http://stackoverflow.com/questions/1552392/determine-genuine-windows-installation-in-c-sharp – Colin Smith Sep 10 '13 at 11:14
-
1maybe this (WGA), http://stackoverflow.com/questions/1552392/determine-genuine-windows-installation-in-c-sharp/1552434#1552434 but keep in mind that you require vista for that. so either forbid XP and below or check for and handle older versions as well. And imho, its so easy to break WGA - that the amount of people missing valid WGA is so tiny that the effort implenting the logic is to high – Najzero Sep 10 '13 at 11:15
-
Out of curiosity: why don't you want to run your program on a legal OS? Furthermore I guess such tests can be fooled. Otherwise Windows could stop executing from the moment it detects there is something wrong with the license. – Willem Van Onsem Sep 10 '13 at 11:19
-
I want to run only on legal Windows because I have as a precondition some certain windows updates. If windows is not genuine then the user will get black screen. – Stathis Andronikos Sep 10 '13 at 11:24
-
Also, from the links of najzero & colinsmith I realize that there is no support for Windows XP – Stathis Andronikos Sep 10 '13 at 11:26
-
That explanation makes no sense to me. I do wonder if you have mis-diagnosed your requirement. – David Heffernan Sep 10 '13 at 11:26
-
1see : http://technet.microsoft.com/en-us/magazine/ee518862.aspx "Despite what you may have read elsewhere, there's no reduced functionality mode in Windows 7. If the activation key expires, the desktop background simply goes black and a notification balloon states that the operating system isn't genuine." – Stathis Andronikos Sep 10 '13 at 11:28
-
If not gennuine, NOT run and leave – Stathis Andronikos Sep 10 '13 at 11:28
-
Please note that doing this is very anti-social. The fact that Windows doesn't detect a valid license DOES NOT necessarily mean that the OS is pirated; false positives are a significant problem, mitigated mainly by the fact that it doesn't usually do any real harm. Your customers will not appreciate being locked out of the software you've sold them just because Windows licensing has glitched. – Harry Johnston Sep 11 '13 at 03:41
-
If you need specific updates, test for those updates. Don't try to second-guess things. – Harry Johnston Sep 11 '13 at 03:43
1 Answers
2
I have copied for you the soultion from:
Determine Genuine Windows Installation in C#
Dont forget to mark the answer if this solve your problem!
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace ConsoleApplication11
{
using SLID = Guid; //SLID id declarated as typedef GUID SLID; in slpublic.h
class Program
{
public enum SL_GENUINE_STATE
{
SL_GEN_STATE_IS_GENUINE = 0,
SL_GEN_STATE_INVALID_LICENSE = 1,
SL_GEN_STATE_TAMPERED = 2,
SL_GEN_STATE_LAST = 3
}
[DllImportAttribute("Slwga.dll", EntryPoint = "SLIsGenuineLocal", CharSet = CharSet.None, ExactSpelling = false, SetLastError = false, PreserveSig = true, CallingConvention = CallingConvention.Winapi, BestFitMapping = false, ThrowOnUnmappableChar = false)]
[PreserveSigAttribute()]
internal static extern uint SLIsGenuineLocal(ref SLID slid, [In, Out] ref SL_GENUINE_STATE genuineState, IntPtr val3);
public static bool IsGenuineWindows()
{
bool _IsGenuineWindows = false;
Guid ApplicationID = new Guid("55c92734-d682-4d71-983e-d6ec3f16059f"); //Application ID GUID http://technet.microsoft.com/en-us/library/dd772270.aspx
SLID windowsSlid = (Guid)ApplicationID;
try
{
SL_GENUINE_STATE genuineState = SL_GENUINE_STATE.SL_GEN_STATE_LAST;
uint ResultInt = SLIsGenuineLocal(ref windowsSlid, ref genuineState, IntPtr.Zero);
if (ResultInt == 0)
{
_IsGenuineWindows = (genuineState == SL_GENUINE_STATE.SL_GEN_STATE_IS_GENUINE);
}
else
{
Console.WriteLine("Error getting information {0}", ResultInt.ToString());
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return _IsGenuineWindows;
}
static void Main(string[] args)
{
if (Environment.OSVersion.Version.Major >= 6) //Version 6 can be Windows Vista, Windows Server 2008, or Windows 7
{
if (IsGenuineWindows())
{
Console.WriteLine("Original Windows");
}
else
{
Console.WriteLine("Not Original Windows");
}
}
else
{
Console.WriteLine("OS Not supoprted");
}
Console.ReadLine();
}
}
}

Community
- 1
- 1

Bassam Alugili
- 16,345
- 7
- 52
- 70
-
Minimum supported client is Windows Vista is this a problem for you? – Bassam Alugili Sep 10 '13 at 11:49
-
1
-
Than I would use the Windows Update function (if Windows is activated than you can use the Allow Windows Updating must be also enabled! ) First add a reference to WUApiLib "C:\windows\system32\Wuapi.dll" Then you can use this code snippet. WUApiLib.AutomaticUpdatesClass auc = new WUApiLib.AutomaticUpdatesClass(); bool active = auc.ServiceEnabled; – Bassam Alugili Sep 10 '13 at 12:18
-
But try the answer code it might be also working for Windows XP with SP – Bassam Alugili Sep 10 '13 at 12:19