【问题标题】:VB.NET Checking if WIndows is ActivatedVB.NET 检查 Windows 是否被激活
【发布时间】:2015-07-27 23:05:27
【问题描述】:

我一直在网上寻找一种解决方案,让我的程序检查我的窗口是否被激活。

与您在底部检查系统属性的方式相同,它显示剩余 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”。

所以我的问题不是看我的窗口是否是原始的,而是是否还需要激活。

有什么办法可以完成这项工作吗?或者关于如何使这项工作的任何提示?

【问题讨论】:

  • 您可以使用WMI 中的SoftwareLicensingProduct 类来获取许可证状态、宽限期等。但是,您为什么要关心- 应用程序通常不会涉及操作系统许可证状态。顺便说一句,我不确定为什么这是 DVed - 对我来说似乎很清楚。
  • 我正在为我们的实习生编写一个小软件,用于在我们构建的笔记本电脑和台式机上运行 sysprep 清单。这样我可以检查他们是否完成了列表中的所有操作,因为每个操作都需要按一下按钮。像设置壁纸,更改系统信息以包含我们的手机等。所有这些都只需一个简单的程序。但是许可证似乎可以在任何机器上给我一个真实的结果,无论是否激活。当我显然只是在问一个正常的问题时,我也没有看到投票的意义。
  • 您总是有可能错误地实现了该代码,因此实际代码可能阻止它被关闭,而不是链接。我不确定这是获取许可证状态的正确方法:正版安装和安装激活状态之间存在差异。
  • 我回家后会发布我的代码。此外,activationstatus 是我想要得到的。
  • 目前我不确定这是否重要。该链接提供了IsGenuine() 测试,您需要其他东西。您想要的答案在我的第一条评论中。

标签: vb.net


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-26
    • 2013-02-24
    • 2011-08-17
    • 1970-01-01
    • 2017-09-14
    • 2018-12-05
    • 1970-01-01
    相关资源
    最近更新 更多