%LOGONSERVER% & .bat if then else

Discussion in 'Windows Server' started by David Lewis, Mar 23, 2005.

  1. David Lewis

    David Lewis Guest

    I got 3 offices with their own local DC and local file server
    One domain
    I wanted to create one login script for the entire company to map
    network drives to their local file servers.
    I know there is a variable %LOGONSERVER%
    So I am thinking that I need to write an if then else where
    if the %LOGONSERVER% = corporate then set FILESERVER=Server1

    Then my drive mapping would be
    net use N: \\%FILESERVER%\share

    Is there any problem in my logic?
    I don't know how to write the if then else statement.
     
    David Lewis, Mar 23, 2005
    #1
    1. Advertisements

  2. I don't know if your logic would work - try it out and
    see what happens! Here is the syntax:

    @echo off
    if /i "%LogonServer"%=="Corporate" (set FileServer=Server1) else (set
    FileServer=Server2)
    net use . . .
     
    Pegasus \(MVP\), Mar 23, 2005
    #2
    1. Advertisements

  3. "%LogonServer%" :)
     
    George Woodbine, Mar 23, 2005
    #3
  4. Oops . . . thanks for pointing out this silly error!
     
    Pegasus \(MVP\), Mar 24, 2005
    #4
  5. David Lewis

    David Lewis Guest

    thankx, that did the trick
    I just had to tweak your code a little
    This way I was able to instead of having 4 login scripts, now I have one

    if /i "%LOGONSERVER%"=="\\Corp" (set FileServer=\\Corp-Files)
    if /i "%LOGONSERVER%"=="\\Remote" (set FileServer=\\Remote)

    net use e: /delete
    net use e: %FileServer%\CAD /PERSISTENT:YES
    net use f: /delete
    net use f: %FileServer%\Docs /PERSISTENT:YES
    net use u: /delete
    net use u: %FileServer%\Users\%USERNAME% /PERSISTENT:YES

    My situation is that in my corporate office, there is a separate DC and file server
    but my remote offices have one server for both DC and files

    Now I just need to figure out how to add mapped drives bassed on security groups.
    How can I do that?

    "Pegasus \(MVP\)" <>
    |>
    |>|>> I got 3 offices with their own local DC and local file server
    |>> One domain
    |>> I wanted to create one login script for the entire company to map
    |>> network drives to their local file servers.
    |>> I know there is a variable %LOGONSERVER%
    |>> So I am thinking that I need to write an if then else where
    |>> if the %LOGONSERVER% = corporate then set FILESERVER=Server1
    |>>
    |>> Then my drive mapping would be
    |>> net use N: \\%FILESERVER%\share
    |>>
    |>> Is there any problem in my logic?
    |>> I don't know how to write the if then else statement.
    |>
    |>I don't know if your logic would work - try it out and
    |>see what happens! Here is the syntax:
    |>
    |>@echo off
    |>if /i "%LogonServer"%=="Corporate" (set FileServer=Server1) else (set
    |>FileServer=Server2)
    |>net use . . .
    |>
     
    David Lewis, Mar 24, 2005
    #5
  6. David Lewis

    David Lewis Guest

    ya I couldn't figure out why the code was not working :)

    George Woodbine <>
    |>Pegasus (MVP) wrote:
    |>>
    |>> @echo off
    |>> if /i "%LogonServer"%=="Corporate" (set FileServer=Server1) else (set
    |>
    |>"%LogonServer%" :)
     
    David Lewis, Mar 24, 2005
    #6
  7. David Lewis

    Todd J Heron Guest

    Look into ifmember.exe
     
    Todd J Heron, Mar 24, 2005
    #7
  8. David Lewis

    David Lewis Guest

    thankx so how would I write a batch to
    ifmember "Domain Admins" then net use .......

    "Todd J Heron" <>
    |>ifmember.exe
     
    David Lewis, Mar 24, 2005
    #8
  9. David Lewis

    Todd J Heron Guest

    Below adds the user's group membership needed for selective processing to a
    small text file in the user's profile folder, then the second command parses
    the text file (named Info.txt) for specific group name (a global group) and
    maps a drive letter h: to the network share. Error checking in line 3 dumps
    out the loginscript if the groupname you are looking for doesn't match and
    line 4 simply deletes any existing maps to h: in case the network share has
    changed locations etc...

    ifmember /v /l >> "%USERPROFILE%\Info.txt"
    type "%USERPROFILE%\Info.txt" |find "<domainname>\<groupname>" /i
    if errorlevel 1 goto :END
    if exist h:\ net use h: /d /y
    net use h: \\<UNCpathtoShareName>

    :END
     
    Todd J Heron, Mar 24, 2005
    #9
  10. You could also do it like this:

    ifmember "Group 1" || net use \\YourServer\Share1
    ifmember "Group 2" || net use \\YourServer\Share2

    Type ifmember /? at the Command Prompt to see what switches
    you should use.
     
    Pegasus \(MVP\), Mar 24, 2005
    #10
  11. David Lewis

    David Lewis Guest

    works, thankx

    "Pegasus \(MVP\)" <>
    |>
    |>|>> |>> >thankx so how would I write a batch to ifmember "Domain Admins" then net
    |>> >use .......
    |>>
    |>> Below adds the user's group membership needed for selective processing to
    |>a
    |>> small text file in the user's profile folder, then the second command
    |>parses
    |>> the text file (named Info.txt) for specific group name (a global group)
    |>and
    |>> maps a drive letter h: to the network share. Error checking in line 3
    |>dumps
    |>> out the loginscript if the groupname you are looking for doesn't match and
    |>> line 4 simply deletes any existing maps to h: in case the network share
    |>has
    |>> changed locations etc...
    |>>
    |>> ifmember /v /l >> "%USERPROFILE%\Info.txt"
    |>> type "%USERPROFILE%\Info.txt" |find "<domainname>\<groupname>" /i
    |>> if errorlevel 1 goto :END
    |>> if exist h:\ net use h: /d /y
    |>> net use h: \\<UNCpathtoShareName>
    |>>
    |>> :END
    |>>
    |>> --
    |>> Todd J Heron, MCSE
    |>> Windows Server 2003/2000/NT; CCA
    |>> --------------------------------------------------------------------------
     
    David Lewis, Mar 24, 2005
    #11
  12. remember..
    %logonserver% is only valid on 2000 and XP, 9x clients don't respect it..

    Diane
     
    Diane McCorkle, Mar 25, 2005
    #12
  13. David Lewis

    David Lewis Guest

    thankx. We don't support 9x :) thank god


    "Diane McCorkle" <diane.mccorkle at atcassociates.com>
    |>remember..
    |>%logonserver% is only valid on 2000 and XP, 9x clients don't respect it..
    |>
    |>Diane
    |>
    |>
    |>|>> works, thankx
    |>>
    |>> "Pegasus \(MVP\)" <>
    |>> |>
    |>> |>|>> |>> |>> |>> >thankx so how would I write a batch to ifmember "Domain Admins" then
    |>> net
    |>> |>> >use .......
    |>> |>>
    |>> |>> Below adds the user's group membership needed for selective processing
    |>> to
    |>> |>a
    |>> |>> small text file in the user's profile folder, then the second command
    |>> |>parses
    |>> |>> the text file (named Info.txt) for specific group name (a global
    |>> group)
    |>> |>and
    |>> |>> maps a drive letter h: to the network share. Error checking in line 3
    |>> |>dumps
    |>> |>> out the loginscript if the groupname you are looking for doesn't match
    |>> and
    |>> |>> line 4 simply deletes any existing maps to h: in case the network
    |>> share
    |>> |>has
    |>> |>> changed locations etc...
    |>> |>>
    |>> |>> ifmember /v /l >> "%USERPROFILE%\Info.txt"
    |>> |>> type "%USERPROFILE%\Info.txt" |find "<domainname>\<groupname>" /i
    |>> |>> if errorlevel 1 goto :END
    |>> |>> if exist h:\ net use h: /d /y
    |>> |>> net use h: \\<UNCpathtoShareName>
    |>> |>>
    |>> |>> :END
    |>> |>>
    |>> |>> --
    |>> |>> Todd J Heron, MCSE
    |>> |>> Windows Server 2003/2000/NT; CCA
    |>> |>> --------------------------------------------------------------------------
    |>>
    |>
     
    David Lewis, Mar 30, 2005
    #13
  14. David Lewis

    Herb Martin Guest

    Re: Better ways:

    How about a Site linked GPO to make the correct settings?
    The GPO linked to a site is cleaner since no need to maintain Group
    memberships BUT it might fail to give the desirves results if Fred-Miami
    still needs to use the Miami file server even when he is IN Boston.

    But the original, was based on the LogonServer which would vary
    when users traveled (or even by accident when DCs are down) so
    using a Site linked GPO would give the proposed results AND be
    reliable (as long as correct server were up.)
     
    Herb Martin, Feb 1, 2007
    #14
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.