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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch File Login Script Help - IF COMPUTERNAME

Status
Not open for further replies.

ToaDz

IS-IT--Management
Oct 19, 2003
26
AU
Hi Guys,

We have a Batch File login script, which maps users network drives as well as points to other VBS scripts, which execute other functions.

Each user logs in with their Windows username (Ie. Username1) and the Batch File automatically runs at login.

Here is a brief extract from our Batch File login script:

@ECHO OFF

NET TIME \\SERVER1 /SET /YES

NET USE G: \\SERVER1\Share1$
NET USE K: \\SERVER1\Share2$
NET USE S: \\SERVER2\Share3$
NET USE U: /home

REM Create a folder called "Admin" in Temp dir
CSCRIPT /T:20 \\SERVER1\NETLOGON\CreateAdminFolder.vbs

:END

Here is where I need help with...

We have several Terminal Services and Citrix Servers located in remote geographical locations. Users login to these servers to access applications using

their Windows username (Ie. Username1). These Terminal Services and Citrix Servers have server names of:

SV-SRV1
SV-SRV2
SV-SRV3
SV-SRV4
SV-SRV5

Each time a user logs in to one of these servers, the Batch File login script is run. The user does not need their drives mapped or any other functions to

be executed in order to access these applications. As you can imagine, each time a user logs in to one of these servers, its take quite a long time for them to login, as their drives are being mapped and so forth.

I understand that there is a batch file command called "IF %COMPUTERNAME%==".

Basically, I want the login script to be able to detect if a user is connecting to one of these Terminal Services and Citrix Servers, and if so, bypass the

drive mappings and other functions in the login script and go straight to ":END".

Would this work?

@ECHO OFF

IF %COMPUTERNAME%==SV-SRV1 GOTO END
IF %COMPUTERNAME%==SV-SRV2 GOTO END
IF %COMPUTERNAME%==SV-SRV3 GOTO END
IF %COMPUTERNAME%==SV-SRV4 GOTO END
IF %COMPUTERNAME%==SV-SRV5 GOTO END

NET TIME \\SERVER1 /SET /YES

NET USE G: \\SERVER1\Share1$
NET USE K: \\SERVER1\Share2$
NET USE S: \\SERVER2\Share3$
NET USE U: /home

REM Create a folder called "Admin" in Temp dir
CSCRIPT /T:20 \\SERVER1\NETLOGON\CreateAdminFolder.vbs

:END

What do you guys think? Have I got the right idea here and have I placed the "IF" statements in the correct area of the Batch File?

Your comments, suggestions and advise would be greatly appreciated.

Thanks to all! :)
 
I'd consider changing your script to vbs but to answer your question the environment object sessionname will start with rdp or ica if its a citrix session

 
Thanks for your response.

Yes, eventually, we'll be looking at creating a VBS Login script. But for now, the Batch File will remain.

So is there a way to accomplish what I want via a Batch File?

For instance, is there a way to determine if the user connects to a TS or Citrix server, regardless of what computer they use, to bypass all lines in the script and go straight to the end?
 
sessionname variable will start with rdp or ica if you have a citrix session. You can view these from dos by just typing set.

You can work with strings using the set command there is examples of these below, just assign the leftmost 3 character to a variable and compare it to ica or rdp with a if command and you are good to go.

 
Thanks again. Since I'm a newbie to scripting, would you be able to give me an example?

Really appreciate your help!
 
here is a start that is Very helpfull from Markdmac

faq329-5798

[cannon] [worm]
"Practice makes Perfect"
("la pratique rend parfait")
CPO rt'd RN

 
I missed that one 'GrimR' nice :) Time to update a few things 4 me :p

[cannon] [worm]
"Practice makes Perfect"
("la pratique rend parfait")
CPO rt'd RN

 
Hey Guys,

Thanks for all the responses and links to other VBS scripts. Can anyone help me with my specific problem (First Thread)?

Basically, I want the login script, which I already have, to be able to detect if a user is connecting to one of these Terminal Services and Citrix Servers, and if so, bypass the drive mappings and other functions in the login script and go straight to ":END".

"theravager" pointed me in the right direction, but need a little help from more experience batch scripting wiz's out there :)

Thanks again
 
