Solved

Logon Script to check mapped drives

Posted on 2011-02-16
8
1,710 Views
Last Modified: 2012-05-11
Server 2008 R2 DC
Some XP pro and Some 7 Pro Clients

OK - so i have been racking my brain trying to figure this out. I need a logon script perferably a batch file) that will run like so

:Start
If X: Does not exist go to MapX
If X: Does exist  Go to VerifyX
:MapX
net use X: \\Server1\Share
goto EOF

:VerifyX
IF UNC of X: IS Not \\Server1\Share 
net use X: /d
net use X: \\Server1\Share
Goto EOF

Open in new window


I can not seem to figure out how to verify the UNC of the share path to remap if needed ony I want to avoid the extra traffic of deleting and remapping shares everytime someone logs on

Thanks
0
Comment
Question by:speeDemon
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 16

Expert Comment

by:sjklein42
ID: 34912340
Here's what I've done:

To verify:

dir \\Server1\Share\ >nul:

Then check %ERRORLEVEL% (which you can use in an IF)
 %ERRORLEVEL% will be zero if the share is already mounted.
%ERRORLEVEL% will be 1 if it needs to be mounted

dir \\Server1\Share\ >nul: 2>nul:
if ERRORLEVEL 1 net use X: \\Server1\Share

Open in new window

0
 
LVL 1

Author Comment

by:speeDemon
ID: 34912464
Can i get that in full code here is what I have so Far

@ECHO OFF

:START
echo at start
IF EXIST P:\ (
	GOTO VerifySvr1
	) ELSE (
		GOTO MAPSVR1		
)
:MAPSVR1
pause
net use P: \\Server1\Share
GOTO EOF
:VerifySvr1
{How does your Code fit here?}

:END

Open in new window

0
 
LVL 12

Accepted Solution

by:
Sommerblink earned 350 total points
ID: 34912475
How about skipping the logon scripts all together and use group policy exclusively?

http://blogs.technet.com/b/askds/archive/2009/01/07/using-group-policy-preferences-to-map-drives-based-on-group-membership.aspx is a great article about accomplishing this.
0
 
LVL 16

Expert Comment

by:sjklein42
ID: 34912493
I think this is all it takes to replace your entire procedure:

@dir P:\ >nul: 2>nul:
@if ERRORLEVEL 1 @net use P: \\Server1\Share 

Open in new window

0
 
LVL 6

Expert Comment

by:sharjeel ashraf
ID: 34912579
@ECHO OFF

:START
echo at start
IF EXIST P:\ (
      GOTO VerifySvr1
      ) ELSE (
            GOTO MAPSVR1            
)
:MAPSVR1
pause
net use P: \\Server1\Share
GOTO EOF
:VerifySvr1
dir P:\ >nul: 2>nul:
if ERRORLEVEL 1 net use P: \\Server1\Share  
:END
0
 
LVL 6

Expert Comment

by:sharjeel ashraf
ID: 34912581
whats the pause for?
0
 
LVL 47

Assisted Solution

by:Donald Stewart
Donald Stewart earned 150 total points
ID: 34913229
another article on Gp preferences


GP Preferences Will Reduce Logon Scripts : Mapping Drives


http://blogs.technet.com/b/grouppolicy/archive/2009/02/11/gp-preferences-will-reduce-logon-scripts-mapping-drives.aspx


0
 
LVL 1

Author Closing Comment

by:speeDemon
ID: 34913416
Perfect, this saves me a bunch of time, I love Group Policy!
0

Join & Write a Comment

Introduction You may have a need to setup a group of users to allow local administrative access on workstations.  In a domain environment this can easily be achieved with Restricted Groups and Group Policies. This article will demonstrate how to…
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now