ThinWorld Citrix Knowledgebase

Thursday, 11 March 2010

VBS Ping check script

This simple VBS allow you to check a device is up and running (with a ping check) before it runs code against the device.

This method means your script will not hang running against machines that are powered off.

PINGFlag = Not CBool(ObjShell.run("ping -n 1 " & StrUserID(1),0,True))
If PINGFlag = True Then
' Machine is up and running
Else
' Machine has not responded
End If

Labels:

Tuesday, 2 March 2010

Registry .REG backup Script

This Script reads in a .REG file and makes a backup of the registry area that the .REG will change when imported.

This is handy when you are given a .REG file and told to import it. The script will create backup .REG files for you to restore the machine to original values should the import cause issues.

Its not the prettiest of things and will create multiple backup REG files if there are multiple key paths. But you can highlight all the backup reg keys and import in the event of a restore.

'
' Backup Registry before importing a REG file
'
' This script is designed to be run before importing a .REG file
' It will export the current registry key values into a .REG file
' in order to make a restore to the original keys quick and simple.
'
' Input it a .REG file
' It will output to a folder of the same name a .REG file for each required Key
'

On error resume next

Set objFSO = CreateObject("Scripting.fileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
Set objInputFile = objFSO.OpenTextFile(StrScript,1,False,0)

StrFolder = Wshshell.CurrentDirectory
StrScript = "tweak-bundle1.reg"
dim StrKey(1000)

StrPath = StrFolder & "\" & Left(StrScript,Len(StrScript)-4)

objFSO.CreateFolder (StrPath)

i=0
Do Until objInputFile.AtEndOfStream
i = i+1
strData = objInputFile.ReadLine
If Instr(Strdata,"[") > 0 Then
StrData = Left(StrData,Len(Strdata)-1)
StrData = Right(Strdata,Len(Strdata)-1)
StrKey(i) = Strdata
StrCommand = "REGEDIT /E " & CHR(34) & StrPath & "\" & i & ".reg" & CHR(34) & " " & CHR(34) & Strkey(i) & CHR(34)
Wshshell.Run Strcommand
End If
Loop

Labels:

Tuesday, 26 January 2010

Support GUI HTA

I wrote this support GUI for my employer. It allows 1st line support to perform a number of quick support actions from a simple GUI Interface. The code is HTA so HTML and VB Script together.

We use a hybrid profile system so the GUI allows the deletion of portions of the profile at the click of a button. (Eg. Delete Printer settings, Delete IE settings)

The program also records it own useage so that trends spotting can be performed.

The code is fairly specific to my current environment so will be of limited use to others , however some of the code may be handy so im posting the whole thing.


Screenshot


SupportGUI2.hta

Labels:

Thursday, 27 August 2009

Font Size change Script XenApp

This is a basic script to give users a GUI to change the Font Size without the need to drill through the control panel and the display settings.

Its a HTA file so is part VBS and part HTML which gives the GUI and nice simple look and feel.

The script imports a reg file based on the users selection of
Normal
Large
Extra Large

The Reg files set HKCU values for the user.
The user then needs to logoff and back on for the settings to take effect.
In a normal roaming profile environment this work as expected.
With Appsense Hybrid profiles the registry keys get imported to late to be in effect.
To resolve this Appsense have a screen refresh tool that can be run, this rather like hitting APPLY when changing in the GUI sets the font size immediately.

There are 4 files required

Font_size.hta
normal.reg
Large.reg
extraLarge.reg

to update the screen run this tool
RefreshTool2008.exe

Labels:

Thursday, 13 August 2009

HTA Map Network Printer

I wrote this HTA to aid users in mapping printers. Its a simple HTA that prompts the user for the name of the printer they want to add, and also allows them to set it as default.
The benefit of this method is its alot simpler than the ADD Printer wizard and also users dont have to worry about knowing what printer server the printer is on.

The script currently will only add the printer from 1 hard coded printer server, but i will be updating it to search for the printer across a pool of printer servers in a update im writing. This will also then be able to validate the printer the user enters to ensure it is valid.

I also added a Remember this printer button. The code does not make use of this as yet. This is again for a later release. I was intending to write out the users personal added printers to %homedrive%\printers.txt I was thinking of getting the logon script to map any printers found in this file. This would mean users get to keep their printers in the event of profile delete and we could also manage these user files in the event of the printer server changing or the queue being removed. This is a better solution than the current situation of users mapping printers inside their profiles which can be easily deleted and is not easily centrally managed.

Labels:

Wednesday, 12 August 2009

Assign Load Evaluator via Script

The following script uses MFCOM to assign a load evaluator to a XenApp server(s) This can be handy as part of a biuld script to ensure the correct load evaluator is assiged to a XenApp server

Dim ServerLE
const MetaFrameWinSrvObject = 6
Const ForRead = 1
Const ForWrite= 2

on error resume next

Set FSO = CreateObject("scripting.FileSystemObject")
set SaveLE = FSO.OpenTextFile("H:\Scripts\Files\LoadEval.txt",ForWrite,True)

Set WshShell = WScript.CreateObject("WScript.Shell")
set rc = WshShell.Exec("MFREG.exe HAVWCP01")

Set farm=CreateObject("MetaframeCOM.MetaframeFarm")
farm.initialize 1

SvrName = "xxxx"

Set ServerLE = CreateObject("MetaframeCom.MetaFrameServer")
ServerLE.Initialize MetaFrameWinSrvObject, SvrName

Set LE = ServerLE.AttachedLE
LE.Loaddata(True)

ServerLE.AttachLEByName "Load to Max"

LE.SaveData(True)

SaveLE.Close

Labels:

Move Server OU with a VB Script

This script can be handy if you build your servers into a BUILD OU and then need to automate moving the server to the correct OU later in the build process.

' Move Computer to Prod Citrix OU

Set WshNetwork = WScript.CreateObject("WScript.Network")
StrComputername= "CN=" & WshNetwork.ComputerName

Set objNewOU = GetObject("LDAP://OU=Live PS45,OU=Citrix W2K3,OU=Servers,DC=thinworld,DC=net")

StrOldOU= "LDAP://" & StrComputername & ",CN=Build ,CN=Servers,DC=thinworld,DC=net"

Set objMoveComputer = objNewOU.MoveHere _
(StroldOU, StrComputerName)

Labels:

Tuesday, 21 July 2009

Script to remove users from AD group

This is a script to remove users listed in a file users.txt from an AD group membership.
I really cant remember why its so damn long and complex but it works and thats all i need to know. The script can also be used to Add rather than remove people from a group by changing the ObjGroup.PutEx value to _APPEND as opposed to _DELETE


' Script to remove users from AD group membership

Dim objConnection, objCommand, objRootDSE, strDNSDomain
Dim strFilter, strQuery, objRecordSet, objArgs, usr
const ADS_PROPERTY_DELETE = 4
Const ADS_PROPERTY_APPEND = 3


Set WshShell = WScript.CreateObject("WScript.Shell")
Set objFileSystem = CreateObject("Scripting.fileSystemObject")


Set objInputFile = objFileSystem.OpenTextFile("users.txt",1)

inputData = Split(objInputFile.ReadAll, vbNewline)
For Each StrData in inputdata
Sam = StrData
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOOBject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
Set objRootDSE = GetObject("LDAP://RootDSE")

strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = ""
strFilter = "(&(objectCategory=person)(objectClass=user)(sAMAccountName=" & sam & "))"
strAttributes = "distinguishedName,sAMAccountName"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 99999
objCommand.Properties("Timeout") = 300
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strDN = objRecordSet.Fields("distinguishedName")
objRecordSet.MoveNext
Loop

objConnection.Close
Set objConnection = Nothing
Set objCommand = Nothing
Set objRootDSE = Nothing
Set objRecordSet = Nothing
Set Objuser = Getobject ("LDAP://" & strDN & "")
StrPath = objUser.TerminalServicesProfilePath
objUser.TerminalServicesProfilePath = StrTSProfile
Set Objgroup = Getobject ("LDAP://CN=CTX-Hybrid-Profile-Migration-Group,OU=Applications,OU=Groups,OU=BusinessOU,DC=THINWORLD,DC=NET")
objGroup.PutEx ADS_PROPERTY_DELETE, "member",Array(strDN)

objuser.setinfo
objgroup.setinfo

Next

objInputFile.Close

WScript.Echo "Completed"
wscript.quit

Labels:

Script to Set Users TSprofile path location in AD

This VB Script will set the TSprofile path to C:\Mandatory_Profile for users whos ID is listed in the text file users.txt.

User names should be seperated by a carriage return inside users.txt

I used this script during a migration of users to a hybrid profile solution. I did not want to set the path with GPO as i wanted a controlled migration over a period of time. Once the migration was completed the path was however controlled via GPO.



' Set User TSProfile path.vbs
'
' Sets users in users.txt to TS profile path C:\Mandatory_Profile
'
'
'


Dim objConnection, objCommand, objRootDSE, strDNSDomain
Dim strFilter, strQuery, objRecordSet, objArgs, usr
StrTSProfile = "c:\Mandatory_Profile"

Set WshShell = WScript.CreateObject("WScript.Shell")
Set objFileSystem = CreateObject("Scripting.fileSystemObject")


Set objInputFile = objFileSystem.OpenTextFile("users.txt",1)

inputData = Split(objInputFile.ReadAll, vbNewline)

For Each StrData in inputdata

Sam = StrData

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")

objConnection.Provider = "ADsDSOOBject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
Set objRootDSE = GetObject("LDAP://RootDSE")

strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = ""
strFilter = "(&(objectCategory=person)(objectClass=user)(sAMAccountName=" & sam & "))"
strAttributes = "distinguishedName,sAMAccountName"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 99999
objCommand.Properties("Timeout") = 300
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strDN = objRecordSet.Fields("distinguishedName")
objRecordSet.MoveNext
Loop

objConnection.Close
Set objConnection = Nothing
Set objCommand = Nothing
Set objRootDSE = Nothing
Set objRecordSet = Nothing
Set Objuser = Getobject ("LDAP://" & strDN & "")
StrPath = objUser.TerminalServicesProfilePath

objUser.TerminalServicesProfilePath = StrTSProfile
objuser.setinfo

Next

objInputFile.Close

WScript.Echo "Completed"
wscript.quit

Labels:

Monday, 8 June 2009

Setting the Default Script Host

To change the default scipt host engine in the event that some software changed it from the default the following command is all you should need.

wscript //h:cscript //s - to set CScript as Default
wscript //h:wscript //s - To set WScript as Default





Labels: