Wie verwalten Sie COM + über PowerShell?


8

Gibt es ein PowerShell-Modul oder Befehle zum Verwalten von COM + -Komponenten? Insbesondere möchte ich:

  • Fragen Sie ab, ob eine COM + -Anwendung installiert / registriert ist.
  • Starten oder Beenden einer COM + -Anwendung.
  • Installieren / Registrieren oder Deinstallieren / Aufheben der Registrierung der COM + -Anwendung.

Ich bin sowohl in PowerShell als auch in COM + neu und verwende möglicherweise die falschen Begriffe (Installation vs. Registrierung usw.).


1
Dieser bevorstehende Webcast könnte für Sie interessant sein: richardspowershellblog.wordpress.com/2011/04/03/…
pk.

Antworten:


16

Liste der COM + -Komponenten

$comAdmin = New-Object -com ("COMAdmin.COMAdminCatalog.1")
$applications = $comAdmin.GetCollection("Applications") 
$applications.Populate() 

foreach ($application in $applications)
{

    $components = $applications.GetCollection("Components",$application.key)
    $components.Populate()
    foreach ($component in $components)
    {

        $dllName = $component.Value("DLL")
        $componentName = $component.Name

        "Component Name:$componentName"
        "DllName: $dllName`n"
    }
}

Komponenten stoppen / starten

$comAdmin.StartApplication("appName")
$comAdmin.ShutdownApplication("appName")

Installieren Sie die Com + -Anwendung mithilfe der InstallApplication- Methode

# Refer to: http://msdn.microsoft.com/en-us/library/ms681806(v=vs.85).aspx
$comAdmin.InstallApplication("fileName")

1

Hier ist eine Möglichkeit, eine com + -Anwendung mit Powershell zu registrieren. Sie müssen $ AppID und $ CLSID durch die eindeutige 128-Bit-Kennung Ihres Objekts ersetzen.

$AppID = "{123456789}"
$CLSID = "{123456789}"
$comAdmin = New-Object -comobject COMAdmin.COMAdminCatalog

function InstallApplication ( $comAdmin ) {
    $AppName = "foobar"
    $AppDesc = "foobar com plus object does stuff"

    $apps = $comAdmin.GetCollection("Applications")
    $apps.Populate();

    $appFound = $false
    foreach ($app in $apps ) {
        if ($app.Name -eq $AppName ) {
            $appFound = $true
            #break
        }
    }
    if (!($appFound )) {
        $app = $apps.Add()
        $app.Value("ID") = $AppID
        $app.Value("Name") = $AppName
        $app.Value("Description") = $AppDesc
        $app.Value("ApplicationAccessChecksEnabled") = $True
        $app.Value("AccessChecksLevel") = 1 #Component level
        $app.Value("Activation") = "Local"
        $apps.SaveChanges();
    }
    Else {
        Write-Host "$AppName already exists, skipping" -ForegroundColor green
    }

}
function InstallComponents( $comAdmin ) {

    $comAdmin.ImportComponent( $AppID, $CLSID )

    # Configure the directory service component
    $apps = $comAdmin.GetCollection("Applications")
    $apps.Populate();

    $comps = $apps.GetCollection("Components", $AppID)
    $comps.Populate();
    ForEach ($comp in $comps) {
        If ($comp.Key -eq $CLSID) {
            $ComponentFound = $True
            #break
        }
    }

    If ($ComponentFound) {
        $comp.Value("Description") = "foobar "
        $comp.Value("ComponentAccessChecksEnabled") = $true
        $comp.Value("ObjectPoolingEnabled") = $true
        $comp.Value("JustInTimeActivation") = $false
        $comp.Value("Synchronization") = 2  #Supported
        $comp.Value("Transaction") = 1      #Not supported
        $comps.SaveChanges();
    }
    Else {
        Write-Warning "CLSID $CLSID not found"
    }
}
function ConfigureSecurity( $comAdmin ) {

    $apps = $comAdmin.GetCollection("Applications")
    $apps.Populate();

    # Add Administrator, and User roles to the application.
    #https://msdn.microsoft.com/en-us/library/windows/desktop/ms678849%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
    $roles = $apps.GetCollection("Roles", $AppID)
    $roles.Populate();

    $found = $false
    foreach ( $role in $roles ) {
        if ($role.Key -eq "Administrators") {
            $found = $true
            #break
        }
    }
    if (!($found)) {
        $role = $roles.Add()
        $role.Value("Name") = "Administrators"
    }

    $found = $false
    foreach ($role in $roles ) {
        if ($role.Key -eq "Users") {
            $found = $true
            #break
        }
    }

    if (!($found)) {
        $role = $roles.Add()
        $role.Value("Name") = "Users"
    }

    $roles.SaveChanges();

  # Assign accounts to the roles

    $domain = (Get-WmiObject Win32_ComputerSystem).Domain
    if ($domain -like 'WORKGROUP') {
        Write-Warning "Not joined to domain, skipping com+ roles"
    }
    else {
        $users = $roles.GetCollection("UsersInRole", "Users")
        $user = $users.Add()
        $roleDescription = "$domain" + "\" + "Users"
        Write-Host "Adding com+ role $roleDescription" -ForegroundColor green
        $user.Value("User") = $roleDescription
        $users.SaveChanges();


        $users = $roles.GetCollection("UsersInRole", "Administrators")
        $user = $users.Add()
        $roleDescription = "$domain" + "\" + "fooAdmin"
        Write-Host "Adding com+ role $roleDescription" -ForegroundColor green
        $user.Value("User") = $roleDescription
        $user = $users.Add()
        $roleDescription = "$domain" + "\" + "barAdmin"
        Write-Host "Adding com+ role $roleDescription" -ForegroundColor green
        $user.Value("User") = $roleDescription
        $users.SaveChanges();

        # Configure component to allow access to role.
        $comps = $apps.GetCollection("Components", $AppID)
        $comps.Populate();

        ForEach ($comp In $comps ) {
          If ($comp.Key -eq $CLSID) {
              $ComponentFound = $True
              #  break
          }
        }
        If ($ComponentFound ) {
            $RolesForComponent = $comps.GetCollection("RolesForComponent", $CLSID)
            $RoleForComponent = $RolesForComponent.Add()
            $RoleForComponent.Value("Name") = "Administrators"
            $RoleForComponent = $RolesForComponent.Add()
            $RoleForComponent.Value("Name") = "Users"
            $RolesForComponent.SaveChanges();
        }
        Else {
            Write-Warning "CLSID $CLSID not found"
        }
    }


}

InstallApplication $comAdmin
InstallComponents $comAdmin
ConfigureSecurity $comAdmin
Durch die Nutzung unserer Website bestätigen Sie, dass Sie unsere Cookie-Richtlinie und Datenschutzrichtlinie gelesen und verstanden haben.
Licensed under cc by-sa 3.0 with attribution required.