Visual Basic WMI System Services
Win32_CodecFile: WMI Installed Codec File Info
     
Posted:   Wednesday October 30, 2002
Updated:   Monday November 28, 2011
     
Applies to:   VB5, VB6
Developed with:   VB6, Windows XP
OS restrictions:   Windows NT, 2000, XP. See Prerequisites below.
Author:   VBnet - Randy Birch
     

Related:  

 
     

 

 Prerequisites
Windows Script Host is built into Microsoft Windows 98, 2000, ME and XP. If you are running Windows 95 or NT4, you can download Windows Script Host from the Microsoft Windows Script Technologies Web site at http://msdn.microsoft.com/scripting/. Some information is not returned on non-NT-based systems.

A reference set in Projects / References to the Microsoft WMI Scripting Library.


Win32_CodecFile represents the audio or video codec installed on the computer system. Codecs convert one media format type to another, typically a compressed format to an uncompressed format. The name codec is derived from a combination of compress and decompress. For example, a codec can convert a compressed format such as MS-ADPCM to an uncompressed format such as PCM, which most audio hardware can play directly.

This demo and illustration shows only some of the available information from the class. For a complete listing see the Comments section below. Note that some systems may not return information in all class properties.

 BAS Module Code
None.

 Form Code
To a form add a command button (Command1) and a listbox (List1). Set a reference in Projects / References to the Microsoft WMI Scripting Library, and add the following to the form:

Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996-2011 VBnet/Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
'               applications, but you may not reproduce 
'               or publish this code on any web site,
'               online service, or distribute as source 
'               on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub Command1_Click()

   Call wmiWin32CodecFile
   
End Sub


Private Sub Form_Load()
   
   Command1.Caption = "Win32_CodecFile"

End Sub


Private Sub wmiWin32CodecFile()
      
   Dim objset  As SWbemObjectSet
   Dim obj     As SWbemObject

   Set objset = GetObject("winmgmts:{impersonationLevel=impersonate}"). _
                                      InstancesOf("Win32_CodecFile")
   
   On Local Error Resume Next

   For Each obj In objset

      With List1
         .AddItem "FileName: " & obj.FileName
         .AddItem "Version: " & obj.Version
         .AddItem "Manufacturer: " & obj.Manufacturer
         .AddItem "Name: " & obj.Name
         .AddItem "Description: " & obj.Description
         .AddItem "Caption: " & obj.Caption
         .AddItem "EightDotThreeFileName: " & obj.EightDotThreeFileName
         .AddItem "AccessMask: " & obj.AccessMask
         .AddItem "InstallDate: " & ConvertDate(obj.InstallDate)
         .AddItem "LastAccessed: " & ConvertDate(obj.LastAccessed)
         .AddItem "LastModified: " & ConvertDate(obj.LastModified)
         .AddItem ""
      End With
        
   Next
   
End Sub


Private Function ConvertDate(dtb) As String

   Dim d As String
   Dim t As String
   Dim bias As Long
   
   If Not IsNull(dtb) Then
   
      bias = SplitDateTimeBias(CStr(dtb), d, t)
      ConvertDate = Format$(d, "dddd mmm d, yyyy") & " at " & _
                    Format$(t, "hh:mm:ss")
   
   Else
   
      ConvertDate = "(date returned null)"
      
   End If
            
End Function


Private Function SplitDateTimeBias(leasedate As String, _
                                   leasedatepart As String, _
                                   leasetimepart As String) As Long

  'takes a datetime returned 
  'and splits out the date and time
  'components, returns them in the
  'leasedatepart and leasetimepart
  'passed variables, and returns the
  'bias to be applied to the resultant date.
   Dim pos     As Long
   Dim bias    As Long
  
   pos = InStr(leasedate, ".")

   If pos > 0 Then

      bias = StripTimeZoneBias(leasedate)
      leasedatepart = Left$(leasedate, 8)
      leasetimepart = Mid$(leasedate, 9, pos - Len(leasedatepart) - 1)
      leasedatepart = InsertInString(leasedatepart, "-", 5, "")
      leasedatepart = InsertInString(leasedatepart, "-", 8, "")
      leasetimepart = InsertInString(leasetimepart, ":", 3, "")
      leasetimepart = InsertInString(leasetimepart, ":", 6, "")
      
      SplitDateTimeBias = bias

   Else

   End If

End Function


Private Function StripTimeZoneBias(leasedate As String) As Long

   Dim pos As Long
   Dim tmp As String
   
   pos = InStr(leasedate, "-")
   
   If pos = 0 Then
      
      pos = InStr(leasedate, "+")
      
      If pos = 0 Then
         StripTimeZoneBias = 0
      Else
      
      End If
      
   Else
   
      tmp = Mid$(leasedate, pos, Len(leasedate))
      leasedate = Mid$(leasedate, 1, pos - 1)
      StripTimeZoneBias = CLng(tmp)
      
   End If
    
End Function


