• 2017-08-22校验


    Const ADDIN_NAME As String = "AddInFunction"
    Const SETTING_ITEM As String = "AddInSetting"
    Const KEY_NAME As String = "RegisterCpu"
    Sub TestRegister()
        Debug.Print IsRegistered
    End Sub
    Public Function IsRegistered() As Boolean
        Dim CpuID As String
        Dim RegisterInfo As String
        Dim Rng As Range, RngInfo As String
        RegisterInfo = Get_Settings
        If RegisterInfo <> "" Then
            If HasRegisterSheet Then
                Set Rng = ThisWorkbook.Worksheets("Register").Range("IV65536")
                RngInfo = Rng.Text
                If Len(RngInfo) > 0 Then
                    If RngInfo = RegisterInfo Then
                        '校验成功
                        IsRegistered = True
                    Else
                        IsRegistered = False
                    End If
                Else
                    IsRegistered = False
                End If
            Else
                IsRegistered = False
            End If
        Else
            If HasRegisterSheet Then
                Set Rng = ThisWorkbook.Worksheets("Register").Range("IV65536")
                RngInfo = Rng.Text
                If Len(RngInfo) > 0 Then
                    IsRegistered = False
                Else
                    '首次注册,写入注册表
                    CpuID = Get_CpuId
                    Rng.Value = "'" & CpuID
                    Save_Settings CpuID
                    IsRegistered = True
                End If
            Else
                IsRegistered = False
            End If
        End If
        Set Rng = Nothing
    End Function
    Private Function Get_Settings() As String
        Get_Settings = GetSetting(ADDIN_NAME, SETTING_ITEM, KEY_NAME)
    End Function
    Private Function Save_Settings(ByVal RegInfo As String)
        SaveSetting ADDIN_NAME, SETTING_ITEM, KEY_NAME, RegInfo
    End Function
    Private Function Get_CpuId() As String
        Dim CpuSet
        Dim OneCpu
        Set CpuSet = GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesOf("Win32_Processor")
        For Each OneCpu In CpuSet
            Get_CpuId = OneCpu.ProcessorId
        Next
    End Function
    Private Function HasRegisterSheet(Optional SheetName As String = "Register") As Boolean
        Dim HasRegSht As Boolean
        Dim Sht As Worksheet
        HasRegisterSheet = False
        For Each Sht In ThisWorkbook.Worksheets
            If Sht.Name = SheetName Then
                HasRegisterSheet = True
                Exit For
            End If
        Next Sht
    End Function
    

      

  • 相关阅读:
    【Spring Framework】10、代理模式
    【Spring Framework】8、使用注解开发
    Codeforces 516E
    AtCoder Grand Contest 055 题解
    Codeforces 1606F
    贪心/构造/DP 杂题选做
    整数拆分最大乘积
    CSP-S2021 被碾压记
    洛谷 P2791
    LCT 小记
  • 原文地址:https://www.cnblogs.com/nextseven/p/7411475.html
Copyright © 2020-2023  润新知