Posted On March 31, 2019

Another Logon Script Example from 2008

kimconnect 0 comments
blog.KimConnect.com >> Codes >> Another Logon Script Example from 2008
Method 1 - Mixed Environment:
1. Edit the following script as appropriate
2. Then, save such script onto %SystemRoot%\sysvol\sysvol\<domain DNS name>\scripts
3. Assign the logon script to a user or group

Method 2 - Native Mode:
1. Create a new OU and move all users into that OU
2. Link a group policy to that OU
- Right-click the OU, Select Properties
- Under Group Policies tab, Click New or Edit to activate Group Policy Object Editor
- Navigate: User Configurations, Windows Settings, Scripts (Logon/logoff). Right-click Logon
- Click "show files" to open the folder that supposed to contain the scripts
- Copy the script file(s) into that folder so that those scripts will be replicated to other domain controllers
- Go back to Group Policy Object Editor and click Add to select the new script

Set wshNetwork = CreateObject("WScript.Network")
wshNetwork.MapNetworkDrive "h:",
"\\ACME_MAIN1\Users\" & wshNetwork.UserName

Set ADSysInfo = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" &
ADSysInfo.UserName)
strGroups = LCase(Join(CurrentUser.MemberOf))

wshNetwork.MapNetworkDrive "g:",
"\\ACME_MAIN1\Engineering\"
wshNetwork.MapNetworkDrive "g:",
"\\ACME_MAIN1\Engineering\"
wshNetwork.MapNetworkDrive "g:",
"\\ACME_MAIN1\Engineering\"

wshNetwork.AddWindowsPrinterConnection
"\\ACME_MAIN1\EngLaser"
wshNetwork.AddWindowsPrinterConnection
"\\ACME_MAIN1\Plotter"
wshNetWork.SetDefaultPrinter
"\\ACME_MAIN1\EngLaser"


---------------------------------------------------------------------------------------------------------------------------------------
Const ENGINEERING_GROUP = "cn=engineering"
Const FINANCE_GROUP = "cn=finance"
Const HUMAN_RESOURCES_GROUP = "cn=human resources"

Set wshNetwork = CreateObject("WScript.Network")
wshNetwork.MapNetworkDrive "h:",
"\\ACME_MAIN1\Users\" & wshNetwork.UserName

Set ADSysInfo = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" &
ADSysInfo.UserName)
strGroups = LCase(Join(CurrentUser.MemberOf))

If InStr(strGroups, ENGINEERING_GROUP) Then

wshNetwork.MapNetworkDrive "g:",
"\\FileServer\Engineering\"
wshNetwork.AddWindowsPrinterConnection
"\\PrintServer\EngLaser"
wshNetwork.AddWindowsPrinterConnection
"\\PrintServer\Plotter"
wshNetWork.SetDefaultPrinter
"\\PrintServer\EngLaser"

ElseIf InStr(strGroups, FINANCE_GROUP) Then

wshNetwork.MapNetworkDrive "g:",
"\\FileServer\Finance\"
wshNetwork.AddWindowsPrinterConnection
"\\PrintServer\FinLaser"
wshNetWork.SetDefaultPrinter
"\\PrintServer\FinLaser"

ElseIf InStr(strGroups, HUMAN_RESOURCES_GROUP) Then

wshNetwork.MapNetworkDrive "g:",
"\\FileServer\Human Resources\"
wshNetwork.AddWindowsPrinterConnection
"\\PrintServer\HrLaser"
wshNetWork.SetDefaultPrinter
"\\PrintServer\HrLaser"

End If
------------------------------------------------------
Implemented Logon Scripts:

---------------- logon.bat -----
echo off
cls
net use * /d /yes

net use i: "\\Acme-main1\ftp1" /y
net use g: "\\Acme-main1\users" /y
net use f: "\\Acme-main1\data" /y

\\Acme-MAIN1\Clients\Setup\setup.exe /s "Acme-MAIN1"

start \\Acme-main1\netlogon\printers.vbs
------------------------------------- -------------

-------------------- Printers.vbs ---------------------
on error resume next

Set objNetwork = CreateObject("WScript.Network")

objNetwork.AddWindowsPrinterConnection "\\Acme-MAIN1\HP LaserJet 8000 Series PCL"
objNetwork.AddWindowsPrinterConnection "\\Acme-MAIN1\HP Color LaserJet 3700 PCL 6"
objNetwork.AddWindowsPrinterConnection "\\Acme-MAIN1\HP LaserJet 4350 PCL 6"

Wscript.Quit

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

Excel Visual Basic For Application (VBA): Determine IP List

Set objExcel = CreateObject("Excel.Application") objExcel.Visible = True intRow = 2 Set Fso = CreateObject("Scripting.FileSystemObject") Set…

PowerShell: Deleting a Single File Safely

# Name your file$item="\\FILESHERVER007\someweird folder names with long paths\ fmmkklghhbb-yj-yuyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy p-hphlfiles\whatup.exe - Shortcut.lnk" #item could…

PowerShell: Copying File Share Permissions from Source to Destination

# Copy-SMB-Share-Permissions.ps1 # Set some SMB Share variables $sourceSmbPath="\\FILESERVER002\Home" $destinationSmbPath="\\FILESERVER002-n\Home" $dateStamp = Get-Date -Format "yyyy-MM-dd-hhmmss"…