Private Function InsertInString(ByVal sOriginal As String, _
                                sReplace As String, _
                                nField As Long, _
                                sDelimeter As String) As String
    
   'c 1998 Mario Lavignasse
   'Abbott Scientific
   'Replaces or inserts a string into a (any char) delimeted string
   '
   'Syntax:
   'sOriginal:  string of interest, returned unchanged
   'sReplace:   replacement or insert chr(s)
   'nField:     1-based position for the insert/replace to begin
   'sDelimeter: string to insert/replace. If empty, sReplace is
   '            inserted, if present sDelimeter is replaced by sReplace.
   '
   'Examples:
   'Inserting:
   ' x = InsertInString("Hello World", "Hello ", 7, "")
   '  (x="Hello Hello World")
   '
   'Replacing:
   ' x = InsertInString("Hello World", "Hello ", 7, "World")
   '   (x="Hello Hello")
         
   Dim lnCount As Long
   Dim lnStart As Long
   Dim lnLast As Long
    
   Do While InStr(lnStart + 1, sOriginal, sDelimeter) > 0
    
      lnStart = InStr(lnStart + 1, sOriginal, sDelimeter)
      lnCount = lnCount + 1
      
      If lnCount >= nField Then
         Exit Do
      End If
      
      lnLast = lnStart
        
   Loop
    
   
   Select Case lnCount
   
      Case 1
         InsertInString = sReplace & Mid$(sOriginal, lnStart)
      
      Case Is >= nField
         InsertInString = Mid$(sOriginal, 1, lnLast) & _
                               sReplace & Mid$(sOriginal, lnStart)
      Case Else
         InsertInString = sOriginal & _
                          String$((nField - 1) - lnCount, sDelimeter) & _
                          sReplace
   End Select
    
End Function
 Comments
All information returned in the Win32_CodecFile class (note that some systems may not return information in all class properties):
   
uint32 AccessMask;
boolean Archive;
string Caption;
boolean Compressed;
string CompressionMethod;
string CreationClassName;
datetime CreationDate;
string CSCreationClassName;
string CSName;
string Description;
string Drive;
string EightDotThreeFileName;
boolean Encrypted;
string EncryptionMethod;
string Extension;
string FileName;
uint64 FileSize;
string FileType;
string FSCreationClassName;
string FSName;
string Group;
boolean Hidden;
datetime InstallDate;
uint64 InUseCount;
datetime LastAccessed;
datetime LastModified;
string Manufacturer;
string Name;
string Path;
boolean Readable;
string Status;
boolean System;
string Version;
boolean Writeable;

 

AccessMask is a Read-only bitmap list of access rights to the given file or directory held by the user or group on whose behalf the instance is returned. This property is only supported under Windows NT and Windows 2000. On Windows 98 and on Windows NT/Windows 2000 FAT volumes, the FULL_ACCESS value is returned instead, indicating no security has been set on the object.
   

Value

Meaning

0 FILE_LIST_DIRECTORY
Grants the right to read data from the file. For a directory, this value grants the right to list the contents of the directory.
1 FILE_ADD_FILE
Grants the right to write data to the file. For a directory, this value grants the right to create a file in the directory.
2 FILE_ADD_SUBDIRECTORY
Grants the right to append data to the file. For a directory, this value grants the right to create a subdirectory.
3 FILE_READ_EA
Grants the right to read extended attributes.
4 FILE_WRITE_EA
Grants the right to write extended attributes.
5 FILE_TRAVERSE
Grants the right to execute a file. For a directory, the directory can be traversed.
6 FILE_DELETE_CHILD
Grants the right to delete a directory and all the files it contains (its children), even if the files are read-only.
7 FILE_READ_ATTRIBUTES
Grants the right to read file attributes.
8 FILE_WRITE_ATTRIBUTES
Grants the right to change file attributes.
16 DELETE
Grants delete access.
17 READ_CONTROL
Grants read access to the security descriptor and owner.
18 WRITE_DAC
Grants write access to the discretionary ACL.
19 WRITE_OWNER
Assigns the write owner.
20 SYNCHRONIZE
Synchronizes access and allows a process to wait for an object to enter the signalled state.

 

The Win32_CodecFile class defines the following methods.

Method Description
ChangeSecurityPermissions Changes the security permissions for the logical file specified in the object path.
ChangeSecurityPermissionsEx Changes the security permissions for the logical file specified in the object path.
Compress Compresses the logical file (or directory) specified in the object path.
CompressEx Compresses the logical file (or directory) specified in the object path.
Copy Copies the logical file or directory specified in the object path to the location specified by the input parameter.
CopyEx Class method that copies the logical file or directory specified in the object path to the location specified by the FileName parameter.
Delete Deletes the logical file (or directory) specified in the object path.
DeleteEx Deletes the logical file (or directory) specified in the object path.
GetEffectivePermission Determines whether the caller has the aggregated permissions specified by the Permission argument not only on the file object, but on the share the file or directory resides on (if it is on a share).
Rename Class method that renames the logical file (or directory) specified in the object path.
TakeOwnerShip Obtains ownership of the logical file specified in the object path.
TakeOwnerShipEx Class method that obtains ownership of the logical file specified in the object path.
Uncompress Uncompresses the logical file (or directory) specified in the object path.
UncompressEx Uncompresses the logical file (or directory) specified in the object path.

 
 

PayPal Link
Make payments with PayPal - it's fast, free and secure!

 
 
 
 

Copyright ©1996-2011 VBnet and Randy Birch. All Rights Reserved.
Terms of Use  |  Your Privacy

 

Hit Counter