script>network drives

I have a net use script that I assign to users profile that maps network shares during logon.  I made a change to a lone in the script that changes the name of where the share is located.  now when the users logon the mapping is still pointing towards the old name and not mapping  the new one.

OLD SCRIPT
cls
net use G: /d
cls
net use G: \\oldname\g-drive

NEW SCRIPT
cls
net use G: /d
cls
net use G: \\newname\g-drive



why would this not overwrite the old script and map the new share?
dtooth71Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sirbountyCommented:
Almost sounds  like it isn't running.
Try placing a pause in there and determine if it's even kicking off...
PanjandrumCommented:
Maybe some checks you can do

- Check all DC's netlogon folders to see if the scripts are propagated correctly (if you have more then 1 DC offcourse)

- Try mapping the script manually at a user
start --> run --> \\DC\netlogon --> use correct scritp

- Clear the cache of the PC's


 
Kevin HaysIT AnalystCommented:
maybe becuase the drive is still connected when you are trying to assign the same drive letter to it again.

Try any of the following, I can't remember which one it is since I use a vbscript to map drives based on group membership in AD.

net use g: \\servername\g_drive /persistant:no

net use * /delete /yes
net use g: \\servername\g_drive

The first command I believe will make sure it's disconnected after the user logs off the system.
The 2nd and 3rd commands go together and deletes all the shares and then recreates the g drive for you.

regards,

kshays
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

PanjandrumCommented:
Also,

you can use this is your script to clear out previous drives

net use * /D /YES    


PanjandrumCommented:
oops... posted at the same time  :)
Kevin HaysIT AnalystCommented:
heheeh, i know the feeling ;)

sirbountyCommented:
Would you mind posting back what helped you here?
dtooth71Author Commented:
/yes cleared and remapped the new drive
sirbountyCommented:
Odd - in my experience a /yes was only necessary when deleting multiple mappings (net use * /d)
Which is not what I'd recommend in any scenario since it can potentially destroy any scripted or manual mappings...
Kevin HaysIT AnalystCommented:
Glad you got it resolved.

regards,

kshays
dtooth71Author Commented:
i do have multiple mappins, there are 6.
what do you suggest.  i am not opposed to trying something else that is more productive
Kevin HaysIT AnalystCommented:
I would have probably done it with a /persistant:no
True, I would think if they had any manual mappings it would remove them, but then again my users don't map drives manually though :)

kshays
sirbountyCommented:
Is the above 'all' of your script?

No offense to the others here, but this seems to be more of a band-aid solution.
I would rather find out 'why' yours isn't working.

Is G a 'home' folder?  If the script is running *from* G, then that would explain it, and you could simply modify your script to something like:

@echo off
cls
%systemdrive%
if not exist G:\ goto mapDrive
net use G: /d >nul
:mapDrive
net use G: \\newname\g-drive
::you can add a /persist:yes if you want to 'keep' it that way....
sirbountyCommented:
kshays - nor do mine.
However, I think it's presumptious to think that nobody's manually mapping.  
I know at least some IT folks in our company certainly do... (I do, and would be pissed if my manual mappings were eliminated daily due to a poorly constructed login script).
dtooth71Author Commented:
no, that is not the entire script.  there are just more mappings to different locations but it is the same format.
g: is not a home folder it is a share that users access, like the other shares that the script has.
the script is located in the SYSVOL folder and assigned to each use.

I also use manual mapping, so if this will remove them maybe I should look for a better solution.  I do not want to remap my drives every morning.
sirbountyCommented:
Try heading your script with %systemdrive%
This places the command interpreter onto the local system's drive and runs the commands from there, eliminating any in-use network access paths as the culprit.
dtooth71Author Commented:
cls
%systemdrive%
net use G: /d
cls
net use G: \\newname\g-drive

is this what you are refering too? I am not opposed to completely redoing the script, this was created a very long time ago, I am sure there are better ways of accomplishing the same outcome these days.
sirbountyCommented:
Yes, systemdrive is the equivalent of C:\ (in 'most' cases).  Using the environment variable overrides any chance of it being other than C:\.
Then all the commands run from there - net.exe is in the system path, so it will still execute...
Kevin HaysIT AnalystCommented:
sirbounty - there are just 3 IT people and i'm one of them where I work and I've got us in a seperate OU than the "staff", but I would agree if I was in a larger corporation and others that administered gpo's and so forth did that to me I would be pissed as well :)

