Home All Groups Group Topic Archive Search About

%LOGONSERVER% & .bat if then else

Author
23 Mar 2005 7:02 PM
David Lewis
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.

Author
23 Mar 2005 8:37 PM
Pegasus (MVP)
Show quote Hide quote
"David Lewis" <u***@microsoft.com> wrote in message
news:c1f341h9u64e7ocmk9m76ld2693o3d06i2@4ax.com...
> 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 . . .
Are all your drivers up to date? click for free checkup

Author
23 Mar 2005 11:22 PM
George Woodbine
Pegasus (MVP) wrote:
>
> @echo off
> if /i "%LogonServer"%=="Corporate" (set FileServer=Server1) else (set

"%LogonServer%" :)
Author
24 Mar 2005 12:10 AM
Pegasus (MVP)
"George Woodbine" <geo***@woodbine.com> wrote in message
news:4241fa01$0$2763$cc9e4d1f@news-text.dial.pipex.com...
> Pegasus (MVP) wrote:
> >
> > @echo off
> > if /i "%LogonServer"%=="Corporate" (set FileServer=Server1) else (set
>
> "%LogonServer%" :)

Oops . . . thanks for pointing out this silly error!
Author
24 Mar 2005 1:07 AM
David Lewis
ya I couldn't figure out why the code was not working :)

George Woodbine <geo***@woodbine.com>
Show quoteHide quote
|>Pegasus (MVP) wrote:
|>>
|>> @echo off
|>> if /i "%LogonServer"%=="Corporate" (set FileServer=Server1) else (set
|>
|>"%LogonServer%" :)
Author
24 Mar 2005 1:03 AM
David Lewis
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?

Show quoteHide quote
"Pegasus \(MVP\)" <I.***@fly.com>
|>
|>"David Lewis" <u***@microsoft.com> wrote in message
|>news:c1f341h9u64e7ocmk9m76ld2693o3d06i2@4ax.com...
|>> 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 . . .
|>
Author
24 Mar 2005 1:22 AM
Todd J Heron
"David Lewis" <u***@microsoft.com> wrote in message
news:6a4441pa98tbmb4472a9u49n8e6fkcmm6u@4ax.com...
<snipped>
>Now I just need to figure out how to add mapped drives based on security
>groups. How can I do that?

Look into ifmember.exe

--
Todd J Heron, MCSE
Windows Server 2003/2000/NT; CCA
----------------------------------------------------------------------------
This posting is provided "as is" with no warranties and confers no rights.
Author
24 Mar 2005 2:21 AM
David Lewis
thankx so how would I write a batch to
ifmember "Domain Admins" then net use .......

Show quoteHide quote
"Todd J Heron" <todd_heron_no_spam@hotmail.com>
|>ifmember.exe
Author
24 Mar 2005 3:09 AM
Todd J Heron
"David Lewis" <u***@microsoft.com> wrote in message
news:mv84411p14ideh3fjomiiuahm2ktv0kogv@4ax.com...
>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
----------------------------------------------------------------------------
This posting is provided "as is" with no warranties and confers no rights.
Author
24 Mar 2005 10:22 AM
Pegasus (MVP)
Show quote Hide quote
"Todd J Heron" <todd_heron_no_spam@hotmail.com> wrote in message
news:eet2Z7BMFHA.1172@TK2MSFTNGP12.phx.gbl...
> "David Lewis" <u***@microsoft.com> wrote in message
> news:mv84411p14ideh3fjomiiuahm2ktv0kogv@4ax.com...
> >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
> --------------------------------------------------------------------------
--
> This posting is provided "as is" with no warranties and confers no rights.
>

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.
Author
24 Mar 2005 8:55 PM
David Lewis
works, thankx

Show quoteHide quote
"Pegasus \(MVP\)" <I.***@fly.com>
|>
|>"Todd J Heron" <todd_heron_no_spam@hotmail.com> wrote in message
|>news:eet2Z7BMFHA.1172@TK2MSFTNGP12.phx.gbl...
|>> "David Lewis" <u***@microsoft.com> wrote in message
|>> news:mv84411p14ideh3fjomiiuahm2ktv0kogv@4ax.com...
|>> >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
|>> --------------------------------------------------------------------------
Author
25 Mar 2005 8:19 PM
Diane McCorkle
remember..
%logonserver% is only valid on 2000 and XP, 9x clients don't respect it..

Diane


Show quoteHide quote
"David Lewis" <u***@microsoft.com> wrote in message
news:29a641hpq4e0kgt44obte1jd7opilv24dq@4ax.com...
> works, thankx
>
> "Pegasus \(MVP\)" <I.***@fly.com>
> |>
> |>"Todd J Heron" <todd_heron_no_spam@hotmail.com> wrote in message
> |>news:eet2Z7BMFHA.1172@TK2MSFTNGP12.phx.gbl...
> |>> "David Lewis" <u***@microsoft.com> wrote in message
> |>> news:mv84411p14ideh3fjomiiuahm2ktv0kogv@4ax.com...
> |>> >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
> |>> --------------------------------------------------------------------------
>
Author
30 Mar 2005 6:05 PM
David Lewis
thankx.  We don't support 9x :) thank god


Show quoteHide quote
"Diane McCorkle" <diane.mccorkle at atcassociates.com>
|>remember..
|>%logonserver% is only valid on 2000 and XP, 9x clients don't respect it..
|>
|>Diane
|>
|>
|>"David Lewis" <u***@microsoft.com> wrote in message
|>news:29a641hpq4e0kgt44obte1jd7opilv24dq@4ax.com...
|>> works, thankx
|>>
|>> "Pegasus \(MVP\)" <I.***@fly.com>
|>> |>
|>> |>"Todd J Heron" <todd_heron_no_spam@hotmail.com> wrote in message
|>> |>news:eet2Z7BMFHA.1172@TK2MSFTNGP12.phx.gbl...
|>> |>> "David Lewis" <u***@microsoft.com> wrote in message
|>> |>> news:mv84411p14ideh3fjomiiuahm2ktv0kogv@4ax.com...
|>> |>> >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
|>> |>> --------------------------------------------------------------------------
|>>
|>

Bookmark and Share