Jump to content

login script


lingk
 Share

Recommended Posts

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 off

net 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\Programs

net use S: \\*servername*\Network_Share\Share

net use Z: \\*servername*\Network_Share

net use U: \\*servername*\%USERNAME%

net use X: \\*servername*\network_data

Link to comment
Share on other sites


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 Next

Dim oNet, sUser, sDept

Dim GroupList

Set fso = CreateObject("Scripting.FileSystemObject")

Set WshShell = CreateObject("WScript.Shell")

Set WshNetwork = WScript.CreateObject("WScript.Network")

Set oNet = CreateObject("Wscript.Network")

sUser =oNet.UserName

rem UPDATE MCAFEE ANTIVIRUS WITH NEW VER

Dim oShell

Set oShell = WScript.CreateObject ("WSCript.shell")

oShell.run "\\Server01\Mcafee\sdatnew.exe /s"

Set oShell = Nothing

oNet.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

Next

End If

Sub GetGroupInfo

Set UserObj = GetObject("WinNT://" & wshNetwork.UserDomain & "/" & WshNetwork.UserName)

Set Groups = UserObj.groups

For Each Group In Groups

GroupCount = GroupCount + 1

Next

ReDim GroupList(GroupCount -1)

i = 0

For Each Group In Groups

GroupList(i) = Group.Name

i = i + 1

Next

End Sub

Create another file name "Grouplist.csv"

Finance,L:,\\Server01\Finance

Engineering,L:,\\Server01\Engineering

Technical Office,L:,\\Server01\Technical Office

Front Office,L:,\\Server01\Front Office

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 Policy

so 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 Policy

Thanks for all the help!

Edited by lingk
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 Explicit

Dim objWMIService, objItem
Dim colIPItems
Dim i
Dim blnOnCampus : blnOnCampus=False
Dim 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 away
For 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 If
Next

if not blnOnCampus then WScript.Quit(1234)

Const ForReading=1
Const ForWriting=2

Dim objNetwork, objDrive, objSysInfo
Dim objUser, objGroup, objDNS, objFSO, objFile
Dim intDrive, intNetLetter
Dim strUserPath, strGroupPath, strGroupName
Dim strCaterproDrive, strCaterproPath, strCaterproDriveDefault
Dim strCheftecDrive, strCheftecPath
Dim strCorporateDrive, strCorporatePath
Dim strUserNetfileDrive, strUserNetfilePath
Dim strText, strAllText, strGroup
Dim 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 run
strCaterproDrive="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 filespace
strCorporateDrive="Z:"
strCorporatePath="\\fileserver.mysubdoamin.mydomain.com\deptname\private"

'Sets variable for users personal filespace
strUserNetfileDrive="N:"

'On Error Resume Next

Set objSysInfo = CreateObject("ADSystemInfo")
Set objNetwork = CreateObject("Wscript.Network")
Set objDrive = objNetwork.EnumNetworkDrives

'Sets variable with path to users personal filespace using the logged in username
strUserNetfilePath="\\myserver.mydomain.com\" & objNetwork.UserName

'bind to local directory and get AD info on loggied in user
strUserPath = "LDAP://" & objSysInfo.UserName
Set 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 membership

For 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 Select
Next

objNetwork.MapNetworkDrive strUserNetfileDrive, strUserNetfilePath

WScript.Quit(0)

Link to comment
Share on other sites

  • 3 weeks later...

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.

Link to comment
Share on other sites

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", True
Set 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 ports
for each instPrinter in colInstalledPrinters
if (instr(instPrinter.Name, "Adobe")=0) and (instr(instPrinter.Name, "Microsoft Office")=0) then
instPrinter.Delete_
end if
next

set colInstalledPrinters = objWMIService.ExecQuery ("Select * from Win32_Printer")

For Each instPrinter in colInstalledPrinters
objDictionary.Add instPrinter.PortName, instPrinter.PortName
Next

Set colPorts = objWMIService.ExecQuery ("Select * from Win32_TCPIPPrinterPort")
For Each objPort in colPorts
If objDictionary.Exists(objPort.Name) Then
Else
ObjPort.Delete_
End If
Next
'end delete printers and ports



'Laserjet 4000
'Installs Printer Driver, one already in the windows driver subset
objDriver.Name = "HP LaserJet 4000 Series PS"
objDriver.SupportedPlatform = "Windows NT x86"
objDriver.Version = "3"
intResult = objDriver.AddPrinterDriver(objDriver)

'Installs Printer Port
objNewPort.Name = "cmc-109q-pr.mydomain.com"
objNewPort.Protocol = 1
objNewPort.HostAddress = "cmc-109q-pr.mydomain.com"
objNewPort.PortNumber = 9100
objNewPort.SNMPEnabled = True
objNewPort.Put_

'Install Printer
objPrinter.DriverName = "HP LaserJet 4000 Series PS"
objPrinter.PortName = "cmc-109q-pr.mydomain.com"
objPrinter.DeviceID = "LJ4000"
objPrinter.Location = ""
objPrinter.Network = True
objPrinter.Put_

'Laserjet 4200
'Installs Printer Driver, one whose driver needs to be added, not part of windows
objDriver.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 Port
objNewPort.Name = "lj4200.mydomain.com"
objNewPort.Protocol = 1
objNewPort.HostAddress = "lj4200.mydomain.com"
objNewPort.PortNumber = 9100
objNewPort.SNMPEnabled = True
objNewPort.Put_

'Install Printer
objPrinter.DriverName = "HP LaserJet 4200 PS"
objPrinter.PortName = "lj4200.mydomain.com"
objPrinter.DeviceID = "LJ4200"
objPrinter.Location = ""
objPrinter.Network = True
objPrinter.Put_

'Laserjet 4250
'Installs Printer Driver
objDriver.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 Port
objNewPort.Name = "4250tn.mydoamin.com"
objNewPort.Protocol = 1
objNewPort.HostAddress = "4250tn.mydomain.com"
objNewPort.PortNumber = 9100
objNewPort.SNMPEnabled = True
objNewPort.Put_

'Install Printer
objPrinter.DriverName = "HP LaserJet 4250 PS"
objPrinter.PortName = "4250tn.mydomain.com"
objPrinter.DeviceID = "LJ4250"
objPrinter.Location = ""
objPrinter.Network = True
objPrinter.Put_

'Set LJ4250 as default
Set colInstalledPrinters = objWMIService.ExecQuery ("Select * from Win32_Printer Where Name = 'LJ4250'")

For Each objPrinter in colInstalledPrinters
objPrinter.SetDefaultPrinter()
Next

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.


×
×
  • Create New...