I know that nobody where i'm at does manual mapping at all.  I try to control what they can and cannot do so things don't get screwed up for me and my IT staff.

Anyway, I agree that you should write the login scripts and any other scripts properly so nothing gets screwed up in the process.  There is a lot of thought involved when designing your AD structure for many reasons as you know :)

 

sirbountyCommented:
I agree.  We do the same thing here with our IT staff, but we also use two accounts - our admin accounts don't even process a login script...

dtooth71 - if you want to post the entire script, perhaps we can put our heads together here and update it for you - perhaps a vbs solution...?
Kevin HaysIT AnalystCommented:
This also proves that there could be something more to a question that what is initially posted.  What would seem like a simple fix could actually destroy something else.

kshays
dtooth71Author Commented:
that would be great, I appreciate all the assistance!



cls
net use F: /d
net use G: /d
net use I: /d
net use J: /d
net use K: /d
net use M: /d
net use P: /d
cls
net use F: \\servername\f-drive
net use G: \\servername\g-drive
net use I: \\servername\i-drive
net use J: \\servername\j-drive
net use K: \\servername\k-drive
net use M: \\servername\m-drive
net use N: \\servername\accounting
net use P: \\servername\p-drive
sirbountyCommented:
Dim objNet
Set objNet = CreateObject("WScript.Network")

with objNet
 .MapNetworkDrive "F:" "\\servername\f-drive"
 .MapNetworkDrive "G:" "\\servername\g-drive"
 .MapNetworkDrive "I:" "\\servername\i-drive"
 .MapNetworkDrive "J:" "\\servername\j-drive"
 .MapNetworkDrive "K:" "\\servername\k-drive"
 .MapNetworkDrive "M:" "\\servername\m-drive"
 .MapNetworkDrive "N:" "\\servername\accounting"
 .MapNetworkDrive "P:" "\\servername\p-drive"
end with
set objNet=Nothing
Wscript.Quit
Kevin HaysIT AnalystCommented:
Hmmm.

Is this script applied via a GPO login script?
Is this applied to all users in your domain or just a set of particular groups in an OU?

From sirbountys post of the sample script using the net use if it applied to all users you should be able to modify that script fairly easy to implement it in your environment.
dtooth71Author Commented:
no this is currently not applied through GPO.  althought I do have groups that have different logon mappings.  I just modify the number of mappings the groups get.  this one above is just the biggest one. for example our cad department would look like this;

Dim objNet
Set objNet = CreateObject("WScript.Network")

with objNet
  .MapNetworkDrive "G:" "\\servername\g-drive"
  .MapNetworkDrive "K:" "\\servername\k-drive"
end with
set objNet=Nothing
Wscript.Quit

I would just create another script, assign it a different name and assign it to the CAD operators account in AD>
sirbountyCommented:
Looking at this again, it might be just as easy to create a looped array:

Dim objNet, strDrives, strDrv, strServer, x
Set objNet = CreateObject("WScript.Network")

strServer = "\\servername\"
strDrives="F,G,I,J,K,M,P"
strDrv=Split(strDrives,",")

with objNet
  For x = 0 to ubound(strDrv)
   .MapNetworkDrive strDrv(x) & ":", strServer & strDrv & "-drive"
  Next
 .MapNetworkDrive "N:", strServer & "accounting"
end with
set objNet=Nothing
Wscript.Quit

Or, you could set up a select case outlining the membership in groups...probably better still...
dtooth71Author Commented:
ya, it might be good to aassign through GPO.
sirbountyCommented:
How many groups are we talking?
You could run one managed script by identifying the group membership with something like:

Select Case objGroup
   Case "Marketing"
     ....map Marketing's drives...
   Case "Sales"
     ....map Sales' drives...
   Case Else
     ....map drives for users not in either group
End Select
Kevin HaysIT AnalystCommented:
I would agree with sirbounty's last comment on the switch, err select case that is.  I'm sure i'll be learning some new vbscript tips here from sirbounty :)

kshays
dtooth71Author Commented:
I have 9
dtooth71Author Commented:
so we could just use one script that would map all groups. sounds great!
Kevin HaysIT AnalystCommented:
Yes, that's how i've got my script as of now, but like I said i'm sure sirbounty can provide a much more efficient vbscript to do map the drives based on group membership in AD than mine will.

