Solved

Logon Script to check mapped drives

Posted on 2011-02-16
8
1,715 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

OfficeMate Freezes on login or does not load after login credentials are input.
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 create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

773 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