我一直在寻找一个解决方案,让我的程序检查我的窗口是否被激活。
您可以检查底部的系统属性,并说明剩余xx天,点击此处激活。这样我知道它没有激活。
问题是我使用了以下代码:
Imports System.Collections.Generic
Imports System.Text
Imports System.Runtime.InteropServices
Imports SLID = System.Guid
Module Genuine_Check
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
End Enum
<DllImportAttribute("Slwga.dll", EntryPoint:="SLIsGenuineLocal", CharSet:=CharSet.None, ExactSpelling:=False, SetLastError:=False, PreserveSig:=True, CallingConvention:=CallingConvention.Winapi, _
BestFitMapping:=False, ThrowOnUnmappableChar:=False)> _
<PreserveSigAttribute()> _
Friend Function SLIsGenuineLocal(ByRef slid As SLID, <[In](), Out()> ByRef genuineState As SL_GENUINE_STATE, ByVal val3 As IntPtr) As UInteger
End Function
Public Function IsGenuineWindows() As Boolean
Dim _IsGenuineWindows As Boolean = False
Dim ApplicationID As New Guid("55c92734-d682-4d71-983e-d6ec3f16059f")
'Application ID GUID http://technet.microsoft.com/en-us/library/dd772270.aspx
Dim windowsSlid As SLID = CType(ApplicationID, Guid)
Try
Dim genuineState As SL_GENUINE_STATE = SL_GENUINE_STATE.SL_GEN_STATE_LAST
Dim ResultInt As UInteger = SLIsGenuineLocal(windowsSlid, genuineState, IntPtr.Zero)
If ResultInt = 0 Then
_IsGenuineWindows = (genuineState = SL_GENUINE_STATE.SL_GEN_STATE_IS_GENUINE)
Else
MsgBox("Error getting information {0}", ResultInt.ToString())
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return _IsGenuineWindows
End Function
Public Function CheckGenuine()
If Environment.OSVersion.Version.Major >= 6 Then
'Version 6 can be Windows Vista, Windows Server 2008, or Windows 7
If IsGenuineWindows() Then
MsgBox("Original Windows")
Form1.Button8.BackColor = Color.LawnGreen
Else
MsgBox("Not Original Windows")
Form1.Button8.BackColor = Color.Red
End If
Else
MsgBox("OS Not supported")
End If
End Function
End Module
然后我运行以下内容:
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
Try
CheckGenuine()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly)
End Try
但是这显示了一个消息:带有密钥的系统上的'原始Windows',并且在没有安装密钥的情况下激活了干净安装。
所以我的问题是不要看我的窗户是否是原装的,但是如果它仍然需要激活。
有没有办法完成这项工作?或者有关如何使这项工作的任何提示?
答案 0 :(得分:1)
我设法解决了问题,使用完全不同的解决方案,如上所述,我正在查看错误的解决方案和代码。
如果有人感兴趣,以下是解决方案。
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
Try
Dim searcher As New ManagementObjectSearcher( _
"root\CIMV2", _
"SELECT * FROM SoftwareLicensingProduct WHERE LicenseStatus = 1")
Dim myCollection As ManagementObjectCollection
Dim myObject As ManagementObject
myCollection = searcher.Get()
If myCollection.Count = 0 Then
MsgBox("Windows is not activated")
Button8.BackColor = Color.Red
searcher.Dispose()
Else
For Each myObject In myCollection
MsgBox("Windows is activated")
Button8.BackColor = Color.LawnGreen
searcher.Dispose()
Next
End If
searcher.Dispose()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly)
End Try