Mapping Drives based on Home server in VBScript 
Author Message
 Mapping Drives based on Home server in VBScript

I want a VBScript (to run under WSH) that will map a drive based on the
users home server.

Here is the situration:

We have many sites within our NT 4.0 domain. Each user has a home drive (H:)
specified in User Manager to point to their local server (not always a BDC
sometimes just a member server)
The Home server names (for their H: drives) are in the form S0402001 or
S0876543 for example (S = server, number = site number)
I want a VB script that will map the drive letter S: to
\\<HomeServername>\xxxShare (where xxx is the 3rd, 4th & 5th character of
the servername. IE \\S0402001\402SHARE
To get the server name you need to get the home drive variable and for the
share name extract the 3 characters and add the name share.
I think this would be a fairly simple script but I'm very new to this.
Thanks
Pete



Tue, 26 Nov 2002 03:00:00 GMT  
 Mapping Drives based on Home server in VBScript
Here's one option:
(NOTE: This script depends on the workstation being NT, if it's 9x, it'll
act a little different in relation to getting the home dir because it's not
automatically mapped at login.)

dim wshShell, wshNet, fso, fsoDrv, strPath, strSvr, strShr
set fso = createobject("Scripting.FileSystemObject")
set wshNet = CreateObject("WScript.Network")
set wshShell = CreateObject("WScript.Shell")
'Get the users home drive
set fsoDrv = fso.GetDrive("h:")
'Get the share name of the users home drive
strPath = fsoDrv.Sharename
'return the server name from the path
' this should be in the form: '\\S0402001\'
strSrv = left(strPath, instr(3, strPath, "\"))
'Get the 3 digit number from the share that starts in the 5th position
' and add share to it, it'll look like this: '402Share'
strShr = mid(strPath, 5, 3) & "Share"
'Map the network drive to the share
wshNet.MapNetworkDrive "S:", strSrv & strShr
'Display the path mapped.
wshShell.popup strSrv & strShr, , "NEW SHARE", vbInformation



Quote:
> I want a VBScript (to run under WSH) that will map a drive based on the
> users home server.

> Here is the situration:

> We have many sites within our NT 4.0 domain. Each user has a home drive
(H:)
> specified in User Manager to point to their local server (not always a BDC
> sometimes just a member server)
> The Home server names (for their H: drives) are in the form S0402001 or
> S0876543 for example (S = server, number = site number)
> I want a VB script that will map the drive letter S: to
> \\<HomeServername>\xxxShare (where xxx is the 3rd, 4th & 5th character of
> the servername. IE \\S0402001\402SHARE
> To get the server name you need to get the home drive variable and for the
> share name extract the 3 characters and add the name share.
> I think this would be a fairly simple script but I'm very new to this.
> Thanks
> Pete



Tue, 26 Nov 2002 03:00:00 GMT  
 Mapping Drives based on Home server in VBScript
A better solution uses ADSI to pull the home dir from the users profile.
This does require ADSI being installed on all workstations.

Dim User
Dim UserName
Dim UserDomain
Dim RetVal
UserDomain = "CatFish"
UserName = "Trout"

Set User = GetObject("WinNT://" & UserDomain & "/" & UserName & ",user")
RetVal = User.HomeDirectory

Then do your mapping code...  Easy as pie

-Mark


Quote:
> Here's one option:
> (NOTE: This script depends on the workstation being NT, if it's 9x, it'll
> act a little different in relation to getting the home dir because it's
not
> automatically mapped at login.)

> dim wshShell, wshNet, fso, fsoDrv, strPath, strSvr, strShr
> set fso = createobject("Scripting.FileSystemObject")
> set wshNet = CreateObject("WScript.Network")
> set wshShell = CreateObject("WScript.Shell")
> 'Get the users home drive
> set fsoDrv = fso.GetDrive("h:")
> 'Get the share name of the users home drive
> strPath = fsoDrv.Sharename
> 'return the server name from the path
> ' this should be in the form: '\\S0402001\'
> strSrv = left(strPath, instr(3, strPath, "\"))
> 'Get the 3 digit number from the share that starts in the 5th position
> ' and add share to it, it'll look like this: '402Share'
> strShr = mid(strPath, 5, 3) & "Share"
> 'Map the network drive to the share
> wshNet.MapNetworkDrive "S:", strSrv & strShr
> 'Display the path mapped.
> wshShell.popup strSrv & strShr, , "NEW SHARE", vbInformation



> > I want a VBScript (to run under WSH) that will map a drive based on the
> > users home server.

> > Here is the situration:

> > We have many sites within our NT 4.0 domain. Each user has a home drive
> (H:)
> > specified in User Manager to point to their local server (not always a
BDC
> > sometimes just a member server)
> > The Home server names (for their H: drives) are in the form S0402001 or
> > S0876543 for example (S = server, number = site number)
> > I want a VB script that will map the drive letter S: to
> > \\<HomeServername>\xxxShare (where xxx is the 3rd, 4th & 5th character
of
> > the servername. IE \\S0402001\402SHARE
> > To get the server name you need to get the home drive variable and for
the
> > share name extract the 3 characters and add the name share.
> > I think this would be a fairly simple script but I'm very new to this.
> > Thanks
> > Pete



Tue, 26 Nov 2002 03:00:00 GMT  
 Mapping Drives based on Home server in VBScript
Another suggestion:
The Technique that we use is to assign users to an NT Group denoting their
Home Server, e.g. "NT-SERVER1". That way we don't have problems with mixed
OS Clients and those without ADSI installed. We enumerate the groups for
each user and if they are in a group prefixed "NT-" then we take the last
bit and use it as their home server.

Rgds
Iain


Quote:
> A better solution uses ADSI to pull the home dir from the users profile.
> This does require ADSI being installed on all workstations.

> Dim User
> Dim UserName
> Dim UserDomain
> Dim RetVal
> UserDomain = "CatFish"
> UserName = "Trout"

> Set User = GetObject("WinNT://" & UserDomain & "/" & UserName & ",user")
> RetVal = User.HomeDirectory

> Then do your mapping code...  Easy as pie

> -Mark



> > Here's one option:
> > (NOTE: This script depends on the workstation being NT, if it's 9x,
it'll
> > act a little different in relation to getting the home dir because it's
> not
> > automatically mapped at login.)

> > dim wshShell, wshNet, fso, fsoDrv, strPath, strSvr, strShr
> > set fso = createobject("Scripting.FileSystemObject")
> > set wshNet = CreateObject("WScript.Network")
> > set wshShell = CreateObject("WScript.Shell")
> > 'Get the users home drive
> > set fsoDrv = fso.GetDrive("h:")
> > 'Get the share name of the users home drive
> > strPath = fsoDrv.Sharename
> > 'return the server name from the path
> > ' this should be in the form: '\\S0402001\'
> > strSrv = left(strPath, instr(3, strPath, "\"))
> > 'Get the 3 digit number from the share that starts in the 5th position
> > ' and add share to it, it'll look like this: '402Share'
> > strShr = mid(strPath, 5, 3) & "Share"
> > 'Map the network drive to the share
> > wshNet.MapNetworkDrive "S:", strSrv & strShr
> > 'Display the path mapped.
> > wshShell.popup strSrv & strShr, , "NEW SHARE", vbInformation



> > > I want a VBScript (to run under WSH) that will map a drive based on
the
> > > users home server.

> > > Here is the situration:

> > > We have many sites within our NT 4.0 domain. Each user has a home
drive
> > (H:)
> > > specified in User Manager to point to their local server (not always a
> BDC
> > > sometimes just a member server)
> > > The Home server names (for their H: drives) are in the form S0402001
or
> > > S0876543 for example (S = server, number = site number)
> > > I want a VB script that will map the drive letter S: to
> > > \\<HomeServername>\xxxShare (where xxx is the 3rd, 4th & 5th character
> of
> > > the servername. IE \\S0402001\402SHARE
> > > To get the server name you need to get the home drive variable and for
> the
> > > share name extract the 3 characters and add the name share.
> > > I think this would be a fairly simple script but I'm very new to this.
> > > Thanks
> > > Pete



Tue, 26 Nov 2002 03:00:00 GMT  
 Mapping Drives based on Home server in VBScript
I need to do something similar.
Using the HOMESHARE environment variable, which includes the username, I
need to remove the extra folder to make it in the form of
\\SERVERNAME\SHARENAME.
For example, for all Windows 2000 clients, the HOMESHARE is set as
\\SERVERNAME\SHARENAME\USERNAME.  I need to remove "USERNAME" from HOMESHARE
so that it is \\SERVERNAME\SHARENAME\.  I then need to append "Shared" from
the UNC.  Thus the end result is \\SERVERNAME\SHARENAME\Shared.

What do I need to do?

Thanks,
Jay

Quote:
> Here's one option:
> (NOTE: This script depends on the workstation being NT, if it's 9x, it'll
> act a little different in relation to getting the home dir because it's
not
> automatically mapped at login.)

> dim wshShell, wshNet, fso, fsoDrv, strPath, strSvr, strShr
> set fso = createobject("Scripting.FileSystemObject")
> set wshNet = CreateObject("WScript.Network")
> set wshShell = CreateObject("WScript.Shell")
> 'Get the users home drive
> set fsoDrv = fso.GetDrive("h:")
> 'Get the share name of the users home drive
> strPath = fsoDrv.Sharename
> 'return the server name from the path
> ' this should be in the form: '\\S0402001\'
> strSrv = left(strPath, instr(3, strPath, "\"))
> 'Get the 3 digit number from the share that starts in the 5th position
> ' and add share to it, it'll look like this: '402Share'
> strShr = mid(strPath, 5, 3) & "Share"
> 'Map the network drive to the share
> wshNet.MapNetworkDrive "S:", strSrv & strShr
> 'Display the path mapped.
> wshShell.popup strSrv & strShr, , "NEW SHARE", vbInformation



> > I want a VBScript (to run under WSH) that will map a drive based on the
> > users home server.

> > Here is the situration:

> > We have many sites within our NT 4.0 domain. Each user has a home drive
> (H:)
> > specified in User Manager to point to their local server (not always a
BDC
> > sometimes just a member server)
> > The Home server names (for their H: drives) are in the form S0402001 or
> > S0876543 for example (S = server, number = site number)
> > I want a VB script that will map the drive letter S: to
> > \\<HomeServername>\xxxShare (where xxx is the 3rd, 4th & 5th character
of
> > the servername. IE \\S0402001\402SHARE
> > To get the server name you need to get the home drive variable and for
the
> > share name extract the 3 characters and add the name share.
> > I think this would be a fairly simple script but I'm very new to this.
> > Thanks
> > Pete



Tue, 26 Nov 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Mapping home drives in VBScript

2. Mapping home network drive.

3. Mapping drive to user's home directory

4. Map drive to Home Dir

5. Mapping Drives based on NT global groups

6. Mapping drives based on group membership using ADSI with VBS

7. Drive Mappings based on Group Name

8. Drive Mapping based on Computer Name

9. mapping drives based on global groups

10. Mapping drives based on group membership

11. Drive Mappings based on group membership again

12. Drive mappings based on group membership

 

 
Powered by phpBB® Forum Software