Jump to content

Recommended Posts

Posted

Hi,

 

I am currently trying to map an extra network drive for pupils on log on.

 

We use simple bat files normally and this works fine for us for now, however I am trying to use a VB as this script needs to be a little more complex.

 

The script checks the first two characters of the computer name and then only allows a network drive to map for certain machines (by room number).

 

I can get this to work with any admin or staff account, but not a pupil account. I believe that this is due to restrictions we have set up to 'lockdown' our network. I have tried researching adding user credentials into the script but always receive the same error message when running the code.

"Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again.."

 

Following this message I have tried a bit of script to remove cached user credentials, to no avail.

 

Here is my script so far... maybe a little messy, but i'm only just learning.

 

set shell = WScript.CreateObject( "WScript.Shell" )

computername = shell.ExpandEnvironmentStrings("%COMPUTERNAME%")

If (left(computername,2)) = "D2" Or (left(computername,2)) = "D3" Or 

(left(computername,2)) = "D4" Or (left(computername,2)) = "D5" Then

wscript.echo ("This test was a success!")

Dim objNetwork, strRemotePath1, strDriveLetter1

strDriveLetter1 = "T:"
strRemotePath1 = "\\Server\Share"
On Error Resume Next
Set objNetwork = CreateObject("WScript.Network") 
objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1

ElseIf  (left(computername,2)) = "SV" Then

wscript.echo ("This test was a successful failure!")

Else

wscript.echo ("This test was a failure!")

wscript.Quit
End if

 

I beleive this to remove cached credentials, but as I said, I couldn't get it to work.

 

strServer = "servername"
strCommand = "cmd /c cmdkey /delete:" & strServer
objShell.Run strCommand, 0, True

 

And finally the adding user credentials section.

 

Set objNetwork = WScript.CreateObject("WScript.Network")
strDriveLetter1 = "L:"
strRemotePath1 = "\\server\share"
strPer1 = "FALSE"
strUsr1 = "username"
strPas1 = "password"
objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1, strPer1, strUsr1, strPas1

 

Any help would be greatly appreciated, or even just tell me that i'm going the wrong way about achieving what I set out to.

 

Thanks,

Pete

Posted

Are the permissions on the share correct?

 

I have a test student account which loads the default profile etc, but doesn't apply any of the lockdown settings so I can emulate a student, but also have the ability to get to areas I need - in this case, I would see if I could manually map the drive as a student.

 

My VB head has floated away the last few days...

 

I've always used the network object to obtain the computer name and username should I be that way inclined, but I suspect it doesn't really make any difference.

Posted

I have set the NTFS permissions on the share. They are set at full control for now, and i'll lock down later.

 

When trying to map to the drive manually, I get an error of this has been disable / not allowed, something like that. Which I took to mean the group policies we have do not allow students to perform this action.

 

When testing without our lockdown policy enabled, the script works beautifully.

 

I figured that running the script as admin would bypass this policy, but I couldn't get it to work.

 

Cheers for the quick responce,

Pete

Posted

The credentials is not to do with cached credentials, it's just that you can't have 2 connections to the same server using different usernames

 

this means that you can't do:

net use X: \\server1\share1 /user:steve password
net use Y: \\server1\share2 /user:fredd password

 

What restrictions do you have on connecting network drives? There's nothing wrong with the idea of your script.

Posted

Ah, I see. So that would never work.

 

Pupils are able to map network drives when they log-on. They get 3 drives mapped normally with no problems, just using a net use bat file GP applied to the Pupil OU.

 

I could map this drive to all users everywhere in school just adding to this bat file, but as I want to run this more complex VB script. I just tested this and the drive was mapped, permissions must not be a problem.

 

Could I use the bat to call the VB script? or something like that?

 

Any ideas?

 

Cheers,

Pete

Posted

 

Could I use the bat to call the VB script? or something like that?

 

No problem; just add:

 

cscript \\server\share\mappingscript.vbs

 

to your existing batch file.

 

You could also do it all in a batch file if you prefer:

 

if %computername:~0,2% ==  D2 net use T: \\server\share
if %computername:~0,2% ==  D3 net use T: \\server\share
if %computername:~0,2% ==  D4 net use T: \\server\share
if %computername:~0,2% ==  D5 net use T: \\server\share

 

The ~ operator does string slicing; you take the variable computername and slice it, starting at position 0 and taking 2 characters

  • Thanks 1
Posted

That's great!

 

Thank you very much, i'll use the bat file.

 

I was quite proud that the VB worked, even though it didn't work through pupil accounts. I'm very new to it.

 

Finally, again probably very easy but, how do I get a message box on screen saying "Done" and a click ok box?

 

ECHO [message] - only brings it up in cmd.

MSGBOX - says not recognised as a command. (found it on a website somewhere)

 

Thanks,

Pete

Posted

msgbox works in vbscript - you could have 1 line vbs file saying

msgbox "OK"

and then call that from your batch file. Pretty sure you can't do Windows messages from a command script without calling another program. You can do:

pause Done

which will then stop and wait for you to press a key but it's not obvious if you're not looking for it.

 

Good luck with it all - it does eventually become really useful and (maybe!) fun :-)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...