Link to home
Start Free TrialLog in
Avatar of dtooth71
dtooth71

asked on

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?
Avatar of sirbounty
sirbounty
Flag of United States of America image

Almost sounds  like it isn't running.
Try placing a pause in there and determine if it's even kicking off...
Avatar of Panjandrum
Panjandrum

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


 
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
Also,

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

net use * /D /YES    


oops... posted at the same time  :)
heheeh, i know the feeling ;)

Would you mind posting back what helped you here?
Avatar of dtooth71

ASKER

/yes cleared and remapped the new drive
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...
Glad you got it resolved.

regards,

kshays
i do have multiple mappins, there are 6.
what do you suggest.  i am not opposed to trying something else that is more productive
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
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....
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).
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.
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.
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.
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...
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 :)

 

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...?
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
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
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
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.
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>
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...
ya, it might be good to aassign through GPO.
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
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
I have 9
so we could just use one script that would map all groups. sounds great!
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.

:)

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)
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
Will work on this in just a bit - I had to get on a stupid meeting for my supervisor... :(
excellent, you are the man!
Yeah, you could definately benefit from a more dynamic script.  Look forward to seeing what sirbounty comes up with ;)

Cheers,

kshays
Whew - the pressure's on... : $
ASKER CERTIFIED SOLUTION
Avatar of sirbounty
sirbounty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
DarthMod
CS Moderator

yes thank you
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
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
bear with me on the programming, not my strong point at this time
no problem - ask away if you need clarification on anything...
I'm just reading a boring manual...lol
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>
Sure - play around with it by adding yourself to the various groups and see if the mapping follows suit...
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
Whoops...
blnAct="True
should read
blnAct="True"
In this section...

ElseIf Instr(1,strGroup,"MARKETING") > 0 Then
  strDrives="F,I,J,M,P"
  blnMkt="True"
  blnAct="True"
End If
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
ok I saw the missing "

how about in line 46
char 8

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

Next

(vb habit)
I won't take offense - for obvious reasons I wasn't able to test out this 'exact' script in my environment...;^)
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...
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
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.


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
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)
For x = 0 to oDrives.Count - 1 Step 2
should read
For x = 0 to objDrives.Count - 1 Step 2
line 46
char 5
error network path not found
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...
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

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.

:)
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
that is not necessary.

good luck
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...
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
it is two servers that we will be mapping to

spider and cassandra(servername)
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?
thanks for all your help!! I will play with it and see if I can tweak it