+ Post New Thread
Page 2 of 2 FirstFirst 12
Results 16 to 25 of 25
Scripts Thread, Script to Map Home Directory after prompting for username in Coding and Web Development; Originally Posted by Steve21 Aye Code: strInput = InputBox( "Enter your name now!!!", "DriveMapping") dim oShell Set oShell = CreateObject("WScript.Shell") ...
  1. #16

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,932
    Thank Post
    3,464
    Thanked 1,090 Times in 1,005 Posts
    Rep Power
    371
    Quote Originally Posted by Steve21 View Post
    Aye

    Code:
    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 ?

  2. #17
    tri_94's Avatar
    Join Date
    Feb 2007
    Location
    Lincolnshire
    Posts
    117
    Thank Post
    2
    Thanked 2 Times in 2 Posts
    Rep Power
    17
    sorry i really dont follow that one.

  3. #18

    SYNACK's Avatar
    Join Date
    Oct 2007
    Posts
    11,247
    Thank Post
    882
    Thanked 2,745 Times in 2,319 Posts
    Blog Entries
    11
    Rep Power
    785
    @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.

  4. Thanks to SYNACK from:

    mac_shinobi (24th August 2012)

  5. #19
    tri_94's Avatar
    Join Date
    Feb 2007
    Location
    Lincolnshire
    Posts
    117
    Thank Post
    2
    Thanked 2 Times in 2 Posts
    Rep Power
    17
    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

  6. #20
    tri_94's Avatar
    Join Date
    Feb 2007
    Location
    Lincolnshire
    Posts
    117
    Thank Post
    2
    Thanked 2 Times in 2 Posts
    Rep Power
    17
    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

  7. #21

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,932
    Thank Post
    3,464
    Thanked 1,090 Times in 1,005 Posts
    Rep Power
    371
    Quote Originally Posted by tri_94 View Post
    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"

  8. #22

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,731
    Thank Post
    344
    Thanked 520 Times in 488 Posts
    Rep Power
    180
    Quote Originally Posted by tri_94 View Post
    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

  9. #23

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,932
    Thank Post
    3,464
    Thanked 1,090 Times in 1,005 Posts
    Rep Power
    371
    Quote Originally Posted by Steve21 View Post
    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 ??

  10. #24

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,731
    Thank Post
    344
    Thanked 520 Times in 488 Posts
    Rep Power
    180
    Quote Originally Posted by mac_shinobi View Post
    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

  11. #25

    SYNACK's Avatar
    Join Date
    Oct 2007
    Posts
    11,247
    Thank Post
    882
    Thanked 2,745 Times in 2,319 Posts
    Blog Entries
    11
    Rep Power
    785
    Quote Originally Posted by mac_shinobi View Post
    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:
    Code:
    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 T: \\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.
    Last edited by SYNACK; 25th August 2012 at 07:06 AM.



SHARE:
+ Post New Thread
Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 6
    Last Post: 23rd August 2012, 10:40 PM
  2. Giving user access to all home directories
    By paularmstrong in forum Windows
    Replies: 11
    Last Post: 7th November 2007, 09:27 AM
  3. Replies: 0
    Last Post: 20th August 2007, 03:20 PM
  4. Script to set active directory object security
    By meastaugh1 in forum Windows
    Replies: 4
    Last Post: 5th January 2007, 05:28 AM
  5. Replies: 19
    Last Post: 20th June 2006, 04:53 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •