[THIN] Re: Groups for Application

  • From: "Callahan, Michael" <MichaelCallahan@xxxxxxxxxxxxxxxx>
  • To: "thin@xxxxxxxxxxxxx" <thin@xxxxxxxxxxxxx>
  • Date: Fri, 18 Mar 2005 07:29:26 -0600

Probably overkill for what you want, but I've attached three scripts I've
written - rename them with .wsf extensions:

AppReport.wsf - Lists all apps in the farm, their settings, users and groups
and outputs to a report in Word.
FarmAppSave.wsf - Does the above, but outputs to an .inf file and stores the
apps' icons to a backup directory.  Basically a farm app backup script.
FarmAppRestore.wsf - takes the .inf file generated by the FarmAppSave script
and restores apps into any farm.  Can easily be used to batch application
publishing or duplicate applications from another farm.

I've found them to be useful.

Michael

-----Original Message-----
From: BRUTON, Malcolm, FM [mailto:Malcolm.BRUTON@xxxxxxxx]
Sent: Friday, March 18, 2005 2:47 AM
To: 'thin@xxxxxxxxxxxxx'
Subject: [THIN] Re: Groups for Application


Use the Citrix server SDK.

I think you can get some good examples off http://www.citrix4ge.de

You can export all published apps to a file and read what groups are with
watch apps.

Malcolm

-----Original Message-----
From: thin-bounce@xxxxxxxxxxxxx [mailto:thin-bounce@xxxxxxxxxxxxx] On Behalf
Of Michael Day
Sent: 17 March 2005 16:56
To: thin@xxxxxxxxxxxxx
Subject: [THIN] Groups for Application

Does anyone know of an easy way to list what users and groups belong to
what published applications.  I am in the process of building a new
Citrix farm and moving our users to a new windows domain and I want to
clean up the groups.

Thanks for any help 


Michael Day
Senior Technical Analyst
Kinecor
mday@xxxxxxxxxxx
 

********************************************************
This Weeks Sponsor: RTO Software TScale
TScale provides a cost-effective way to improve performance, capacity and
stability for thin-client servers like Citrix MetaFrame or Microsoft
Terminal Services running Windows NT, 2000 or 2003.
http://www.rtosoft.com/enter.asp?id)6
********************************************************** 
Useful Thin Client Computing Links are available at:
http://thin.net/links.cfm
ThinWiki community - Excellent SBC Search Capabilities!
http://www.thinwiki.com
***********************************************************
For Archives, to Unsubscribe, Subscribe or 
set Digest or Vacation mode use the below link:
http://thin.net/citrixlist.cfm


****************************************************************************
*******
The Royal Bank of Scotland plc. Registered in Scotland No 90312.
Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB.

Authorised and regulated by the Financial Services Authority     
 
This e-mail message is confidential and for use by the                      
addressee only. If the message is received by anyone other             
than the addressee, please return the message to the sender          
by replying to it and then delete the message from your                    
computer. Internet e-mails are not necessarily secure. The               
Royal Bank of Scotland plc does not accept responsibility for          
changes made to this message after it was sent.

 

Whilst all reasonable care has been taken to avoid the                   
transmission of viruses, it is the responsibility of the recipient to

ensure that the onward transmission, opening or use of this             
message and any attachments will not adversely affect its               
systems or data.  No responsibility is accepted by The Royal           
Bank of Scotland plc in this regard and the recipient should carry   
out such virus and other checks as it considers appropriate.           
 
Visit our websites at:

http://www.rbs.co.uk/CBFM

http://www.rbsmarkets.com

 
****************************************************************************
****

********************************************************
This Weeks Sponsor: RTO Software TScale
TScale provides a cost-effective way to improve performance, capacity and
stability for thin-client servers like Citrix MetaFrame or Microsoft
Terminal Services running Windows NT, 2000 or 2003.
http://www.rtosoft.com/enter.asp?id=296
********************************************************** 
Useful Thin Client Computing Links are available at:
http://thin.net/links.cfm
ThinWiki community - Excellent SBC Search Capabilities!
http://www.thinwiki.com
***********************************************************
For Archives, to Unsubscribe, Subscribe or 
set Digest or Vacation mode use the below link:
http://thin.net/citrixlist.cfm

**********    Confidentiality Notice    **********
This electronic transmission and any attached documents or other
writings are confidential and are for the sole use of the intended
recipient(s) identified above. This message may contain information
that is privileged, confidential or otherwise protected from disclosure
under applicable law. If the receiver of this information is not the
intended recipient, or the employee, or agent responsible for delivering
the information to the intended recipient, you are hereby notified that
any use, reading, dissemination, distribution, copying or storage of this
information is strictly prohibited. If you have received this information in
error, please notify the sender by return email and delete the electronic
transmission, including all attachments from your system.
'*******************************************************************************
'Written by Michael Callahan
'Date: 01/06/2005
'
'AppReport.wsf
'
'Description: List all applications in a farm and the users and servers 
assigned to them
'Report  to Microsoft Word document.             
'Requires Microsoft Word be installed on the machine you are running this from!
'
'
'*******************************************************************************
<package>
    <job id=" FarmApplications">

        <comment>

        File:           AppReportWord.wsf
        Description:    List all applications in a farm and the users and 
