Solved

Logon Script to check mapped drives

Posted on 2011-02-16
8
1,713 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 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

15 Experts available now in Live!

Get 1:1 Help Now