:)

sirbountyCommented:
Sure...however, can you provide a bit more detail on the groups?
How many users do you have?
Do some groups overlap?
Can you provide the mappings needed for each group? (Mask it as necessary)
dtooth71Author Commented:
there are about 75 users
um, no, not for the mappings/
these are the scripts that aare in use currently


ASSISTANT
cls
net use F: /d
net use G: /d
net use I: /d
net use J: /d
net use M: /d
net use R: /d
net use o: /d
cls
net use F: \\servername\f-drive
net use G: \\servername\g-drive
net use I: \\servername\i-drive
net use J: \\servername\j-drive
net use M: \\servername\m-drive
net use R: \\servername\marketing
net use o: \\servername\madagascar

CAD
cls

net use G: /d
net use K: /d
net use o: /d
cls
net use G: \\servername\g-drive
net use K: \\servername\k-drive
net use o: \\servername\madagascar
ENG
cls
net use F: /d
net use G: /d
net use I: /d
net use J: /d
net use K: /d
net use M: /d
net use P: /d
cls
net use F: \\servername\f-drive
net use G: \\servername\g-drive
net use I: \\servername\i-drive
net use J: \\servername\j-drive
net use K: \\servername\k-drive
net use M: \\servername\m-drive
net use N: \\servername1\accounting
net use P: \\servername\p-drive

INTERN

cls
net use J: /d
net use G: /d
net use K: /d

cls
net use J: \\servername\j-drive
net use g: \\servername\G-drive
net use K: \\servername\K-drive

MARKETING
cls
net use I: /d
net use J: /d
net use M: /d
net use P: /d
net use R: /d
cls
net use F: \\servername\f-drive
net use G: \\servername\g-drive
net use I: \\servername\i-drive
net use J: \\servername\j-drive
net use M: \\servername\m-drive
net use N: \\servername1\accounting
net use P: \\servername\p-drive
net use R: \\servername\marketing
sirbountyCommented:
Will work on this in just a bit - I had to get on a stupid meeting for my supervisor... :(
dtooth71Author Commented:
excellent, you are the man!
Kevin HaysIT AnalystCommented:
Yeah, you could definately benefit from a more dynamic script.  Look forward to seeing what sirbounty comes up with ;)

Cheers,

kshays
sirbountyCommented:
Whew - the pressure's on... : $
sirbountyCommented:
Now I know why he didn't want to attend...sheesh!  What a boring meeting.  Anyway - here's what I've come up with.  Test it and let me know...I've tried to comment it as much as necessary.
The function (below) is added as a 'just-in-case'.  It's not being used in the code at all, but as you're *renewing* your G drive, you could certainly call it in the script (clrNetDrive "G:")

Dim objNet, objADInfo, objUser 'declare objects
Dim strGroup, strDrv, strDrives, strServer 'declare string values
Dim blnAct, blnMad, blnMkt 'declare booleans

set objNet=CreateObject("Wscript.Network") 'create network object
set objADInfo=CreateObject("ADSystemInfo") 'create AD object
set objUser=GetObject("LDAP://" & objADInfo.UserName) 'create user object

strServer="\\servername\" 'string value containing server name
strGroup=UCase(Join(objUser.MemberOf,vbCr)) 'combine all groups into an array

'Determine group membership and setup mapping parameters accordingly
If Instr(1,strGroup,"ASSISTANT") > 0 Then
  strDrives="F,I,J,M"
  blnMkt="True"
  blnMad="True"
ElseIf Instr(1,strGroup,"CAD") > 0 Then
  strDrives="K"
  blnMad="True"
ElseIf Instr(1,strGroup,"ENG") > 0 Then
  strDrives="F,I,J,K,M,P"
  blnAct="True"
ElseIf Instr(1,strGroup,"INTERN") > 0 Then strDrives="J,K"
ElseIf Instr(1,strGroup,"MARKETING") > 0 Then
  strDrives="F,I,J,M,P"
  blnMkt="True"
  blnAct="True
End If

'Add common drive mapping  -since everyone is mapping G
strDrives="G," & strDrives

'Establish drive enumeration
strDrv=split(strDrives,",")

