Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exit Script Based on PC/Server Name

Status
Not open for further replies.

fasterthanyours

IS-IT--Management
Apr 13, 2010
3
US
The Environment is multiple XP/W7 machines running RemoteApp (RDP on steriods) to a 3 server TS cluster.

One of the issues with RemoteApp that I have found is that the login script, which I need to run, will sometimes call installation apps in the back ground and it will lock up the TS/RDP session and the users freak out.

Currently I built a script to install he Office 2007 Compatibility Pack on all of my XP Machines on the network. It works well, but I think I'd be better off if the script checks the local machine name and then exited if it was 1 of the TS Servers or the Data Server.

Basically as long as the local machine name isn't USGFDCDCDATA01, USGFDCDCTS01, USGFDCDCTS02, or USGFDCDCTS03 I want the script to run.

The global log in script runs this:
Code:
'------------------------------------------------------------------------------------
'Install MS Compatibility Pack for Office 2007
'------------------------------------------------------------------------------------
Set objShell = Wscript.CreateObject("WScript.Shell")
objShell.Run "\\cdc-dc1\NETLOGON\ExcelUpdate.vbs"
Set objShell = Nothing

Which calls this file:


Code:
'==========================================================================
'
' NAME: global.vbs
'
' AUTHOR:  Mike Infinger
' UPDATED: 04/01/2010
'
' COMMENT: Enumerates current users' group memberships in given domain.
'          Maps and disconnects drives.
'
'==========================================================================


ON ERROR RESUME NEXT

'Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj, Path, HourNow, Greeting, GreetName, oVo, oRootDSE, oConnection, oCommand, oRecordSet, MyObj,

Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")

'------------------------------------------------------------------------------------
'Automatically grab the user's domain name
'------------------------------------------------------------------------------------
DomainString = Wshnetwork.UserDomain

'------------------------------------------------------------------------------------
'Find the Windows Directory
'------------------------------------------------------------------------------------
WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")

'------------------------------------------------------------------------------------
'Grab the user name
'------------------------------------------------------------------------------------
UserString = WSHNetwork.UserName

'------------------------------------------------------------------------------------
'Bind to the user object to get user name and check for group memberships later
'------------------------------------------------------------------------------------
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)

'------------------------------------------------------------------------------------
'Grab the computer name for use in add-on code later
'------------------------------------------------------------------------------------
strComputer = WSHNetwork.ComputerName


'------------------------------------------------------------------------------------
'Disconnect any drive mappings as needed.
' - In this script, Disconnects are perform based on Group Memberships.
' - This is only and example
'------------------------------------------------------------------------------------
'Example
'WSHNetwork.RemoveNetworkDrive "E:", True, True

'------------------------------------------------------------------------------------
'
'                         ******   WARNING    ******
'
'  *** DO NOT RUN THIS IN THE SCRIPT AS IT WILL DISCONNECT ALL MAPPINGS!!!  ***
'
'Disconnect ALL mapped drives
'Set clDrives = WshNetwork.EnumNetworkDrives
'For i = 0 to clDrives.Count -1 Step 2
'    WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True
'Next
'------------------------------------------------------------------------------------

'------------------------------------------------------------------------------------
'Give the PC time to do the disconnect, wait 2000 milliseconds
'------------------------------------------------------------------------------------
'WScript.sleep 200


'=====================================
'Add On Code goes above this line

'------------------------------------------------------------------------------------
'Installing Excel File Converter Program.
'Installs with only a progress bar.
'------------------------------------------------------------------------------------
	Const HKEY_LOCAL_MACHINE = &H80000002
	
	strComputer = "."
	Set objRegistry = GetObject("winmgmts:\\" & _ 
	    strComputer & "\root\default:StdRegProv")
	 
	strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{90120000-0020-0409-0000-0000000FF1CE}"
	strValueName = "DisplayName"
	objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
	
	If IsNull(strValue) Then
	    MsgBox "                  Please be patient while we install a few updates.", "0", "** IMPORTANT MESSAGE FROM THE IT DEPARTMENT **"
	    Set MyObj=CreateObject("WScript.Shell")
	    'FileConverter Install
	    MsgBox "                  PLEASE CLICK RUN TO THE NEXT WINDOW.", "0", "** IMPORTANT MESSAGE FROM THE IT DEPARTMENT **"
	    MyObj.Run "\\rdu.carolinadoor.com\DFS_Data\Updates\FileFormatConverters.exe /quiet /passive"
	Else
	    'Wscript.Echo "The registry key exists."
	    'MsgBox "Already Installed", "0", "               ** IMPORTANT MESSAGE FROM THE IT DEPARTMENT **"
	End If
	    
'------------------------------------------------------------------------------------
'Complete
'------------------------------------------------------------------------------------
 
how about a Select Case on WshShell.ExpandEnvironmentStrings("%computername%") from the calling script?
 
Sounds like a plan.

I'm thinking I should put that in the main global login script. I'm kind of new the the whole VB thing, so I'm not positive how to implement that.

Could someone build the syntax for me? That would help me completely understand it.
 
yes put it in the script which calls the little thing which you dont want to happen on your TS boxes.
Infact, i am sure there is a TS specific environment variable? go onto one of you TS boxes and run SET from a command prompt, i think there might be an indicator there, rather then you maintaining a list of machine names.

Dim blnTSBox, strComputerName
blnTSBox = False
strComputerName = WshShell.ExpandEnvironmentStrings("%computername%")
Select Case LCase(strComputerName)
Case "USGFDCDCDATA01", "USGFDCDCTS01", "USGFDCDCTS02", "USGFDCDCTS03
blnTSBox = True
End Select
'
If blnTSBox = False Then
'
End If
 
I'd replace this:
Select Case LCase(strComputerName)
Case "USGFDCDCDATA01", "USGFDCDCTS01", "USGFDCDCTS02", "USGFDCDCTS03
with this:
Select Case [!]U[/!]Case(strComputerName)
Case "USGFDCDCDATA01", "USGFDCDCTS01", "USGFDCDCTS02", "USGFDCDCTS03[!]"[/!]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top