Professional Visual Basic 6 MTS Programming

  • Upload
    buitruc

  • View
    228

  • Download
    7

Embed Size (px)

Citation preview

PPInstall.vbsOption Explicit

'Stop

On Error Resume Next

Dim blnRet Dim strPackageID Dim strRoleID

strPackageID = RecreatePackage("PasswordPersist")

If VarType(strPackageID) = 0 Then MsgBox "Package PasswordPersist was not created."

Else ' Now install each component. blnRet = ImportComponent(strPackageID, "PPIndependents.User", _ "Required", "Y") If blnRet = False Then MsgBox "Component PPIndependents.User was not added to " & _ "PasswordPersist." End If

blnRet = ImportComponent(strPackageID, "PPIndependents.System", _ "Required", "Y") If blnRet = False Then MsgBox "Component PPIndependents.System was not added to " & _ "PasswordPersist." End If

blnRet = ImportComponent(strPackageID, "PPIndependents.Attribute", _ "Required", "Y") If blnRet = False Then MsgBox "Component PPIndependents.Attribute was not added to " & _ "PasswordPersist." End If

blnRet = ImportComponent(strPackageID, "PPAssociations.SystemUser", _ "Required", "Y") If blnRet = False Then MsgBox "Component PPAssociations.User was not added to " & _ "PasswordPersist." End If

blnRet = ImportComponent(strPackageID, _ "PPAssociations.SystemUserAttributes", "Required", "Y") If blnRet = False Then MsgBox "Component PPAssociations.SystemUserAttributes was not " & _ "added to PasswordPersist." End If

' Add a role strRoleID = CreateRole(strPackageID, "PPAllowedUser")

If VarType(strRoleID) = 0 Then MsgBox "Role PPAllowedUser was not added to PasswordPersist."

Else ' Now add users to the role.' Modify for your user settings' blnRet = AddUserToRole(strPackageID, strRoleID, "ServerName\UserName") blnRet = AddUserToRole(strPackageID, strRoleID, "BTVS\lisas")

If blnRet = False Then MsgBox "User WROX\Mattb was not added to PPAllowedUser" End If

