Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - vbscripting on windows 2008 active directory

Reply
 
Old 10-08-2009   #1 (permalink)
PSU


 
 

vbscripting on windows 2008 active directory

I have been using, windows 2003, the following command to map group users to
their respective departmental drives.

'Grab the user name
UserString = WSHNetwork.UserName
'Bind to the user object to get user name and check for group memberships
later
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)

For Each GroupObj In UserObj.Groups

Select Case UCase(UserObj.Name)

Now, this script stop working under windows 2008 environment.
Is there a solution or a recommendation to make it work in windows 2008
active directory environment?

Thanks

You can email sugestions to par13@newsgroup

My System SpecsSystem Spec
Old 10-09-2009   #2 (permalink)
Richard Mueller [MVP]


 
 

Re: vbscripting on windows 2008 active directory


"PSU" <PSU@newsgroup> wrote in message
news:8A0B6EAD-1FA8-4011-9B84-C0446084C113@newsgroup
Quote:

>I have been using, windows 2003, the following command to map group users
>to
> their respective departmental drives.
>
> 'Grab the user name
> UserString = WSHNetwork.UserName
> 'Bind to the user object to get user name and check for group memberships
> later
> Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)
>
> For Each GroupObj In UserObj.Groups
>
> Select Case UCase(UserObj.Name)
>
> Now, this script stop working under windows 2008 environment.
> Is there a solution or a recommendation to make it work in windows 2008
> active directory environment?
>
We are not seeing enough of your script, but nothing has changed in Windows
Server 2008 AD that accounts for your experience. Does the script work when
you run it after logon? Is there an error message when you run it?

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 10-09-2009   #3 (permalink)
PSU


 
 

Re: vbscripting on windows 2008 active directory

Hi Richard,

The script works if its run again, after the user logged in the computer.
However, during logon process, the department network drives do not map, only
the two network drives before using the group object function.

Here is a copy of the script:


Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj, Path

Dim oNetwork
Dim objWshShell
Dim sComputer
Dim objFSO
Dim strDirectory
Dim objShell
Dim strUserName, objFileSys


Set oNetwork = CreateObject("Wscript.Network")
Set objWshShell = CreateObject("Wscript.Shell")
Set objFSO=CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set objFileSys = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("WScript.Network")

Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
'Automatically find the domain name
Set objDomain = getObject("LDAP://rootDse")
DomainString = objDomain.Get("dnsHostName")
'Find the Windows Directory
WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")


'Grab the user name
UserString = WSHNetwork.UserName
'Bind to the user object to get user name and check for group memberships
later
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)


'Grab the computer name for use in add-on code later
strComputer = WSHNetwork.ComputerName


'Disconnect ALL mapped drives
Set clDrives = WshNetwork.EnumNetworkDrives
For i = 0 to clDrives.Count -1 Step 2
WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True
Next

'Map drives needed by all
'Note the first command uses the user name as a variable to map to a user
share.
Set WshNetwork = WScript.CreateObject("WScript.Network")
'On Error Resume Next

WSHNetwork.MapNetworkDrive "P:", "\\server\dfs\Departments\public" ,True
WSHNetwork.MapNetworkDrive "H:", "\\server\dfs\home\" & UserString ,True

For Each GroupObj In UserObj.Groups

Select Case UCase(UserObj.Name)

Case "LV-ACA-AFFAIRS"

WSHNetwork.MapNetworkDrive "t:", "\\server\dfs\Departments\lvpd"
WSHNetwork.MapNetworkDrive "N:", "\\server\dfs\Departments\acad"
WSHNetwork.MapNetworkDrive "M:", "\\server\dfs\Departments\faculty"
WSHNetwork.AddWindowsPrinterConnection "\\server\LV-AdminHall"

Case "LV-ADMISION"

WSHNetwork.MapNetworkDrive "N:", "\\server\dfs\Departments\admission"
WSHNetwork.MapNetworkDrive "L:", "\\server\dfs\Departments\awp"
WSHNetwork.AddWindowsPrinterConnection "\\server\LV-AdminHall"

End Select
Next





'Clean Up Memory We Used
set UserObj = Nothing
set GroupObj = Nothing
set WSHNetwork = Nothing
set DomainString = Nothing
set WSHSHell = Nothing
Set WSHPrinters = Nothing


'Quit the Script
wscript.quit

"Richard Mueller [MVP]" wrote:
Quote:

>
> "PSU" <PSU@newsgroup> wrote in message
> news:8A0B6EAD-1FA8-4011-9B84-C0446084C113@newsgroup
Quote:

> >I have been using, windows 2003, the following command to map group users
> >to
> > their respective departmental drives.
> >
> > 'Grab the user name
> > UserString = WSHNetwork.UserName
> > 'Bind to the user object to get user name and check for group memberships
> > later
> > Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)
> >
> > For Each GroupObj In UserObj.Groups
> >
> > Select Case UCase(UserObj.Name)
> >
> > Now, this script stop working under windows 2008 environment.
> > Is there a solution or a recommendation to make it work in windows 2008
> > active directory environment?
> >
>
> We are not seeing enough of your script, but nothing has changed in Windows
> Server 2008 AD that accounts for your experience. Does the script work when
> you run it after logon? Is there an error message when you run it?
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>
>
>
My System SpecsSystem Spec
Old 10-09-2009   #4 (permalink)
Richard Mueller [MVP]


 
 

