Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple groups, logon scripts

Status
Not open for further replies.

hende10

MIS
Joined
Aug 22, 2002
Messages
93
Location
US
I am having trouble mapping group shares to a user, when that user is a member of multiple groups. I want the script to map a group drive for each group the user is a member of, but it only maps one group drive, usually the primary group.

With the following code example, I should be able to map drives G, I, and K to different group shares at the same time if the user is in all these groups. However, only one of these drives are mapped at logon. I am using an old version of KIXtart, if that matters.

$group=Purchasing
if ingroup($group)
use g: /del
use g: "\\serv1\Purchasing$"
ENDIF

$group="Customer Correspondence"
if ingroup($group)
use i: /del
use i: "\\serv1\custcorr$"
ENDIF

$group="Human Resources"
if ingroup($group)
use k: /del
use k: "\\serv1\hr$"
ENDIF

Thanks!
 
Never used KIXtart, though ifmember.exe from the resource kit provides the same functionality.

ifmember Purchasing
if not errorlevel 1 goto xxx
net use g: \\serv1\Purchasing$


:xxx
ifmember "Customer Correspondence"
if not errorlevel 1 goto yyy
net use i: \\serv1\custcorr$

:yyy
ifmember Human Remains
if not errorlevel 1 goto zzz
net use k: \\serv1\hr$

-------------------------------

If it doesn't leak oil it must be empty!!
 
The way to go with current technology is to use vbscript and break the dependance on extra utilities.

This script will let you map drives, delete drives, connect printers and will also let you take action such as mapping a drive based on group membership.

editing the mapping statements is intuitive, just make sure you also edit the line: DomainString = "DomainName" and replace DomainName with your domain name.

Code:
'==========================================================================
'
' NAME: LogonScript.vbs
'
' AUTHOR:  Mark D. MacLachlan, The Spider's Parlor
' URL   : [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' DATE  : 4/10/2003
'
' COMMENT: Enumerates current users' group memberships in given domain.
'
'==========================================================================


ON ERROR RESUME NEXT

Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")

'Edit the next line with your domain name
DomainString = "DomainName"
UserString = WSHNetwork.UserName
'Bind to the user object to get user name and check for group memberships later
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)

'Synchronizes the time with Server our NTP Server
WSHShell.Run "NET TIME \\Server /set /y"

'Disconnect any drive mappings as needed.
WSHNetwork.RemoveNetworkDrive "F:"

'Give the PC time to do the disconnect, wait 300 milliseconds
wscript.sleep 300

'Map drives needed by all
WSHNetwork.MapNetworkDrive "U:", "\\server\users",True
WSHNetwork.MapNetworkDrive "X:", "\\server\executables",True

'Now check for group memberships and map appropriate drives
For Each GroupObj In UserObj.Groups
	Select Case GroupObj.Name
	'Check for group memberships and take needed action
	'In this example below, ADMIN and WORKERB are groups.
		Case "Admin"
			WSHNetwork.MapNetworkDrive "w:", "\\Server\Admin Stuff",True
		Case "WorkerB"
			WSHNetwork.MapNetworkDrive "w:", "\\Server\Shared Documents",True
	End Select
Next


'Install Printers

WSHNetwork.AddWindowsPrinterConnection "\\Server\HP5si"

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

'Quit the Script
wscript.quit

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
KixTart is fine and has much more functionality compared to the resource kit tools. I'm sure that you have already spent a lot of time developing your scripts. There is no reason to change the tool.

I would; however, strongly suggest that you upgrade Kixtart (of course this product is 100% free). You can upgrade at

You should be able to do this:

if ingroup(Purchasing)
use g: /del
use g: "\\serv1\Purchasing$"
ENDIF


if ingroup("Customer Correspondence")
use i: /del
use i: "\\serv1\custcorr$"
ENDIF


if ingroup("Human Resources")
use k: /del
use k: "\\serv1\hr$"
ENDIF

(Good kixtart quick ref)
Joseph L. Poandl
MCSE 2003

If your company is in need of experts to examine technical problems/solutions, please check out (Sales@njcomputernetworks.com)
 
Thanks for all the answers/suggestions. The fix was quite simple, I just had to upgrade KiXTart. The version we had was from 1996 - a bit dated, I would say.

Thanks again!
 
Yeah, I surprised it worked at all. Glad to see you got your problem fixed.

Joseph L. Poandl
MCSE 2003

If your company is in need of experts to examine technical problems/solutions, please check out (Sales@njcomputernetworks.com)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top