Solved

Logon Script to check mapped drives

Posted on 2011-02-16
8
1,722 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

Always backup Domain, SYSVOL etc.using processes according to Microsoft Best Practices. This is meant as a disaster recovery process for small environments that did not implement backup processes and did not run a secondary domain controller that ne…
I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
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…

688 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