In vbscript it would look something like this.
You may want to ask the gurus in the vbscript forum for some help here.

Code:
Dim WshNetwork:Set WshNetwork = CreateObject("WScript.Network")
Dim WshShell:Set WshShell = WScript.CreateObject("WScript.Shell")
Dim WshSysEnv:Set WshSysEnv = WshShell.Environment("Process")
Dim objFSO:Set objFSO = CreateObject("Scripting.FileSystemObject")

SysDrive = WshShell.ExpandEnvironmentStrings("%SYSTEMDRIVE%")
SysRoot = WshShell.ExpandEnvironmentStrings ("%SystemRoot%")
UserProfile = WshShell.ExpandEnvironmentStrings ("%UserProfile%")

DomainLogonServer = WshSysEnv("LogonServer")

Select Case DomainLogonServer
    Case "\\Citric Server Name"
        wscript.quit
    Case "\\Terminal Services Server Name"
        wscript.quit
    Case "\\Good server"
	
	
	'Create the folder
		strFolderName = sysdrive & "\temp\Admin"
		' Check that the strDirectory folder exists
			If objFSO.FolderExists(strFolderName) Then
			  Set objFolder = objFSO.GetFolder(strFolderName)
			Else
			  Set objFolder = objFSO.CreateFolder(strFolderName)
			  'WScript.Echo "Just created " & strDirectory
			End If
       
		'Map Network Drives
			WshNetwork.MapNetworkDrive "G:", "\\server\share$",True
			WshNetwork.MapNetworkDrive "K:", "\\server\share$",True
			WshNetwork.MapNetworkDrive "U:", "\\server\share$",True
			WshNetwork.MapNetworkDrive "s:", "\\server\share$",True
			WshNetwork.RemoveNetworkDrive "R:", True, True
End Select
 
and BTW I just read why you doing this, but if you look at the script I created , it sets a registry value so the script will only run one a day, that way they can logon as many times as they like the script will only run once at first logon.
The second one was a 5 min job, and untested.
 
If I added "IF %SESSIONNAME%==ICA* GOTO END" would that work?

Please help anyone :)
 
Hi Poekies,

As detailed throughout this entire thread, the line you have given me above will NOT work, as the user is not physically connecting FROM that Server name. Ie. COMPUTERNAME variable.

theravager has pointed out that ICA and RDP connections are based on SESSIONS, therefore the SESSIONNAME variable must be used.

I am really rusty on my batch file scripting so need assistance with using the "IF %SESSIONNAME% ==" command and whether or not this will work.

Thanks anyway.
 
Does anyone know how to do this via BATCH FILE script?? NOT VBS. Thanks
 
I'm after the wildcard string / command.

For example,

"IF %SESSIONNAME%==ICA* GOTO END"
"IF %SESSIONNAME%==ICA*.* GOTO END"

Will these work or do I need to do something different?

Please help, ANYONE!

:)
 
You sure about that?

My understanding of the %computername% variable was that it showed you the name of the server that you run the command on.

Easy way to test this.
Logon to a pc and run
Code:
echo %computername%
Logon to the terminal server and run the command again.

Change your current logon script to do something like opening notepad if on the terminal server for testing purposes.
Code:
@ECHO OFF

NET TIME \\SERVER1 /SET /YES

NET USE G: \\SERVER1\Share1$
NET USE K: \\SERVER1\Share2$
NET USE S: \\SERVER2\Share3$
NET USE U: /home

REM Create a folder called "Admin" in Temp dir
CSCRIPT /T:20 \\SERVER1\NETLOGON\CreateAdminFolder.vbs
      
IF /I "%computername%" == "SV-SRV1 " goto TS
    
:TS
start notepad

:END
 
Fixed logic.
Code:
@ECHO OFF

NET TIME \\SERVER1 /SET /YES

NET USE G: \\SERVER1\Share1$
NET USE K: \\SERVER1\Share2$
NET USE S: \\SERVER2\Share3$
NET USE U: /home

REM Create a folder called "Admin" in Temp dir
CSCRIPT /T:20 \\SERVER1\NETLOGON\CreateAdminFolder.vbs
      
IF /I "%computername%" == "SV-SRV1 " goto TS
GOTO END
    
:TS
start notepad

:END
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top