Saturday, April 6, 2013

DAO ain't DOA

The latest build that I know about is DAO.DBEngine.120.

Its a bit tricky to write in powershell. Below is the code just in case anyone is looking for it:


    $iret = [System.Reflection.Assembly]::LoadWithPartialName("System.Management")
    $mc = new-object System.Management.ManagementClass
    $mc.Path.NamespacePath = "root\cimv2"
    $mc.Path.ClassName = "Win32_Process";
    $mc.Scope.Options.Authentication = [System.Management.AuthenticationLevel]::PacketPrivacy;
    $mc.Scope.Options.Impersonation = [System.Management.ImpersonationLevel]::Impersonate;
    $moc = $mc.GetInstances()

    $DBEngine = new-Object -comobject DAO.DBEngine.120
    $DBEngine.CreateDatabase("C:\Melody.mdb",  ";LANGID=0x0409;CP=1252;COUNTRY=0", 64)
    $db = $DBEngine.OpenDatabase("C:\Melody.mdb", $false, $false, "")
    $rs = $db.OpenRecordset("Properties");
    foreach($mo in $moc)
    {
         $rs.AddNew()
         $x=0
         $Fields = $rs.GetType().InvokeMember("Fields", [System.Reflection.BindingFlags]::GetProperty, $null, $rs, $null)
         foreach($Field in $Fields)
         {
                [System.String] $Name = $Field.Name
                [System.String] $Value = $mo.Properties.Item($Name).Value
                $Field.Value = $Value
         }
         $x=0
         $rs.Update()
    }

No comments:

Post a Comment