tri_94 Posted August 24, 2012 Posted August 24, 2012 hi there i have a group of users that use laptops and are not part of a domain. they all have usernames on the domain. and what i need to be able to map there mydocs folder from the server but the script ideally needs to prompt for a username and then use that in the mapping.... example net use T: "\\Server\*there username*$ to map the hidden share. in a perfect world i would also like the script to be able to connect to 2 other network shares and a printer too. any ideas thanks nick
SYNACK Posted August 24, 2012 Posted August 24, 2012 Ask @SimpleSi this kind of setup is his speciality
Steve21 Posted August 24, 2012 Posted August 24, 2012 strInput = InputBox( "Enter your name now!!!", "DriveMapping") dim oShell Set oShell = CreateObject("WScript.Shell") oShell.Run "NET USE X: \\server\" & strInput & "$" (Not tested, but should do it) But aren't you going to need username/passwords etc to connect to the domain, or is it open? Steve
tri_94 Posted August 24, 2012 Author Posted August 24, 2012 Yes i am going to need a username and password to connect to the server. so is there a way of adding that in the code? i can setup a user with access to all home folders.
tri_94 Posted August 24, 2012 Author Posted August 24, 2012 just tried that script and it working if i have connected to the server with a username and password. but another question i have two server and have different users on each is there any way of saying if that share is not on server1 look at server 2 if that makes any sense? but thanks alot for the script
waldronm2000 Posted August 24, 2012 Posted August 24, 2012 Haven't tested this, but if you were to add & "/user:domainname\" & strInput to the end of the last line, (replace domainname with your domain of course), that should then ask for the password when it shells out to map the drive.
Steve21 Posted August 24, 2012 Posted August 24, 2012 Yes i am going to need a username and password to connect to the server. so is there a way of adding that in the code? i can setup a user with access to all home folders. Should be able to just add /user:domain\username password on end of code like this: strInput = InputBox( "Enter your name now!!!", "DriveMapping") dim oShell Set oShell = CreateObject("WScript.Shell") oShell.Run "NET USE X: \\server\" & strInput & "$ /user:domain\username password" Not tested though, Steve
tri_94 Posted August 24, 2012 Author Posted August 24, 2012 i must be doing somthing wrong as its not working for me
tri_94 Posted August 24, 2012 Author Posted August 24, 2012 nope not errors the script works without the "$ /user:domain\username password" am i right in thinking it would be /user:mydomain\myusername mypassword"
SYNACK Posted August 24, 2012 Posted August 24, 2012 nope not errors the script works without the "$ /user:domain\username password" am i right in thinking it would be /user:mydomain\myusername mypassword" Yes, you can grab the command line parameters by using "net use /?"
Steve21 Posted August 24, 2012 Posted August 24, 2012 nope not errors the script works without the "$ /user:domain\username password" am i right in thinking it would be /user:mydomain\myusername mypassword" Aye strInput = InputBox( "Enter your name now!!!", "DriveMapping") dim oShell Set oShell = CreateObject("WScript.Shell") oShell.Run "NET USE Y: \\server\" & strInput & "$ /user:MyDomain\BestUserEver EpicPassword" Works, just tried it on mine Steve
tri_94 Posted August 24, 2012 Author Posted August 24, 2012 right i've got that working. it was because my test machine was on the domain and therefore had the authenitcation. so is it possible to have it look at two servers and a way of telling it if that share is not on server1 look at server 2 if that makes any sense?
waldronm2000 Posted August 24, 2012 Posted August 24, 2012 Maybe instead of shelling out to a one-line net use command, shell to a three-line .cmd file that picks up the username, password and sharename as parameters, tries to use them to map to the share on server1, exits if errorlevel is 0, otherwise maps to server2...
tri_94 Posted August 24, 2012 Author Posted August 24, 2012 right and how could i do that? so is it not possible to use the script that "steve21" gave me and add something to it?
mac_shinobi Posted August 24, 2012 Posted August 24, 2012 Aye strInput = InputBox( "Enter your name now!!!", "DriveMapping") dim oShell Set oShell = CreateObject("WScript.Shell") oShell.Run "NET USE Y: \\server\" & strInput & "$ /user:MyDomain\BestUserEver EpicPassword" Works, just tried it on mine Steve Not sure if the FSO supports UNC paths but just curious if you could use FSO to check if the folder exists on each of the servers and then use the relevant server name ( which ever server said folder exists on ) From here : How to check if UNC folder exists You'd want to use the Dir() function in there, but you're right: it doesn't work. You could do this: Dim vDummy As Variant On Error Resume Next vDummy = Dir(FolderName & "\") If Err.Number = 0 Then ' The folder exists and can be accessed. Else ' The folder doesn't exist, or could not be accessed. End If Or you could use the FolderExists method of the FileSystemObject: Dim fso As Object Set fso = CreateObject("Scripting.FileSystemObject") If fso.FolderExists(FolderName) Then ' The folder exists. Else ' It doesn't. End If Then if it does exist on the first server map it that way and if not then check the other server and if it exists there then map it ?
SYNACK Posted August 24, 2012 Posted August 24, 2012 @mac_shinobi - You still need to authenticate before getting the share listing if not domained. I'd be tempted to use VBS or Autoit as these have many more features that would be useful in a non-domained environment. 1
tri_94 Posted August 24, 2012 Author Posted August 24, 2012 just had a idea, if its gonna be differcult to get it to check and see which server the user is on. then is it possible to tell it to map to server1 and do a command for if it fails to map, then run the script to server2? thanks nick
tri_94 Posted August 24, 2012 Author Posted August 24, 2012 strInput = InputBox( "Enter your name now!!!", "DriveMapping") dim oShell Set oShell = CreateObject("WScript.Shell") oShell.Run "NET USE T: \\server1\" & strInput & "$ /user:domain\user password" oShell.Run "NET USE S: \\server2\" & strInput & "$ /user:domain\user password" is there any reason why i couldnt use this script? thanks nick
mac_shinobi Posted August 24, 2012 Posted August 24, 2012 strInput = InputBox( "Enter your name now!!!", "DriveMapping") dim oShell Set oShell = CreateObject("WScript.Shell") oShell.Run "NET USE T: \\server1\" & strInput & "$ /user:domain\user password" oShell.Run "NET USE S: \\server2\" & strInput & "$ /user:domain\user password" is there any reason why i couldnt use this script? thanks nick Might possibly want to use the On Error Resume Next so if it does error out it carrys on running the rest of the code etc ? On Error Resume Next dim oShell Set oShell = CreateObject("WScript.Shell") oShell.Run "NET USE T: \\server1\" & strInput & "$ /user:domain\user password" oShell.Run "NET USE S: \\server2\" & strInput & "$ /user:domain\user password"
Steve21 Posted August 24, 2012 Posted August 24, 2012 strInput = InputBox( "Enter your name now!!!", "DriveMapping") dim oShell Set oShell = CreateObject("WScript.Shell") oShell.Run "NET USE T: \\server1\" & strInput & "$ /user:domain\user password" oShell.Run "NET USE S: \\server2\" & strInput & "$ /user:domain\user password" is there any reason why i couldnt use this script? thanks nick As mac mentioned best to put the resume line in, but any reason you're using two letters? T and S ? Should only ever map one so shouldn't run into problems with same letters etc Just makes life easier for software paths etc etc Steve
mac_shinobi Posted August 24, 2012 Posted August 24, 2012 As mac mentioned best to put the resume line in, but any reason you're using two letters? T and S ? Should only ever map one so shouldn't run into problems with same letters etc Just makes life easier for software paths etc etc Steve I take it there is no way to get group policy or GPP to do this for you instead of a script even if you have to put one group of users into one OU to map the drive from one server for them and the 2nd group of users into another OU with relevant GPO set to map the drive on the 2nd server or something like that ??
Steve21 Posted August 24, 2012 Posted August 24, 2012 I take it there is no way to get group policy or GPP to do this for you instead of a script even if you have to put one group of users into one OU to map the drive from one server for them and the 2nd group of users into another OU with relevant GPO set to map the drive on the 2nd server or something like that ?? If they're not on domain they won't get it though, or it'll be manual deploys which isn't any diff to script then really. Steve
SYNACK Posted August 25, 2012 Posted August 25, 2012 (edited) Might possibly want to use the On Error Resume Next so if it does error out it carrys on running the rest of the code etc ? On Error Resume Next dim oShell Set oShell = CreateObject("WScript.Shell") oShell.Run "NET USE T: \\server1\" & strInput & "$ /user:domain\user password" oShell.Run "NET USE T: \\server2\" & strInput & "$ /user:domain\user password" Slight adjustment, just map them both to the same letter, if it does not exist on the first server it won't map so the drive letter will be free for the second command. If it does exist it will take the drive leter and the second command will bomb out as the drive letter is already taken. Not pretty but simple. I'd also add in a line at the start to clear any existing connection to that letter just in case, I think it is something like this: dim oShell Set oShell = CreateObject("WScript.Shell") oShell.Run "NET USE T: /delete" oShell.Run "NET USE T: \\server1\" & strInput & "$ /user:domain\user password" oShell.Run "NET USE [b][color="#FF0000"]T[/color][/b]: \\server2\" & strInput & "$ /user:domain\user password" edit: I see Steve21 beat me to the above explanation anyhow,, the deletion of any existing connection is still useful though. Edited August 25, 2012 by SYNACK
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now