Re: vbscripting on windows 2008 active directory

The following statement:

Select Case UCase(UserObj.Name)

should be:

Select Case UCase(GroupObj.Name)

Also, I would use:

DomainString = WSHNetwork.UserDomain

And, I would use one object reference for the wshShell, wshNetwork, and
FileSystemObject objects. You have several for each.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--

"PSU" <PSU@newsgroup> wrote in message
news:6A456157-5661-42D2-9DDA-1884D4CF4D13@newsgroup
Quote:

> Hi Richard,
>
> The script works if its run again, after the user logged in the computer.
> However, during logon process, the department network drives do not map,
> only
> the two network drives before using the group object function.
>
> Here is a copy of the script:
>
>
> Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj,
> Path
>
> Dim oNetwork
> Dim objWshShell
> Dim sComputer
> Dim objFSO
> Dim strDirectory
> Dim objShell
> Dim strUserName, objFileSys
>
>
> Set oNetwork = CreateObject("Wscript.Network")
> Set objWshShell = CreateObject("Wscript.Shell")
> Set objFSO=CreateObject("Scripting.FileSystemObject")
> Set objShell = CreateObject("WScript.Shell")
> Set objFileSys = CreateObject("Scripting.FileSystemObject")
> Set objNetwork = CreateObject("WScript.Network")
>
> Set WSHShell = CreateObject("WScript.Shell")
> Set WSHNetwork = CreateObject("WScript.Network")
> 'Automatically find the domain name
> Set objDomain = getObject("LDAP://rootDse")
> DomainString = objDomain.Get("dnsHostName")
> 'Find the Windows Directory
> WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")
>
>
> 'Grab the user name
> UserString = WSHNetwork.UserName
> 'Bind to the user object to get user name and check for group memberships
> later
> Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)
>
>
> 'Grab the computer name for use in add-on code later
> strComputer = WSHNetwork.ComputerName
>
>
> 'Disconnect ALL mapped drives
> Set clDrives = WshNetwork.EnumNetworkDrives
> For i = 0 to clDrives.Count -1 Step 2
> WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True
> Next
>
> 'Map drives needed by all
> 'Note the first command uses the user name as a variable to map to a user
> share.
> Set WshNetwork = WScript.CreateObject("WScript.Network")
> 'On Error Resume Next
>
> WSHNetwork.MapNetworkDrive "P:", "\\server\dfs\Departments\public" ,True
> WSHNetwork.MapNetworkDrive "H:", "\\server\dfs\home\" & UserString ,True
>
> For Each GroupObj In UserObj.Groups
>
> Select Case UCase(UserObj.Name)
>
> Case "LV-ACA-AFFAIRS"
>
> WSHNetwork.MapNetworkDrive "t:", "\\server\dfs\Departments\lvpd"
> WSHNetwork.MapNetworkDrive "N:", "\\server\dfs\Departments\acad"
> WSHNetwork.MapNetworkDrive "M:", "\\server\dfs\Departments\faculty"
> WSHNetwork.AddWindowsPrinterConnection "\\server\LV-AdminHall"
>
> Case "LV-ADMISION"
>
> WSHNetwork.MapNetworkDrive "N:", "\\server\dfs\Departments\admission"
> WSHNetwork.MapNetworkDrive "L:", "\\server\dfs\Departments\awp"
> WSHNetwork.AddWindowsPrinterConnection "\\server\LV-AdminHall"
>
> End Select
> Next
>
>
>
>
>
> 'Clean Up Memory We Used
> set UserObj = Nothing
> set GroupObj = Nothing
> set WSHNetwork = Nothing
> set DomainString = Nothing
> set WSHSHell = Nothing
> Set WSHPrinters = Nothing
>
>
> 'Quit the Script
> wscript.quit
>
> "Richard Mueller [MVP]" wrote:
>
Quote:

>>
>> "PSU" <PSU@newsgroup> wrote in message
>> news:8A0B6EAD-1FA8-4011-9B84-C0446084C113@newsgroup
Quote:

>> >I have been using, windows 2003, the following command to map group
>> >users
>> >to
>> > their respective departmental drives.
>> >
>> > 'Grab the user name
>> > UserString = WSHNetwork.UserName
>> > 'Bind to the user object to get user name and check for group
>> > memberships
>> > later
>> > Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)
>> >
>> > For Each GroupObj In UserObj.Groups
>> >
>> > Select Case UCase(UserObj.Name)
>> >
>> > Now, this script stop working under windows 2008 environment.
>> > Is there a solution or a recommendation to make it work in windows 2008
>> > active directory environment?
>> >
>>
>> We are not seeing enough of your script, but nothing has changed in
>> Windows
>> Server 2008 AD that accounts for your experience. Does the script work
>> when
>> you run it after logon? Is there an error message when you run it?
>>
>> --
>> Richard Mueller
>> MVP Directory Services
>> Hilltop Lab - http://www.rlmueller.net
>> --
>>
>>
>>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Virtualise Windows 2008 Server Active Directory Virtual Server
Windows Live Messenger in Active Directory Computer Live Messenger
Windows Server 2003 Ent Edition Active Directory .NET General
Windows Vista Bitlocker Active Directory Schema Vista installation & setup


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46