WMI script for find correct System Volume

Discussion in 'Windows 7' started by Mr Jinje, Aug 25, 2009.

  1. nononsence

    nononsence MDL Addicted

    Aug 18, 2009
    809
    818
    30
    #21 nononsence, Sep 3, 2009
    Last edited by a moderator: Apr 20, 2017
  2. nononsence

    nononsence MDL Addicted

    Aug 18, 2009
    809
    818
    30
    #22 nononsence, Sep 3, 2009
    Last edited by a moderator: Apr 20, 2017
    and the install licence function

    Code:
    
    cert = "cert.xrm-ms"
    
    LicenceData = ReadAllTextFile(cert)
    
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    
    
        Dim objService
        Dim colServices
    
        On Error Resume Next
           
        Set colServices = objWMIService.ExecQuery("SELECT Version FROM SoftwareLicensingService")
        QuitIfError()
    
        For each objService in colServices
            QuitIfError()
            Exit For
        Next
    
        set GetServiceObject = objService    
    
    
    objService.InstallLicense(LicenceData)
    
    Function ReadAllTextFile(strFileName)
        Dim strData
        Dim oStream
        
        Set oStream = CreateObject("ADODB.Stream")
    
        oStream.Type = 2 'adTypeText
        oStream.Open
        oStream.Charset = GetFileEncoding(strFileName)
        oStream.LoadFromFile(strFileName)
    
        strData = oStream.ReadText(-1) 'adReadAll
    
        oStream.Close
    
        ReadAllTextFile = strData
    End Function
    
    
    Function GetFileEncoding(strFileName)
        Dim strData
        Dim strEncoding
        Dim oStream
    
        Set oStream = CreateObject("ADODB.Stream")
    
        oStream.Type = 1 'adTypeBinary
        oStream.Open
        oStream.LoadFromFile(strFileName)
    
        ' Default encoding is ascii
        strEncoding =  "ascii"
    
        strData = BinaryToString(oStream.Read(2))
    
        ' Check for little endian (x86) unicode preamble
        If (Len(strData) = 2) and strData = (Chr(255) + Chr(254)) Then
            strEncoding = "unicode"
        Else
            oStream.Position = 0
            strData = BinaryToString(oStream.Read(3))
    
            ' Check for utf-8 preamble
            If (Len(strData) >= 3) and strData = (Chr(239) + Chr(187) + Chr(191)) Then
                strEncoding = "utf-8"
            End If
        End If
    
        oStream.Close
    
        GetFileEncoding = strEncoding
    End Function
    
    
    Function BinaryToString(dataBinary)
      Dim i
      Dim str
    
      For i = 1 To LenB(dataBinary)
        str = str & Chr(AscB(MidB(dataBinary, i, 1)))
      Next
    
      BinaryToString = str
    End Function
    
    ' Returns string containing the whole text file data.
    ' Supports ascii, unicode (little-endian) and utf-8 encoding.
    Function ReadAllTextFile(strFileName)
        Dim strData
        Dim oStream
        
        Set oStream = CreateObject("ADODB.Stream")
    
        oStream.Type = 2 'adTypeText
        oStream.Open
        oStream.Charset = GetFileEncoding(strFileName)
        oStream.LoadFromFile(strFileName)
    
        strData = oStream.ReadText(-1) 'adReadAll
    
        oStream.Close
    
        ReadAllTextFile = strData
    End Function
    
    more functions to deal with cert file.
     
  3. Mr Jinje

    Mr Jinje MDL Expert

    Aug 19, 2009
    1,773
    1,096
    60
    #23 Mr Jinje, Sep 3, 2009
    Last edited by a moderator: Apr 20, 2017
    (OP)