' Modify' blnRet = AddUserToRole(strPackageID, strRoleID, _' "ServerName\IUSR_ServerName") blnRet = AddUserToRole(strPackageID, strRoleID, _ "BTVS\IUSR_BTVS")

If blnRet = False Then' Modify' MsgBox "User ServerName\IUSR_ServerName was not added to PPAllowedUser" MsgBox "BTVS\lisas was not added to PPAllowedUser" End If

End If

End If

MsgBox "Installation is complete."

Function RecreatePackage(PackageName)

On Error Resume Next

Dim lngC Dim objCatalog Dim objNewPackage Dim objPackages Dim objUtil

Set objCatalog = CreateObject("MTSAdmin.Catalog.1")

If Err Then Exit Function

Set objPackages = objCatalog.GetCollection("Packages")

If Err Then Exit Function

objPackages.Populate

For lngC = 0 To (objPackages.Count - 1) If objPackages.Item(lngC).Value("Name") = PackageName Then ' Get rid of the package. Set objUtil = objPackages.GetUtilInterface objUtil.ShutdownPackage objPackages.Item(lngC).Value("ID") objPackages.Remove (lngC) Exit For End If

Next

If Err Then Exit Function

objPackages.SaveChanges

Set objNewPackage = objPackages.Add objNewPackage.Value("Name") = PackageName

If Err Then Exit Function

objPackages.SaveChanges

RecreatePackage = objNewPackage.Value("ID")

Set objNewPackage = Nothing Set objPackages = Nothing Set objCatalog = Nothing

End Function

Function ImportComponent(PackageID, ComponentProgID, TransactionType, _ SecurityEnabled)

On Error Resume Next

Dim lngC Dim objCatalog Dim objComponent Dim objComponents Dim objComponentUtil Dim objPackage Dim objPackages

ImportComponent = False

Set objCatalog = CreateObject("MTSAdmin.Catalog.1")

If Err Then Exit Function

Set objPackages = objCatalog.GetCollection("Packages")

If Err Then Exit Function

objPackages.Populate

For Each objPackage In objPackages If objPackage.Key = PackageID Then ' We now have the correct reference. Exit For End If

Next

If objPackage Is Nothing Then Exit Function

Set objComponents = objPackages.GetCollection("ComponentsInPackage", _ objPackage.Key)

Set objComponentUtil = objComponents.GetUtilInterface

objComponentUtil.ImportComponentByName(ComponentProgID)

If Err Then Exit Function

objComponents.Populate

For Each objComponent In objComponents

If objComponent.Value("ProgID") = ComponentProgID Then

objComponent.Value("Transaction") = TransactionType objComponent.Value("SecurityEnabled") = SecurityEnabled Exit For End If

Next

If Err Then Exit Function

objComponents.SaveChanges

If Err Then Exit Function

Set objCatalog = Nothing Set objComponent = Nothing Set objComponents = Nothing Set objComponentUtil = Nothing Set objPackage = Nothing Set objPackages = Nothing

ImportComponent = True

End Function

Public Function CreateRole(PackageID, NewRoleName)

On Error Resume Next

Dim lngC Dim objCatalog Dim objNewRole Dim objRoles Dim objPackage Dim objPackages

Set objCatalog = CreateObject("MTSAdmin.Catalog.1")

If Err Then Exit Function

Set objPackages = objCatalog.GetCollection("Packages")

If Err Then Exit Function

objPackages.Populate

For Each objPackage In objPackages If objPackage.Key = PackageID Then ' We now have the correct reference. Exit For End If

Next

If objPackage Is Nothing Then Exit Function

Set objRoles = objPackages.GetCollection("RolesInPackage", _ objPackage.Key)

If Err Then Exit Function

objRoles.Populate

Set objNewRole = objRoles.Add

objNewRole.Value("Name") = NewRoleName

If Err Then Exit Function

objRoles.SaveChanges

If Err Then Exit Function

CreateRole = objNewRole.Value("ID")

Set objCatalog = Nothing Set objNewRole = Nothing Set objRoles = Nothing Set objPackage = Nothing Set objPackages = Nothing

End Function

Function AddUserToRole(PackageID, RoleID, UserName)

On Error Resume Next

Dim lngC Dim objCatalog Dim objNewRole Dim objRoles Dim objRole Dim objPackage Dim objPackages Dim objUser Dim objUsers

AddUserToRole = False

Set objCatalog = CreateObject("MTSAdmin.Catalog.1")

If Err Then Exit Function

Set objPackages = objCatalog.GetCollection("Packages")

If Err Then Exit Function

objPackages.Populate

For Each objPackage In objPackages If objPackage.Key = PackageID Then Exit For End If

Next

If objPackage Is Nothing Then Exit Function

Set objRoles = objPackages.GetCollection("RolesInPackage", _ objPackage.Key)

If Err Then Exit Function

objRoles.Populate

For Each objRole in objRoles If objRole.Key = RoleID Then Exit For End If

Next

If objRole Is Nothing Then Exit Function

Set objUsers = objRoles.GetCollection("UsersInRole", objRole.Key)

If Err Then Exit Function

objUsers.Populate

Set objUser = objUsers.Add

objUser.Value("User") = UserName

If Err Then Exit Function

objUsers.SaveChanges

If Err Then Exit Function

If UserName = objUser.Name Then AddUserToRole = True End If

Set objCatalog = Nothing Set objNewRole = Nothing Set objRole = Nothing Set objRoles = Nothing Set objPackage = Nothing Set objPackages = Nothing Set objUser = Nothing Set objUsers = Nothing

End Function

Wrox/code/PasswordPersist/Chapter12/AttributeList.asp