lingk Posted May 29, 2007 Posted May 29, 2007 I have a batch files that maps network drives for users using the net use command. I found that the script runs 3 times during login. I have checked and made sure that GP isn't reading 3 different files. any ideas why the batch file runs 3 times?@echo offnet use /delete p:net use /delete S:net use /delete Z:net use /delete U:net use /delete x:net use P: \\*servername*\Network_Share\Programsnet use S: \\*servername*\Network_Share\Sharenet use Z: \\*servername*\Network_Sharenet use U: \\*servername*\%USERNAME%net use X: \\*servername*\network_data
FAT64 Posted May 29, 2007 Posted May 29, 2007 No idea why it is running 3 times, but I was going to say that personally I use VBScript to map network drives and not a DOS batch file.
moinuddin_sh Posted June 4, 2007 Posted June 4, 2007 Create two files as explained below and copy these two files to the scripts folder under sysvol:create a file name "script.vbs" and copy the following in this file:On Error Resume NextDim oNet, sUser, sDeptDim GroupListSet fso = CreateObject("Scripting.FileSystemObject")Set WshShell = CreateObject("WScript.Shell") Set WshNetwork = WScript.CreateObject("WScript.Network") Set oNet = CreateObject("Wscript.Network")sUser =oNet.UserNamerem UPDATE MCAFEE ANTIVIRUS WITH NEW VERDim oShellSet oShell = WScript.CreateObject ("WSCript.shell")oShell.run "\\Server01\Mcafee\sdatnew.exe /s"Set oShell = NothingoNet.MapNetworkDrive "K:", "\\Server01\" & sUser oNet.MapNetworkDrive "M:", "\\Server01\" & "Everyone"GetGroupInfo()LogonPath = fso.GetParentFolderName(WScript.ScriptFullName)'**************************************Group Mappings Based on Grouplist.csv*********************************If fso.FileExists(logonpath&"\Grouplist.csv") Then Set grplist = Fso.OpenTextFile(logonpath&"\Grouplist.csv") ' make File into an Array aGroup = Split(grplist.Readall,vbcrlf) For I = 0 to UBound(GroupList) ' Check Every Group Membership the user is in (populated into Grouplist) grpname = Grouplist(i) For x = 0 to UBound(aGroup) ' Read the entire CSV to make sure all drives are mapped for each Group mapline = agroup(x) If InStr(LCase(mapline),LCase(grpname)) Then ' If you're in the group mapline = Mid(mapline,InStr(mapline,",")+1) ' Remove the GroupName from the line Drive = Left(mapline,InStr(mapline,",")-1) ' Extract Drive Letter Path = Mid(mapline,InStr(mapline,",")+1) ' Extract the path If (fso.DriveExists(drive) <> True) and (Drive<>"!!") Then ' If The Drive is not already mapped WshNetwork.MapNetworkDrive drive,path ' Map The Drive wscript.sleep 1000 End If If Drive = "!!" then WSHNetwork.AddWindowsPrinterConnection Path wscript.sleep 1000 end if End If Next NextEnd IfSub GetGroupInfoSet UserObj = GetObject("WinNT://" & wshNetwork.UserDomain & "/" & WshNetwork.UserName)Set Groups = UserObj.groupsFor Each Group In GroupsGroupCount = GroupCount + 1NextReDim GroupList(GroupCount -1)i = 0For Each Group In GroupsGroupList(i) = Group.Namei = i + 1NextEnd SubCreate another file name "Grouplist.csv"Finance,L:,\\Server01\FinanceEngineering,L:,\\Server01\EngineeringTechnical Office,L:,\\Server01\Technical OfficeFront Office,L:,\\Server01\Front Office
IcemanND Posted June 4, 2007 Posted June 4, 2007 run gpresult in a cmd window on a machine with this problem and check to make sure it is not pulling that startup script from mulitple GPO's.
DennisT Posted June 4, 2007 Posted June 4, 2007 or possibly that the logon script is defined 3x in the winning GPO.
lingk Posted June 5, 2007 Author Posted June 5, 2007 Thanks for the info i'll do some poking around and see what i come up with.moinuddin_sh, do you think you could put a more toned down ver of that script up. something a little more basic. as i was looking over your script i saw a lot of stuff that looked like i didn't need.
lingk Posted June 5, 2007 Author Posted June 5, 2007 (edited) Thanks for the info i'll do some poking around and see what i come up with.moinuddin_sh, do you think you could put a more toned down ver of that script up. something a little more basic. as i was looking over your script i saw a lot of stuff that looked like i didn't need.after I ran gpresult as IcemanND suggested I noticed it was pulling the Default Domain Policy 3 times under user settings Applied Group Policy Objects ----------------------------- Default Domain Policy Default Domain Policy IT Default Domain Policy Local Group Policyso I opened up the Group Policy Manager plug in i use for win2k3 and i noticed on some of the GPO's that the Default Domain Policy was linked. So i simply unlinked the Default Domain Policy from the GPO's and now the script only runs one time. I ran gpresult to double check things and now the Default Domain Policy is listed once user the user settings. Applied Group Policy Objects ----------------------------- Default Domain Policy IT Local Group PolicyThanks for all the help! Edited June 5, 2007 by lingk
IcemanND Posted June 5, 2007 Posted June 5, 2007 glad we could help out.if the script you have works for you then why change? Or is there something additional you wanted to do that moinuddin_sh is doing in his script?
lingk Posted June 5, 2007 Author Posted June 5, 2007 I don't need to change, just would like to see what a simple VB script for drive mapping looks like. also if i did want to add something later on it would be a little easer to do with a VB script then a batch file. well, depending on what i would want to do.
IcemanND Posted June 5, 2007 Posted June 5, 2007 Here is the login script I use which maps network drives according to a users AD Group memberships. I added some comments to it, if you have any questions let me know.Option ExplicitDim objWMIService, objItemDim colIPItemsDim iDim blnOnCampus : blnOnCampus=FalseDim strComputer : strComputer="."Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colIPItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=True")'Checks to verify that the machine is on the company network, since our DNS servers are not available remotely'the only way they would be listed is if the machine was in house, this eliminates the script trying to run on 'laptops that are awayFor Each objItem in colIPItems objDNS = objItem.DNSServerSearchOrder if not isNull(objDNS) and isArray(objDNS) then for i = lbound(objDNS,1) to ubound(objDNS,1) if objDNS(i)="192.168.100.100" or objDNS(i)="192.168.100.250" then blnOnCampus=True end if next End IfNextif not blnOnCampus then WScript.Quit(1234)Const ForReading=1Const ForWriting=2Dim objNetwork, objDrive, objSysInfoDim objUser, objGroup, objDNS, objFSO, objFileDim intDrive, intNetLetterDim strUserPath, strGroupPath, strGroupNameDim strCaterproDrive, strCaterproPath, strCaterproDriveDefaultDim strCheftecDrive, strCheftecPathDim strCorporateDrive, strCorporatePathDim strUserNetfileDrive, strUserNetfilePathDim strText, strAllText, strGroupDim blnFileUpdated : blnFileUpdated=False'Sets variable for a drive that contains a database which the drive letter must be set in an ini file on the 'local machine inorder for it to runstrCaterproDrive="Q:"strCaterproDriveDefault="Q:"strCaterproPath="\\myserver.mydomain.com\caterpro"'Sets variables for a drve that contains a database which only needs to be mapped no settings are otherise 'requied when the application is installed.strCheftecDrive="O:"strCheftecPath="\\myserver.mydomain.com\cheftec"'Sets variables for departmental corporate filespacestrCorporateDrive="Z:"strCorporatePath="\\fileserver.mysubdoamin.mydomain.com\deptname\private"'Sets variable for users personal filespacestrUserNetfileDrive="N:"'On Error Resume NextSet objSysInfo = CreateObject("ADSystemInfo")Set objNetwork = CreateObject("Wscript.Network")Set objDrive = objNetwork.EnumNetworkDrives'Sets variable with path to users personal filespace using the logged in usernamestrUserNetfilePath="\\myserver.mydomain.com\" & objNetwork.UserName'bind to local directory and get AD info on loggied in userstrUserPath = "LDAP://" & objSysInfo.UserNameSet objUser = GetObject(strUserPath)'Check for any currently mapped network drives in case they are already mapped but to a different drive letter'store the current drive letter so that it can be remapped the same, otherwise it will use the defaults set above.if objDrive.Count <>0 then for intDrive = 0 to (objDrive.Count -1) Step 2 if instr(1,objDrive.item(intDrive +1),"caterpro",1)>0 then strCaterproDrive=objDrive.item(intDrive) objNetwork.RemoveNetworkDrive strCaterproDrive end if if instr(1,objDrive.item(intDrive +1),"cheftec",1)>0 then strCheftecDrive=objDrive.item(intDrive) objNetwork.RemoveNetworkDrive strCheftecDrive end if if instr(1,objDrive.item(intDrive +1),"deptname",1)>0 then strCorporateDrive=objDrive.item(intDrive) objNetwork.RemoveNetworkDrive strCorporateDrive end if if instr(1,objDrive.item(intDrive +1),objNetwork.UserName,1)>0 then strUserNetfileDrive=objDrive.item(intDrive) objNetwork.RemoveNetworkDrive strUserNetfileDrive end if Next end if'Remap drives according to users AD group membershipFor Each strGroup in objUser.MemberOf strGroupPath = "LDAP://" & strGroup Set objGroup = GetObject(strGroupPath) strGroupName = objGroup.CN Select Case strGroupName Case "Caterpro users" objNetwork.MapNetworkDrive strCaterproDrive, strCaterproPath Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile("C:\caterpro\caterpro.ini", ForReading) Do Until objFile.AtEndOfStream strText = objFile.ReadLine if instr(1,strText,"CaterPro=",1)>0 then if instr(1,strText,"CaterPro=" & strCaterproDrive & "\")=0 then strText="CaterPro=" & strCaterproDrive & "\" blnFileUpdated=True end if end if strAllText=strAllText & strText & vbcrlf loop objFile.Close if blnFileUpdated then Set objFile = objFSO.OpenTextFile("C:\caterpro\caterpro.ini", ForWriting) objFile.WriteLine strAllText objFile.Close end if Case "Cheftec Users" objNetwork.MapNetworkDrive strCheftecDrive, strCheftecPath Case "Deptname - Dept Netfile Users" objNetwork.MapNetworkDrive strCorporateDrive, strCorporatePath End SelectNextobjNetwork.MapNetworkDrive strUserNetfileDrive, strUserNetfilePathWScript.Quit(0)
lingk Posted June 27, 2007 Author Posted June 27, 2007 I thought i would add my question in here seeing how i already have a post gong on.I am looking for a script that will check for what printers the user has installed, if the user doesn't have the printers it should have installed the scrip will add the pinter they should have installed and set the one that should be default depending on what user group they are in. as some of the users have different default printers.
IcemanND Posted June 27, 2007 Posted June 27, 2007 I've never tried looking to see what printer was installed, but here is a script I use to delete all installed printers and then install three printers and set one of them to the default. You could use the loop that deletes the all the printers but the adobe and microsoft virtual printers to look for the printer that should be installed.strComputer = "."Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")set objNewPort = objWMIService.get("Win32_TCPIPPrinterPort").SpawnInstance_Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", TrueSet objDriver = objWMIService.Get("Win32_PrinterDriver")set colInstalledPrinters = objWMIService.ExecQuery ("Select * from Win32_Printer")set objDictionary = CreateObject("Scripting.Dictionary")' Deletes all installed printers and added printer portsfor each instPrinter in colInstalledPrinters if (instr(instPrinter.Name, "Adobe")=0) and (instr(instPrinter.Name, "Microsoft Office")=0) then instPrinter.Delete_ end ifnextset colInstalledPrinters = objWMIService.ExecQuery ("Select * from Win32_Printer")For Each instPrinter in colInstalledPrinters objDictionary.Add instPrinter.PortName, instPrinter.PortNameNextSet colPorts = objWMIService.ExecQuery ("Select * from Win32_TCPIPPrinterPort")For Each objPort in colPorts If objDictionary.Exists(objPort.Name) Then Else ObjPort.Delete_ End IfNext'end delete printers and ports'Laserjet 4000'Installs Printer Driver, one already in the windows driver subsetobjDriver.Name = "HP LaserJet 4000 Series PS"objDriver.SupportedPlatform = "Windows NT x86"objDriver.Version = "3"intResult = objDriver.AddPrinterDriver(objDriver)'Installs Printer PortobjNewPort.Name = "cmc-109q-pr.mydomain.com"objNewPort.Protocol = 1objNewPort.HostAddress = "cmc-109q-pr.mydomain.com"objNewPort.PortNumber = 9100objNewPort.SNMPEnabled = TrueobjNewPort.Put_'Install PrinterobjPrinter.DriverName = "HP LaserJet 4000 Series PS"objPrinter.PortName = "cmc-109q-pr.mydomain.com"objPrinter.DeviceID = "LJ4000"objPrinter.Location = ""objPrinter.Network = TrueobjPrinter.Put_'Laserjet 4200'Installs Printer Driver, one whose driver needs to be added, not part of windowsobjDriver.Name = "HP LaserJet 4200 PS"objDriver.SupportedPlatform = "Windows NT x86"objDriver.Version = "3"objDriver.FilePath = "c:\\DRIVERS\\lj4200ps\\"objDriver.Infname = "c:\\DRIVERS\\lj4200ps\\hpc4200d.inf"intResult = objDriver.AddPrinterDriver(objDriver)'Installs Printer PortobjNewPort.Name = "lj4200.mydomain.com"objNewPort.Protocol = 1objNewPort.HostAddress = "lj4200.mydomain.com"objNewPort.PortNumber = 9100objNewPort.SNMPEnabled = TrueobjNewPort.Put_'Install PrinterobjPrinter.DriverName = "HP LaserJet 4200 PS"objPrinter.PortName = "lj4200.mydomain.com"objPrinter.DeviceID = "LJ4200"objPrinter.Location = ""objPrinter.Network = TrueobjPrinter.Put_'Laserjet 4250'Installs Printer DriverobjDriver.Name = "HP LaserJet 4250 PS"objDriver.SupportedPlatform = "Windows NT x86"objDriver.Version = "3"objDriver.FilePath = "c:\\DRIVERS\\lj4250ps\\"objDriver.Infname = "c:\\DRIVERS\\lj4250ps\\hpc4x50d.inf"intResult = objDriver.AddPrinterDriver(objDriver)'Installs Printer PortobjNewPort.Name = "4250tn.mydoamin.com"objNewPort.Protocol = 1objNewPort.HostAddress = "4250tn.mydomain.com"objNewPort.PortNumber = 9100objNewPort.SNMPEnabled = TrueobjNewPort.Put_'Install PrinterobjPrinter.DriverName = "HP LaserJet 4250 PS"objPrinter.PortName = "4250tn.mydomain.com"objPrinter.DeviceID = "LJ4250"objPrinter.Location = ""objPrinter.Network = TrueobjPrinter.Put_'Set LJ4250 as defaultSet colInstalledPrinters = objWMIService.ExecQuery ("Select * from Win32_Printer Where Name = 'LJ4250'")For Each objPrinter in colInstalledPrinters objPrinter.SetDefaultPrinter()Next
fizban2 Posted June 27, 2007 Posted June 27, 2007 An alternative if you are at Server 2003 R2http://www.windowsnetworking.com/articles_...er-2003-R2.htmlhttp://www.windowsnetworking.com/articles_...Windows-R2.html
lingk Posted June 27, 2007 Author Posted June 27, 2007 alright, thanks for the replys I'll see what i can do if i need any more help I'll let ya know
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