Solved

Logon Script to check mapped drives

Posted on 2011-02-16
8
1,719 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

This article describes my battle tested process for setting up delegation. I use this process anywhere that I need to setup delegation. In the article I will show how it applies to Active Directory
This article explains the steps required to use the default Photos screensaver to display branding/corporate images
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

738 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