'---===Drive Mappings===---
'
'    run clrNetDrive to clear any drives in advance
'    particulary in situations where you want to change
'    the target or ensure the drive is not in use


With objNet
  For x = 0 to Ubound(strDrv) 'Loop through drive mappings
    .MapNetworkDrive strDrv(x) & ":", strServer & strDrv(x) & "-drive"
  Next x
  'Add additional mappings based upon membership criteria
  If blnAct Then .MapNetworkDrive "N:", strServer & "acounting"
  If blnMad Then .MapNetworkDrive "O:", strServer & "madagascar"
  If blnMkt Then .MapNetworkDrive "R:", strServer & "marketing"
End With

set objNet=Nothing
set objADInfo=Nothing
set objUser=Nothing
WScript.Quit

Function clrNetDrive (strDrive)
'Usage:  
'       clrNetDrive (X:)
' where X: is the drive letter to remove
Dim x, objDrives
Set objDrives = objNet.EnumNetworkDrives
For x = 0 to oDrives.Count - 1 Step 2
 If objDrives.Item(x) = strDrive Then objNet.RemoveNetworkDrive strDrive, True, True
Next
set objDrives=Nothing
End Function

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dtooth71Author Commented:
DarthMod
CS Moderator

yes thank you
dtooth71Author Commented:
WOW!! sirbounty, so I copy and paste this entire code into a file, change it to .bat and then assign the name of the script to the user accounts, or actually to the GPO.  please advise
sirbountyCommented:
No, sorry - it's a vbs script - not a bat...a vbs.
Call it
Mapping.vbs
or
<whatever>.vbs

You should be able to call it by simply referencing the name - otherwise precede it with the built-in cscript:

cscript mapping.vbs

in your domain login script
dtooth71Author Commented:
bear with me on the programming, not my strong point at this time
sirbountyCommented:
no problem - ask away if you need clarification on anything...
I'm just reading a boring manual...lol
dtooth71Author Commented:
I think for testing I should put it where the other scripts are and assign it to me for testing, then when all is good maybe to the GPO> what do you think>
sirbountyCommented:
Sure - play around with it by adding yourself to the various groups and see if the mapping follows suit...
dtooth71Author Commented:
Windows Script Host Error

script:  \\server\netlogon\script.vbs
line:     27
Char:     15
error:    unterminiated string constant
Code:   800A0409
Sourcce:  Microsoft VBscript compilation error


this is what I see
sirbountyCommented:
Whoops...
blnAct="True
should read
blnAct="True"
sirbountyCommented:
In this section...

ElseIf Instr(1,strGroup,"MARKETING") > 0 Then
  strDrives="F,I,J,M,P"
  blnMkt="True"
  blnAct="True"
End If
Kevin HaysIT AnalystCommented:
hehe, i thought about posting there needed to be another quote around blnAct awhile back but I didn't want to offend anyone though :)

I'm looking over the script sirbounty and it looks like so far it's more dynamic than what i'm using right now.

Cheers on a good script!

kshays
dtooth71Author Commented:
ok I saw the missing "

how about in line 46
char 8

I do not see this one
sirbountyCommented:
Er, <ahem>, remove the 'x'...
it should read:

Next

(vb habit)
sirbountyCommented:
I won't take offense - for obvious reasons I wasn't able to test out this 'exact' script in my environment...;^)
sirbountyCommented:
I don't know why vb requires you to declare the variable and vbs doesn't...I might have to ask that question in the programming TA... haha.
It gets me *every* time...
dtooth71Author Commented:
we are all human, man it is all good> I understand

ready for this one???

line 45
char 5
error the local device name has a remembered connection to another network resource
Kevin HaysIT AnalystCommented:
ahh ok, i know what you mean there.  I commented a lot of stuff out first and just added a few msgbox's, change the security groups to a few in my AD environment just to see what kind of info I was getting.  Very simple script once you actually see what type of data you are getting and how it is performing the actions.


sirbountyCommented:
Ah - there's where clrNetDrive comes in...
Adjust the For/Next loop as so...

  For x = 0 to Ubound(strDrv) 'Loop through drive mappings
     clrNetDrive (strDrv(x) & ":"
    .MapNetworkDrive strDrv(x) & ":", strServer & strDrv(x) & "-drive"
  Next
dtooth71Author Commented:
again, bear with me, I wish i could look and help but.....

 For x = 0 to Ubound(strDrv) 'Loop through drive mappings
     clrNetDrive (strDrv(x)) & ":"
    .MapNetworkDrive strDrv(x) & ":", strServer & strDrv(x) & "-drive"
  Next

i added the secound ) on the clrNetDrive line

