0

我无法UserAssignment使用 .net 访问容器。我能够进入应用程序容器,但没有进一步。任何想法将不胜感激。我正在使用的代码是:

Private Function runScript2(userName As String, applicationName As String) As String
    Dim rs As Runspace = RunspaceFactory.CreateRunspace
    rs.Open()

    Dim ps As PowerShell = PowerShell.Create
    ps.Runspace = rs
    Dim sb2 As New StringBuilder
    sb2.AppendLine("Import-Module -Name C:\RemoteDesktopServices\RemoteDesktopServices.psd1")
    sb2.AppendLine("Get-ChildItem -Path RDS:\") 'this works
    sb2.AppendLine("Get-ChildItem -Path RDS:\RemoteApp\RemoteAppPrograms\WordPad\")  'this works
    sb2.AppendLine("Get-ChildItem -Path RDS:\RemoteApp\RemoteAppPrograms\WordPad\UserAssignment") 'this does not work, no error
    sb2.AppendLine("Get-ChildItem -Path C:\MyScripts")
    ps.AddScript(sb2.ToString)

    Dim output As Collection(Of PSObject) = ps.Invoke
    Dim sb As New StringBuilder
    For Each obj As PSObject In output
        If TypeOf (obj.BaseObject) Is DirectoryInfo Then
            Dim fle As DirectoryInfo = CType(obj.BaseObject, DirectoryInfo)
            sb.AppendLine(fle.FullName)
        ElseIf TypeOf (obj.BaseObject) Is FileInfo Then
            Dim fle As FileInfo = CType(obj.BaseObject, FileInfo)
            sb.AppendLine(fle.FullName)
        Else
            sb.AppendLine(obj.BaseObject.ToString)
        End If
    Next
    Return sb.ToString

End Function
4

1 回答 1

0

It doesn't fail, you simply has no any UserAssignments yet, so it return you nothing. As soon as you will add some user - it will return it. You can check it by adding user manually through Computer Management console

于 2012-04-18T10:36:02.493 回答