Smart questions
Smart answers
Smart people
Join Tek-Tips Forums
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

ToaDz (IS/IT--Management) (OP)
13 Apr 08 20:43
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! :)
theravager (TechnicalUser)
13 Apr 08 21:39
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

 
ToaDz (IS/IT--Management) (OP)
13 Apr 08 23:29
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?
theravager (TechnicalUser)
14 Apr 08 3:04
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.

http://www.dostips.com/DtTipsStringManipulation.php


 
ToaDz (IS/IT--Management) (OP)
14 Apr 08 20:00
Thanks again.  Since I'm a newbie to scripting, would you be able to give me an example?  

Really appreciate your help!
schtek (IS/IT--Management)
15 Apr 08 2:39
here is a start that is Very helpfull from Markdmac

FAQ329-5798: Implementing powerful and flexible login scripts!

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

 

GrimR (IS/IT--Management)
15 Apr 08 6:54
and here's a one based on Mark's, I posted that I use on my network
http://www.tek-tips.com/viewthread.cfm?qid=1419083
schtek (IS/IT--Management)
15 Apr 08 7:11
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

 

ToaDz (IS/IT--Management) (OP)
15 Apr 08 7:41
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
GrimR (IS/IT--Management)
15 Apr 08 9:14
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
GrimR (IS/IT--Management)
15 Apr 08 9:21
and BTW I just read why you doing this, but if you look at the script I created http://www.tek-tips.com/viewthread.cfm?qid=1419083  , 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.
ToaDz (IS/IT--Management) (OP)
16 Apr 08 1:27
If I added "IF %SESSIONNAME%==ICA* GOTO END" would that work?

Please help anyone :)
eraH (MIS)
17 Apr 08 23:29

CODE

if /I "%computername%" == "SV-SRV1 " goto END
ToaDz (IS/IT--Management) (OP)
18 Apr 08 1:09
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.
GrimR (IS/IT--Management)
18 Apr 08 10:36
ToaDz (IS/IT--Management) (OP)
18 Apr 08 20:17
Does anyone know how to do this via BATCH FILE script??  NOT VBS.  Thanks
ToaDz (IS/IT--Management) (OP)
20 Apr 08 1:30
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!

:)
ToaDz (IS/IT--Management) (OP)
21 Apr 08 22:56
Can anyone help out there?
eraH (MIS)
22 Apr 08 20:23
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
eraH (MIS)
22 Apr 08 21:14
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
ToaDz (IS/IT--Management) (OP)
22 Apr 08 23:29
Thanks again Poekies.  I will give these a go and report back on the outcome.

Appreciate your input and assistance!

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close