now

line 65
char 1
error object requires: 'oDrives'


were almost to the end (group engineers)
sirbountyCommented:
For x = 0 to oDrives.Count - 1 Step 2
should read
For x = 0 to objDrives.Count - 1 Step 2
dtooth71Author Commented:
line 46
char 5
error network path not found
sirbountyCommented:
A tad trickier...

Modify your for/next to read this:

  For x = 0 to Ubound(strDrv) 'Loop through drive mappings
    wscript.echo "Mapping " & strDrv(x) & ":" & " to " & strServer & strDrv(x) & "-drive"
    .MapNetworkDrive strDrv(x) & ":", strServer & strDrv(x) & "-drive"
  Next

See if you can identify where it's failing.
You can replace wscript.echo with msgbox if you'd rather...depending on how you 'call' the script, one produces text output, the other a pop-up box...
dtooth71Author Commented:
OK I see that these mappings are based of of

strServer="\\servername\" 'string value containing server name

so accounting is on a differnet box  so this is what I think to do

create another line

strServer="\\servername\" 'string value containing server name
strServer1="\\spider\" 'string value containing server name


then this on accounting line


'Add additional mappings based upon membership criteria
  If blnAct Then .MapNetworkDrive "N:", strServer1 & "acounting"


am i on the correct path

Kevin HaysIT AnalystCommented:
Sirbounty, what exactly is the method used for in your last post?  I can tell it's looping through the strDrv array until it gets to the upper bounds, but i'm sorta confused on the "-drive" part on the .MapNetworkDrive though.

:)
dtooth71Author Commented:
I see the dialog box that is appearing and dont want that to appear each time users log on, is that necessary


so far I can not get it to work, my day is over, tomorrow will try again
Kevin HaysIT AnalystCommented:
that is not necessary.

good luck
sirbountyCommented:
If it's just that one, I would probably say do it this way instead:

  If blnAct Then .MapNetworkDrive "N:", "\\spider\acounting"

>Sirbounty, what exactly is the method used for in your last post?  I can tell it's looping through the strDrv array until it gets to the upper bounds, but i'm sorta confused on the "-drive" part on the .MapNetworkDrive though.<

the -drive was the portion of the mapped drive..
\\server\f-drive
\\server\g-drive
etc...
Since F: maps to \\server\F-drive, I'm just using the array variable in both places...

>>I see the dialog box that is appearing and dont want that to appear each time users log on, is that necessary<<
No, the dialog box was for troubleshooting the problem.  Looks like you found it (the spider server), thus that wscript.echo line can again be removed...
Kevin HaysIT AnalystCommented:
Doh!  The share name was "F-drive".  That confused the heck out of me :)  I've modified your script sirbounty to suit my needs as well.  It's smaller and much simpler than my current one.

Hats off you man, excellent script!

kshays
dtooth71Author Commented:
it is two servers that we will be mapping to

spider and cassandra(servername)
Kevin HaysIT AnalystCommented:
With objNet
      For x = 0 to Ubound(strDrv) 'Loop through drive mappings
            clrNetDrive (strDrv(x)) & ":"
        Next

      'Add additional mappings based upon membership criteria
       If blnIT Then
            .MapNetworkDrive "N:", strDC & "IT"
            .MapNetworkDrive "O:", strDC & "PUBLIC"
      end if
      
        If blnSL Then .MapNetworkDrive "O:", strServer & "sales"
        If blnMK Then .MapNetworkDrive "F:", strServer & "marketing"
        If blnCS Then .MapNetworkDrive "F:", strServer & "customer_service"
        If blnHR Then .MapNetworkDrive "F:", strServer & "quickbooks"

      ' Map public drives, home folder for each account
      .MapNetworkDrive "Y:", strFileServer & "Public"                        'public on fileserver
      .MapNetworkDrive "Z:", strFileServer & objNet.UserName            'home folder

End With

Is this example what you were looking for?
dtooth71Author Commented:
thanks for all your help!! I will play with it and see if I can tweak it
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2003

From novice to tech pro — start learning today.