servers assigned to them - output in MS Word.
        Requirements:   WSH 5.5 or higher.
        
        

        </comment>
        <runtime>
            <description>
               List Servers and Users for all apps  in the farm.
            </description>
              
        </runtime>
        <reference object="MetaFrameCOM.MetaFrameFarm"/>
        <script language="VBScript">
       'On Error Resume Next
        'Create the Word document
        Set objWord = CreateObject("Word.Application")
        objWord.Visible = True
        Set objDoc = objWord.Documents.Add()
        Set objSelection = objWord.Selection
        objDoc.Paragraphs.KeepTogether = True
        
        
            Dim theFarm,AppName ,anApp,aServer, Array()
            
            '
            'Set up basic scripting objects
            '
            Set oShell = WScript.CreateObject("WScript.Shell")
            Set oFso = CreateObject("Scripting.FileSystemObject")
            Set oWshNetwork = WScript.CreateObject("WScript.Network")
            sScriptFullName = WScript.ScriptFullName
            sScriptPath = Left(sScriptFullName, InStrRev(sScriptFullName, "\"))

            
            '
            ' Create MetaFrameFarm object
            '

            Set theFarm = CreateObject("MetaFrameCOM.MetaFrameFarm")
            if Err.Number <> 0 Then
                WScript.Echo "Can't create MetaFrameFarm object"
                WScript.Echo "(" & Err.Number & ") " & Err.Description
                WScript.Echo ""
                WScript.Quit Err.Number
            End if

            '
            ' Initialize the farm object.
            '

            theFarm.Initialize(MetaFrameWinFarmObject)
            if Err.Number <> 0 Then
                WScript.Echo "Can't  Initialize MetaFrameFarm object"
                WScript.Echo "(" & Err.Number & ") " & Err.Description
                WScript.Echo ""
                WScript.Quit Err.Number
            End if
            
            '
            'Set  file
            '
            '
            '
            ' Are you Citrix Administrator?
            '

            If theFarm.WinFarmObject.IsCitrixAdministrator = 0 then
                WScript.Echo "You must be a Citrix admin to run this script" 
                WScript.Echo ""
                WScript.Quit 0
            End If

            '
            ' Print out the farm name.
            '
            WScript.Echo "MetaFrame Farm Name: " & theFarm.FarmName
            WScript.Echo ""
            objSelection.Font.Name = "Arial"
            objSelection.Font.Size = "18"
            objSelection.TypeText theFarm.FarmName & " Applications Report"
            objSelection.TypeParagraph()
            '
            objSelection.Font.Size = "14"
            objSelection.TypeText "" & Date()
            objSelection.TypeParagraph()
            objSelection.TypeParagraph()
            '
            '
            objSelection.Font.Size = "10"
            'Loop through all applications in the farm 
        
            For Each anApp In theFarm.Applications
            Set aWinApp = anApp.WinAppObject

                if Err.Number <> 0 Then
                    WScript.Echo "Can't enumerate applications"
                    WScript.Echo "(" & Err.Number & ") " & Err.Description
                    WScript.Echo ""
                    WScript.Quit Err.Number
                End if
              If aWinApp.PNAttributes AND MFWinAppDesktop Then 'If these values 
are True then it is a published desktop
              
              WScript.Echo "Application Name: " & anApp.AppName
              objSelection.Font.Bold = True
              objSelection.TypeText "Application Name: "
              objSelection.Font.Bold = False
              objSelection.TypeText " " & anApp.AppName
              objSelection.TypeParagraph()
              
              WScript.Echo "Distinguished Name: " & anApp.DistinguishedName
              objSelection.Font.Bold = True
              objSelection.TypeText "Distinguished Name: "
              objSelection.Font.Bold = False
              objSelection.TypeText " " & anApp.DistinguishedName
              objSelection.TypeParagraph()
              
              WScript.Echo "Command Line: " & "Published Desktop"
              objSelection.Font.Bold = True
              objSelection.TypeText "Command Line: "
              objSelection.Font.Bold = False
              objSelection.TypeText " " & "Published Desktop"
              objSelection.TypeParagraph()
              
                        If aWinApp.PNFolder <> "" Then
                        WScript.Echo "Program Neighborhood Folder: " & 
aWinApp.PNFolder
                        objSelection.Font.Bold = True
                        objSelection.TypeText "Program Neighborhood Folder: "
                        objSelection.Font.Bold = False
                        objSelection.TypeText " " & aWinApp.PNFolder
                        objSelection.TypeParagraph()
                        End If
              Else
              
              WScript.Echo "Application Name: " & anApp.AppName
              WScript.Echo "Application Name: " & anApp.AppName
              objSelection.Font.Bold = True
              objSelection.TypeText "Application Name: "
              objSelection.Font.Bold = False
              objSelection.TypeText " " & anApp.AppName
              objSelection.TypeParagraph()
              
              WScript.Echo "Distinguished Name: " & anApp.DistinguishedName
              objSelection.Font.Bold = True
              objSelection.TypeText "Distinguished Name: "
              objSelection.Font.Bold = False
              objSelection.TypeText " " & anApp.DistinguishedName
              objSelection.TypeParagraph()
              
              WScript.Echo "Command Line: " & aWinApp.DefaultInitProg
              objSelection.Font.Bold = True
              objSelection.TypeText "Command Line: "
              objSelection.Font.Bold = False
              objSelection.TypeText " " & aWinApp.DefaultInitProg
              objSelection.TypeParagraph()
              
              WScript.Echo "Working Directory: " & aWinApp.DefaultWorkDir
              objSelection.Font.Bold = True
              objSelection.TypeText "Working Directory: "
              objSelection.Font.Bold = False
              objSelection.TypeText " " & aWinApp.DefaultWorkDir
              objSelection.TypeParagraph()
                        If aWinApp.PNFolder <> "" Then
                        WScript.Echo "Program Neighborhood Folder: " & 
aWinApp.PNFolder
                        objSelection.Font.Bold = True
                        objSelection.TypeText "Program Neighborhood Folder: "
                        objSelection.Font.Bold = False
                        objSelection.TypeText " " & aWinApp.PNFolder
                        objSelection.TypeParagraph()
                        End If
              End If
              objSelection.TypeParagraph()
              objSelection.Font.Size = "10"
              objSelection.Font.Bold = True
              objSelection.TypeText "" & "Servers: "
              objSelection.TypeParagraph()
              
              objSelection.Font.Size = "10"
              objSelection.Font.Bold = False
            
               'Print ServerName for the app.
               'Grab all servers into an array, then sort by name
               sCount = 0
                 For Each aServer In anApp.Servers
                 
                                         ReDim Preserve array(sCount)
                                         array(sCount) = aServer.ServerName
                                         sCount = sCount + 1
                                         Next
                                                For i = (UBound(array) - 1) to 
0 Step -1
                                                        For j= 0 to i
                                                                If 
UCase(array(j)) > UCase(array(j+1)) Then
                                                                strHolder = 
array(j+1)
                                                                array(j+1) = 
array(j)
                                                                array(j) = 
strHolder
                                                                End If
                                                        Next
                                                Next
               
               For i=0 to Ubound(Array) 'Output the sorted results
                 
                 WScript.Echo "Server Name: " & Array(i)
                 objSelection.TypeText vbTab & Array(i)
                 objSelection.InsertParagraphAfter()
                                  
                 Next
                 objSelection.TypeParagraph()
              WScript.Echo ""
              'objSelection.TypeParagraph()
                            
              objSelection.Font.Size = "10"
              objSelection.Font.Bold = True
              objSelection.TypeText "" & "Users: "
              objSelection.TypeParagraph()
              
              objSelection.Font.Size = "10"
              objSelection.Font.Bold = False
              
            'List users granted access to the published app
            For Each anUser In anApp.Users
                                    
                                        '
                                        ' MetaFrameUser object.
                                        '
                                        
                                        If nUserCount = 0 then
                                        WScript.Echo "Users            : " & 
anUser.AAName & "\" & anUser.UserName
                                        objSelection.TypeText vbTab & 
anUser.AAName & "\" & anUser.UserName
                                        objSelection.TypeParagraph()
                                        Else                        
                                        WScript.Echo "                   " & 
anUser.AAName & "\" & anUser.UserName
                                        objSelection.TypeText vbTab & 
anUser.AAName & "\" & anUser.UserName
                                        objSelection.TypeParagraph()
                                        End if           
                                        
                                        
                                        
            Next    
                objSelection.TypeParagraph()
                objSelection.Font.Size = "10"
                objSelection.Font.Bold = True
                objSelection.TypeText "" & "Groups: "
                objSelection.TypeParagraph()
                
                objSelection.Font.Size = "10"
                objSelection.Font.Bold = False
                                    'List groups granted access to the 
published app
                                    For Each anGroup In anApp.Groups
                                    
                                        '
                                        ' MetaFrameGroup object.
                                        '
                    
                                        If nUserCount = 0 Then
                                        WScript.Echo "Users            : " & 
anGroup.AAName & "\" & anGroup.GroupName
                                        objSelection.TypeText vbTab & 
anGroup.AAName & "\" & anGroup.GroupName
                                        objSelection.TypeParagraph()
                                        Else
                                        WScript.Echo "                   " & 
anGroup.AAName & "\" & anGroup.GroupName
                                        objSelection.TypeText vbTab & 
anGroup.AAName & "\" & anGroup.GroupName
                                        objSelection.TypeParagraph()
                                        End If    
                                    Next
           objSelection.TypeParagraph()
           objSelection.TypeParagraph()
           objSelection.InlineShapes.AddHorizontalLineStandard 'Add horizontal 
line between application sets
           Next
     'Save the doc, quit Word and clean up variables      
     objDoc.SaveAs sScriptPath & "\" & theFarm.FarmName & " Application 
Report.doc"        
    objDoc.Close
    objWord.Quit
    Set objDoc = Nothing
    Set objWord = Nothing

         </script>
    </job>
</package>
<package>
    <job id="FarmAppRestore">

        <comment>

            FarmAppRestore.wsf

            This script requires Windows Scripting Host 5.5 or higher.
            You will be prompted for the name of the .inf file to restore from; 
this file
            should be located in the same directory you are running the script 
from.  When prompted,
            type in the name of the file only - for example, "MyApps.inf".
            
            Icons - application icons should be located in an "icons" folder in 
the same directory the 
            script is running from.  Ideally, these will have been generated by 
the FarmAppSave.wsf script.
            If they are provided by some other means, then give them the same 
name as the application being
            restored - for example, "MyApplicationProd.ico".
            
            This script should be run on a MetaFrame server.  Tested on XP FR3.
            
        </comment>
<reference object="MetaFrameCOM.MetaFrameFarm"/>
<script language="VBScript">
On Error Resume Next

'Set up basic scripting objects
Set oShell = WScript.CreateObject("WScript.Shell")
Set oFso = CreateObject("Scripting.FileSystemObject")
Set oWshNetwork = WScript.CreateObject("WScript.Network")
sScriptFullName = WScript.ScriptFullName
sScriptPath = Left(sScriptFullName, InStrRev(sScriptFullName, "\"))
Const ForReading = 1

'Get name of .inf file to restore from - should be in the same directory as the 
script
sFileName = InputBox("Enter the name of the file to read:","Information Needed")

'Create Regular Expressions to delineate each section of the INF file
Set oREStart = new RegExp
Set oREServers = new RegExp
Set oREUsers = new RegExp
Set oREGroups = new RegExp
Set OREEnd = new RegExp
Set oREBlank = new RegExp

oREStart.Pattern = "^\s*\[\s*" & "Application" & "\s*\]\s*$"
oREStart.IgnoreCase = True
oREServers.Pattern = "^\s*\[\s*" & "Servers" & "\s*\]\s*$"
oREServers.IgnoreCase = True
oREUsers.Pattern = "^\s*\[\s*" & "Users" & "\s*\]\s*$"
oREUsers.IgnoreCase = True
oREGroups.Pattern = "^\s*\[\s*" & "Groups" & "\s*\]\s*$"
oREGroups.IgnoreCase = True
oREEnd.Pattern = "^\s*\[\s*" & "End Application" & "\s*\]\s*$"
oREEnd.IgnoreCase = True


'Create MFCOM farm object.
            Set myFarm = CreateObject("MetaFrameCOM.MetaFrameFarm")
            if Err.Number <> 0 Then
                WScript.Echo "Can't create MetaFrameFarm object"
                WScript.Echo "(" & Err.Number & ") " & Err.Description
                WScript.Echo ""
                WScript.Quit Err.Number
            End if

            ' Initialize the farm object.
            myFarm.Initialize(MetaFrameWinFarmObject)
            if Err.Number <> 0 Then
                WScript.Echo "Can't  Initialize MetaFrameFarm object"
                WScript.Echo "(" & Err.Number & ") " & Err.Description
                WScript.Echo ""
                WScript.Quit Err.Number
            End if

            ' Are you Citrix Administrator?
            if myFarm.WinFarmObject.IsCitrixAdministrator = 0 then
                WScript.Echo _
                    "You must be a Citrix administrator to run this script" 
                WScript.Echo ""
                WScript.Quit 0
            End If


Set oStream = oFSO.OpenTextFile(sScriptPath & "\" & sFilename, ForReading)
nState = 0
Do Until oStream.AtEndOfStream
        sLine = oStream.ReadLine
        Select Case nState
                Case 0
                        If oREStart.Test(sLine) Then
                        Wscript.echo "Reading the Application Section..."
                                         'Create a new application object.
                                        Set myApp = 
myFarm.AddApplication(MetaFrameWinAppObject)
                                        If Err.Number <> 0 Then
                                            WScript.Echo "Can't create 
application object"
                                            WScript.Echo "(" & Err.Number & ") 
" & Err.Description
                                            WScript.Echo ""
                                        End If
                                        Set theWinApp = myApp.WinAppObject
                        WScript.Echo
                        nState = 1
                        End If
                
                Case 1
                        If sLine = "" Then
                        WScript.Echo
                        WScript.Echo "Ending Application Section..."
                        WScript.Echo
                        ElseIf oREServers.Test(sLine) Then
                        Wscript.echo "Reading the Servers Section..."
                        WScript.Echo
                        nState = 2
                        Else
                        'Read line in INF file and set up variables and values, 
then apply to the application object
                        sAppVal = Split(sLine,"=")

                                Select Case sAppVal(0)
                                
                                Case "AppName"
                                sAppName = sAppVal(1)
                                myApp.AppName = sAppVal(1)
                                WScript.Echo "AppName = " & myApp.AppName
                                
                                Case "Description"
                                myApp.Description = sAppval(1)
                                WScript.Echo "Description = " & 
myApp.Description
                                
                                'Case "DistinguishedName"
                                'myApp.DistinguishedName = sAppval(1)
                                'WScript.Echo "DistinguishedName = " & 
myApp.DistinguishedName
                                
                                Case "DefaultInitProg"
                                If sAppval(1) = "PublishedDesktop" Then
                                theWinApp.PNAttributes = MFWinAppDesktop
                                WScript.Echo "theWinApp.PNAttributes = 
MFWinAppDesktop"
                                theWinApp.ReadIconFromFile sScriptPath & 
"\icons\" & myApp.AppName & ".ico", 0
                                Else
                                theWinApp.DefaultInitProg = sAppval(1)
                                WScript.Echo "DefaultInitProg = " & 
theWinApp.DefaultInitProg
                                theWinApp.ReadIconFromFile sScriptPath & 
"\icons\" & myApp.AppName & ".ico", 0
                                End If
                                
                                Case "DefaultWorkDir"
                                theWinApp.DefaultWorkDir = sAppval(1)
                                WScript.Echo "DefaultWorkDir = " & 
theWinApp.DefaultWorkDir
                                
                                Case "MFAttributes"
                                theWinApp.MFAttributes = sAppval(1)
                                WScript.Echo "MFAttributes = " & 
theWinApp.MFAttributes
                                
                                Case "PNAttributes"
                                theWinApp.PNAttributes = sAppval(1)
                                WScript.Echo "PNAttributes = " & 
theWinApp.PNAttributes
                                
                                Case "PNFolder"
                                theWinApp.PNFolder = sAppval(1)
                                WScript.Echo "PNFolder = " & theWinApp.PNFolder
                                
                                Case "DefaultEncryption"
                                theWinApp.DefaultEncryption = sAppval(1)
                                WScript.Echo "DefaultEncryption = " & 
theWinApp.DefaultEncryption
                                
                                Case "DefaultSoundType"
                                theWinApp.DefaultSoundType = sAppval(1)
                                WScript.Echo "DefaultSoundType = " & 
theWinApp.DefaultSoundType
                                
                                Case "DefaultWindowColor"
                                theWinApp.DefaultWindowColor = sAppval(1)
                                WScript.Echo "DefaultWindowColor = " & 
theWinApp.DefaultWindowColor
                                
                                Case "DefaultWindowType"
                                theWinApp.DefaultWindowType = sAppval(1)
                                WScript.Echo "DefaultWindowType = " & 
theWinApp.DefaultWindowType
                                
                                Case "ParentFolderDN"
                                If theWinApp.ParentFolder.Exists(sAppval(1)) 
Then
                                theWinApp.ParentFolderDN = sAppval(1)
                                WScript.Echo "ParentFolderDN = " & 
theWinApp.ParentFolderDN
                                Else
                                WScript.Echo sAppval(1) & " does not exist; 
setting default app folder to Applications."
                                theWinApp.ParentFolderDN = "Applications"
                                End If
                                
                                Case "DesktopIntegrate"
                                theWinApp.DesktopIntegrate = sAppval(1)
                                WScript.Echo "DesktopIntegrate = " & 
theWinApp.DesktopIntegrate
                                
                                Case "WaitOnPrinterCreation"
                                theWinApp.WaitOnPrinterCreation = sAppval(1)
                                WScript.Echo "WaitOnPrinterCreation = " & 
theWinApp.WaitOnPrinterCreation
                                
                                Case "AllowMultiInstancePerUser"
                                theWinApp.AllowMultiInstancePerUser = sAppval(1)
                                WScript.Echo "AllowMultiInstancePerUser = " & 
theWinApp.AllowMultiInstancePerUser
                                
                                Case "InstanceLimit"
                                theWinApp.InstanceLimit = sAppval(1)
                                WScript.Echo "InstanceLimit = " & 
theWinApp.InstanceLimit
                                
                                Case "AddShortcutToClientDesktop"
                                theWinApp.AddShortcutToClientDesktop = 
sAppval(1)
                                WScript.Echo "AddShortcutToClientDesktop = " & 
theWinApp.AddShortcutToClientDesktop
                                
                                Case "AddToClientStartMenu"
                                theWinApp.AddToClientStartMenu = sAppval(1)
                                WScript.Echo "AddToClientStartMenu = " & 
theWinApp.AddToClientStartMenu
                                
                                Case "DefaultSoundType"
                                theWinApp.DefaultSoundType = sAppval(1)
                                WScript.Echo "DefaultSoundType = " & 
theWinApp.DefaultSoundType
                                
                                Case "EnableSSLConnections"
                                theWinApp.EnableSSLConnections = sAppval(1)
                                WScript.Echo "EnableSSLConnections = " & 
theWinApp.EnableSSLConnections
                                
                                Case "PlaceUnderProgramsFolder"
                                theWinApp.PlaceUnderProgramsFolder = sAppval(1)
                                WScript.Echo "PlaceUnderProgramsFolder = " & 
theWinApp.PlaceUnderProgramsFolder
                                
                                Case "StartMenuFolder"
                                theWinApp.StartMenuFolder = sAppval(1)
                                WScript.Echo "StartMenuFolder = " & 
theWinApp.StartMenuFolder
                                
                                Case "EnableApp"
                                theWinApp.EnableApp = sAppval(1)
                                WScript.Echo "EnableApp = " & 
theWinApp.EnableApp
                                
                                End Select
                                
                        End If
                        
                Case 2
                        If sLine = "" Then
                        WScript.Echo
                        WScript.Echo "Ending Servers Section..."
                        WScript.Echo
                        ElseIf oREUsers.Test(sLine) Then
                        Wscript.echo "Reading the Users Section..."
                        WScript.Echo
                        nState = 3
                        Else
                        Set AppSrv = 
CreateObject("MetaFrameCOM.MetaFrameAppSrvBinding")
                        AppSrv.Initialize MetaFrameWinSrvObject, sLine, 
myApp.DistinguishedName
                        theWinApp.AddServer AppSrv
                        WScript.Echo "Adding server " & sLine
                        End If
                Case 3
                        If sLine = "" Then
                        WScript.Echo
                        WScript.Echo "Ending Users Section..."
                        WScript.Echo
                        ElseIf oREGroups.Test(sLine) Then
                        Wscript.echo "Reading the Groups Section..."
                        WScript.Echo
                        nState = 4
                        Else
                        sUserVal = Split(sLine,"\")
                        theWinApp.AddUser MFAccountAuthorityNTDomain, 
sUserVal(0), sUserVal(2), sUserVal(1)
                        WScript.Echo "Adding user " & sUserVal(0) & "\" & 
sUserVal(1)
                        End If
                Case 4
                        If oREEnd.Test(sLine) Then
                        WScript.Echo
                        WScript.Echo "Ending Groups Section..."
                        WScript.Echo
                        WScript.Echo "Saving Application..."
                        ' Create the published application.
                                        myApp.SaveData
                                        If Err.Number <> 0 Then
                                        WScript.Echo "Can't create " & AppName
                                        WScript.Echo "(" & Err.Number & ") " & 
Err.Description
                                        WScript.Echo ""
                                        Err.Clear
                                        Else
                                        WScript.Echo AppName & " created 
successfully!"
                                        End If
                                        Set myApp = Nothing
                                        Set theWinApp = Nothing
                                        
                        WScript.Echo
                        WScript.Echo "Application complete"
                        WScript.Echo
                        nState = 5
                        Else
                        sGroupVal = Split(sLine,"\")
                        theWinApp.AddUser MFAccountAuthorityNTDomain, 
sGroupVal(0), sGroupVal(2), sGroupVal(1)
                        WScript.Echo "Adding group " & sGroupVal(0) & "\" & 
sGroupVal(1)
                        End If
                Case 5
                        nState = 0
                        
        End Select
        
Loop
Set oStream = Nothing
Set oREStart = Nothing
Set oREEND = Nothing


</script>

    </job>

</package>
'*******************************************************************************
'Written by Michael Callahan
'Date: 01/25/2005
'
'AppSave.wsf
'
'Description: List all applications in a farm and write the settings out to a 
file for restore.
'All files will be created in the same directory the script is run in; a folder 
named "icons" should also             
'be created in this directory for icon storage and retrieval.
'
'
'*******************************************************************************
<package>
    <job id=" FarmApplications">

        <comment>

        File:           FarmAppSave.wsf
        Description:    Backup application settings for all apps  in the farm.
        Requirements:   WSH 5.5 or higher.
                

        </comment>
        <runtime>
            <description>
               Backup application settings for all apps  in the farm.
            </description>
              
        </runtime>
        <reference object="MetaFrameCOM.MetaFrameFarm"/>
        <script language="VBScript">
        'On Error Resume Next
            Dim theFarm,AppName ,anApp,aServer
            
            '
            'Set up basic scripting objects
            '
            Set oShell = WScript.CreateObject("WScript.Shell")
            Set oFso = CreateObject("Scripting.FileSystemObject")
            Set oWshNetwork = WScript.CreateObject("WScript.Network")
            sScriptFullName = WScript.ScriptFullName
            sScriptPath = Left(sScriptFullName, InStrRev(sScriptFullName, "\"))

            
            '
            ' Create MetaFrameFarm object
            '

            Set theFarm = CreateObject("MetaFrameCOM.MetaFrameFarm")
            if Err.Number <> 0 Then
                WScript.Echo "Can't create MetaFrameFarm object"
                WScript.Echo "(" & Err.Number & ") " & Err.Description
                WScript.Echo ""
                WScript.Quit Err.Number
            End if

            '
            ' Initialize the farm object.
            '

            theFarm.Initialize(MetaFrameWinFarmObject)
            if Err.Number <> 0 Then
                WScript.Echo "Can't  Initialize MetaFrameFarm object"
                WScript.Echo "(" & Err.Number & ") " & Err.Description
                WScript.Echo ""
                WScript.Quit Err.Number
            End if
            
            '
            '
            '
            'Create icon folder for icon storage
            If not oFso.FolderExists(sScriptPath & "\icons") Then
            oFso.CreateFolder(sScriptPath & "\icons")
            End If
            'Create backup folder for files from last script run
            If not oFso.FolderExists(sScriptPath & "\backup") Then
            oFso.CreateFolder(sScriptPath & "\backup")
            End If
            'Create backup folder for icons, then copy last run's icons over
            If oFso.FolderExists(sScriptPath & "backup\icons") Then
            oFso.DeleteFile sScriptPath & "backup\icons\*.*"
            oFso.CopyFolder sScriptPath & "\icons", sScriptPath & 
"\backup\icons"
            Else
            oFso.CreateFolder(sScriptPath & "\backup\icons")
            oFso.CopyFolder sScriptPath & "\icons", sScriptPath & 
"\backup\icons"
            End If
            'Copy .inf file from last script run to backup folder, then clean 
up icon directory
            If oFso.FileExists(sScriptPath & "\" & theFarm.FarmName 
&"_Applications.inf") Then
            oFso.CopyFile sScriptPath & "\" & theFarm.FarmName 
&"_Applications.inf", sScriptPath & "\backup\"
            oFso.DeleteFile sScriptPath & "\icons\*.*"
            End If
            '
            '
            'Set output file
            Set output = oFso.OpenTextFile(sScriptPath & "\" & theFarm.FarmName 
&"_Applications.inf", 2, True)
            '            '
            ' Are you Citrix Administrator?
            '

            if theFarm.WinFarmObject.IsCitrixAdministrator = 0 then
                WScript.Echo "You must be a Citrix admin to run this script" 
                WScript.Echo ""
                WScript.Quit 0
            End If

            '
            ' Print out the farm name.
            '

            WScript.Echo "MetaFrame Farm Name: " & theFarm.FarmName
            WScript.Echo ""
            '
            '
            '
            'Loop through all applications in the farm 

            For Each anApp In theFarm.Applications
            Set aWinApp = anApp.WinAppObject

                if Err.Number <> 0 Then
                    WScript.Echo "Can't enumerate applications"
                    WScript.Echo "(" & Err.Number & ") " & Err.Description
                    WScript.Echo ""
                    WScript.Quit Err.Number
                End if
              output.writeline "[Application]"
              'if aWinApp.PNAttributes equals MFWinAppDesktop then it is a 
published desktop
              If aWinApp.PNAttributes AND MFWinAppDesktop Then
              WScript.Echo "Application Name: " & anApp.AppName
              output.writeline "AppName=" & anApp.AppName
              WScript.Echo "Description: " & anApp.Description
              output.writeline "Description=" & anApp.Description
              WScript.Echo "Distinguished Name: " & 
Replace(anApp.DistinguishedName,"/","\")
              output.writeline "DistinguishedName=" & 
Replace(anApp.DistinguishedName,"/","\")
              WScript.Echo "Command Line: " & "Published Desktop"
              output.writeline "DefaultInitProg=" & "PublishedDesktop"
              WScript.Echo "MetaFrame Attribute: " & aWinApp.MFAttributes
              output.writeline "MFAttributes=" & aWinApp.MFAttributes
              WScript.Echo "PN Attribute: " & aWinApp.PNAttributes
              output.writeline "PNAttributes=" & aWinApp.PNAttributes
                        If aWinApp.PNFolder <> "" Then
                        WScript.Echo "Program Neighborhood Folder: " & 
aWinApp.PNFolder
                        output.writeline "PNFolder=" & aWinApp.PNFolder
                        End If
              
              WScript.Echo "Encryption: " & aWinApp.DefaultEncryption
              output.writeline "DefaultEncryption=" & aWinApp.DefaultEncryption
              WScript.Echo "Sound Type: " & aWinApp.DefaultSoundType
              output.writeline "DefaultSoundType=" & aWinApp.DefaultSoundType
              WScript.Echo "Window Color: " & aWinApp.DefaultWindowColor
              output.writeline "DefaultWindowColor=" & 
aWinApp.DefaultWindowColor
              WScript.Echo "Window Size: " & aWinApp.DefaultWindowType
              output.writeline "DefaultWindowType=" & aWinApp.DefaultWindowType
              WScript.Echo "Parent Folder: " & aWinApp.ParentFolderDN
              output.writeline "ParentFolderDN=" & aWinApp.ParentFolderDN
              WScript.Echo "Desktop Integrate: " & aWinApp.DesktopIntegrate
              output.writeline "DesktopIntegrate=" & aWinApp.DesktopIntegrate
              WScript.Echo "Wait on Printer: " & aWinApp.WaitOnPrinterCreation
              output.writeline "WaitOnPrinterCreation=" & 
aWinApp.WaitOnPrinterCreation
              WScript.Echo "Multi Instance: " & 
aWinApp.AllowMultiInstancePerUser
              output.writeline "AllowMultiInstancePerUser=" & 
aWinApp.AllowMultiInstancePerUser
              WScript.Echo "Instance Limit: " & aWinApp.InstanceLimit
              output.writeline "InstanceLimit=" & aWinApp.InstanceLimit
              WScript.Echo "Add Shortcut: " & aWinApp.AddShortcutToClientDesktop
              output.writeline "AddShortcutToClientDesktop=" & 
aWinApp.AddShortcutToClientDesktop
              WScript.Echo "Add to Start Menu: " & aWinApp.AddToClientStartMenu
              output.writeline "AddToClientStartMenu=" & 
aWinApp.AddToClientStartMenu
              WScript.Echo "Default Sound Type: " & aWinApp.DefaultSoundType
              output.writeline "DefaultSoundType=" & aWinApp.DefaultSoundType
              WScript.Echo "Enable SSL: " & aWinApp.EnableSSLConnections
              output.writeline "EnableSSLConnections=" & 
aWinApp.EnableSSLConnections
                        If aWinApp.AddToClientStartMenu <> 0 Then
                        WScript.Echo "Place Under Programs: " & 
aWinApp.PlaceUnderProgramsFolder
                        output.writeline "PlaceUnderProgramsFolder=" & 
aWinApp.PlaceUnderProgramsFolder
                        WScript.Echo "Start Menu Folder: " & 
aWinApp.StartMenuFolder
                        output.writeline "StartMenuFolder=" & 
aWinApp.StartMenuFolder
                        End If
              WScript.Echo "Enable App: " & aWinApp.EnableApp
              output.writeline "EnableApp=" & aWinApp.EnableApp
              aWinApp.WriteIconToFile sScriptPath & "\icons\" & anApp.AppName & 
".ico"
              '
              Else
              '
              WScript.Echo "Application Name: " & anApp.AppName
              output.writeline "AppName=" & anApp.AppName
              WScript.Echo "Description: " & anApp.Description
              output.writeline "Description=" & anApp.Description
              WScript.Echo "Distinguished Name: " & 
Replace(anApp.DistinguishedName,"/","\")
              output.writeline "DistinguishedName=" & 
Replace(anApp.DistinguishedName,"/","\")
              WScript.Echo "Command Line: " & aWinApp.DefaultInitProg
              output.writeline "DefaultInitProg=" & aWinApp.DefaultInitProg
              WScript.Echo "Working Directory: " & aWinApp.DefaultWorkDir
              output.writeline "DefaultWorkDir=" & aWinApp.DefaultWorkDir
              WScript.Echo "MetaFrame Attribute: " & aWinApp.MFAttributes
              output.writeline "MFAttributes=" & aWinApp.MFAttributes
              WScript.Echo "PN Attribute: " & aWinApp.PNAttributes
              output.writeline "PNAttributes=" & aWinApp.PNAttributes
                        If aWinApp.PNFolder <> "" Then
                        WScript.Echo "Program Neighborhood Folder: " & 
aWinApp.PNFolder
                        output.writeline "PNFolder=" & aWinApp.PNFolder
                        End If
              WScript.Echo "Encryption: " & aWinApp.DefaultEncryption
              output.writeline "DefaultEncryption=" & aWinApp.DefaultEncryption
              WScript.Echo "Sound Type: " & aWinApp.DefaultSoundType
              output.writeline "DefaultSoundType=" & aWinApp.DefaultSoundType
              WScript.Echo "Window Color: " & aWinApp.DefaultWindowColor
              output.writeline "DefaultWindowColor=" & 
aWinApp.DefaultWindowColor
              WScript.Echo "Window Size: " & aWinApp.DefaultWindowType
              output.writeline "DefaultWindowType=" & aWinApp.DefaultWindowType
              WScript.Echo "Parent Folder: " & aWinApp.ParentFolderDN
              output.writeline "ParentFolderDN=" & aWinApp.ParentFolderDN
              WScript.Echo "Desktop Integrate: " & aWinApp.DesktopIntegrate
              output.writeline "DesktopIntegrate=" & aWinApp.DesktopIntegrate
              WScript.Echo "Wait on Printer: " & aWinApp.WaitOnPrinterCreation
              output.writeline "WaitOnPrinterCreation=" & 
aWinApp.WaitOnPrinterCreation
              WScript.Echo "Multi Instance: " & 
aWinApp.AllowMultiInstancePerUser
              output.writeline "AllowMultiInstancePerUser=" & 
aWinApp.AllowMultiInstancePerUser
              WScript.Echo "Instance Limit: " & aWinApp.InstanceLimit
              output.writeline "InstanceLimit=" & aWinApp.InstanceLimit
              WScript.Echo "Add Shortcut: " & aWinApp.AddShortcutToClientDesktop
              output.writeline "AddShortcutToClientDesktop=" & 
aWinApp.AddShortcutToClientDesktop
              WScript.Echo "Add to Start Menu: " & aWinApp.AddToClientStartMenu
              output.writeline "AddToClientStartMenu=" & 
aWinApp.AddToClientStartMenu
              WScript.Echo "Default Sound Type: " & aWinApp.DefaultSoundType
              output.writeline "DefaultSoundType=" & aWinApp.DefaultSoundType
              WScript.Echo "Enable SSL: " & aWinApp.EnableSSLConnections
              output.writeline "EnableSSLConnections=" & 
aWinApp.EnableSSLConnections
                        If aWinApp.AddToClientStartMenu <> 0 Then
                        WScript.Echo "Place Under Programs: " & 
aWinApp.PlaceUnderProgramsFolder
                        output.writeline "PlaceUnderProgramsFolder=" & 
aWinApp.PlaceUnderProgramsFolder
                        WScript.Echo "Start Menu Folder: " & 
aWinApp.StartMenuFolder
                        output.writeline "StartMenuFolder=" & 
aWinApp.StartMenuFolder
                        End If
              WScript.Echo "Enable App: " & aWinApp.EnableApp
              output.writeline "EnableApp=" & aWinApp.EnableApp
              aWinApp.WriteIconToFile sScriptPath & "\icons\" & anApp.AppName & 
".ico"
              End If
              output.writeline
              output.writeline "[Servers]"
                                 
               'Print ServerName for the app . 
                 For Each aServer In anApp.Servers
                 
                 WScript.Echo "Server Name: " & aServer.ServerName
                 output.writeline aServer.ServerName
                 Next
              WScript.Echo ""
              output.writeline
              output.writeline "[Users]"
            For Each anUser In anApp.Users
                                    
                                        '
                                        ' MetaFrameUser object.
                                        '
                                        
                                        If nUserCount = 0 then
                                            WScript.Echo "Users            : " 
& anUser.AAName & "\" & anUser.UserName
                                            output.writeline anUser.AAName & 
"\" & anUser.UserName & "\" & anUser.AccountType
                                        Else                        
                                            WScript.Echo "                   " 
& anUser.AAName & "\" & anUser.UserName
                                            output.writeline anUser.AAName & 
"\" & anUser.UserName & "\" & anUser.AccountType
                                        End if             
                                        
                                        
                                        
                                    Next    
                                    output.writeline
                                    output.writeline "[Groups]"
                                    
                                    For Each anGroup In anApp.Groups
                                    
                                        '
                                        ' MetaFrameGroup object.
                                        '
                    
                                        If nUserCount = 0 Then
                                            WScript.Echo "Users            : " 
& anGroup.AAName & "\" & anGroup.GroupName
                                            output.writeline anGroup.AAName & 
"\" & anGroup.GroupName & "\" & anGroup.AccountType
                                        Else
                                            WScript.Echo "                   " 
& anGroup.AAName & "\" & anGroup.GroupName
                                            output.writeline anGroup.AAName & 
"\" & anGroup.GroupName & "\" & anGroup.AccountType
                                        End If    
                                        
                                        
                                        
                                    Next
                                    WScript.Echo
                                    WScript.Echo
                                    output.writeline "[End Application]"
                                    output.writeline
                                    
            
            Next
            
            
           
            
            
        </script>
    </job>
</package>

Other related posts: