gpt4 book ai didi

windows - VB.NET - 检查 Windows 许可证状态或正版 Windows

转载 作者:可可西里 更新时间:2023-11-01 12:02:22 27 4
gpt4 key购买 nike

问答达人您好!

我正在尝试找到一种方法来准确验证 Windows 7 机器当前是否正在使用有效许可证并已激活。我相信我可以启动“cmd.exe”命令来运行 cscript (slmgr) 并解析该信息,但这似乎是一种低效的方法。

我遇到了一个名为 SLGetGenuineInformation (http://msdn.microsoft.com/en-us/library/windows/desktop/bb648650%28v=vs.85%29.aspx) 的非托管 Windows API,但是我不熟悉如何在 VB.NET 中调用它或变量类型应该是什么。我相信 VB6 附带了某种 Visual STudio 2010 似乎不包含的 APIViewer。

所有相关的 Google 搜索都显示为不相关的结果。

关于如何继续或完成此目标的任何建议、意见或指导?

最佳答案

检查这个示例 vb.net 控制台应用程序,它使用 SLIsGenuineLocal功能。

Imports System.Collections.Generic
Imports System.Text
Imports System.Runtime.InteropServices
Imports SLID = System.Guid
Module Module1

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
Console.WriteLine("Error getting information {0}", ResultInt.ToString())

End If
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
Return _IsGenuineWindows
End Function

Sub Main()
If Environment.OSVersion.Version.Major >= 6 Then
'Version 6 can be Windows Vista, Windows Server 2008, or Windows 7
If IsGenuineWindows() Then
Console.WriteLine("Original Windows")
Else
Console.WriteLine("Not Original Windows")
End If
Else
Console.WriteLine("OS Not supoprted")
End If
Console.ReadLine()
End Sub

End Module

关于windows - VB.NET - 检查 Windows 许可证状态或正版 Windows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8647097/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com