Примерный сценарий входа в систему (с записью информации в лог)

Option Explicit
Dim fServer
Dim home
Dim wshNet
Dim ADSysInfo
Dim CurrentUser
Dim strGroups
Dim GroupMember
Dim a, b, c, d
Dim objFSO				
Dim objFile			
Dim message			
Dim objData1		
Dim objData2		
Dim LogFolder
Dim LogFile

Const HR = "cn=hrgroup"
Const MARKETING = "cn=marketinggroup"
Const SALES = "cn=salesgroup"
Const PRODUCTION = "cn=productiongroup"
Const ForWriting = 2
Const ForAppending = 8
LogFolder = "C:\fso"
LogFile = "C:\fso\logFile.txt"
message="Processing Logon Script " & Now



fServer = "\\london"
home = "\\london\users"
Set wshNet = CreateObject("WScript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set ADSysInfo = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)
strGroups = LCase(Join(CurrentUser.MemberOf))
objData1 = ADSysInfo.UserName
objData2 = strGroups
wshNet.MapNetworkDrive "h:", fServer & "\Users\" & wshNet.UserName
WScript.Echo(wshNet.Username & " " & strgroups)

Select Case GroupMember
	case a = InStr(strGroups, HR)
    HRsub
	case b = InStr(strGroups, SALES)
	SalesSub
	case c = InStr(strGroups, MARKETING)
    MarketingSub
    case d = InStr (strGroups, PRODUCTION)
    ProductionSub
End Select

Sub HRsub
WScript.Echo("made it to HR")
wshNet.MapNetworkDrive "g:","\\london\Hr\"
    wshNet.AddWindowsPrinterConnection "\\london\HrPrinter"
    wshNet.SetDefaultPrinter "\\london\HrPrinter"
    Loggingsub
End Sub

Sub SalesSub
WScript.Echo("made it to sales")
    wshNet.MapNetworkDrive "s:", "\\london\Sales"
    wshNet.AddWindowsPrinterConnection "\\london\SalesPrinter"
    wshNet.SetDefaultPrinter "\\london\SalesPrinter"
    Loggingsub
End Sub 

Sub MarketingSub
WScript.Echo("made it to marketing")
	wshNet.MapNetworkDrive "m:","\\london\Marketing\"
    wshNet.AddWindowsPrinterConnection "\\london\MarketingPrinter"
    wshNet.SetDefaultPrinter "\\london\MarketingPrinter"
    Loggingsub
End Sub 

Sub ProductionSub
WScript.Echo("made it to production")
	wshNet.MapNetworkDrive "p:","\\london\Production\"
	wshNet.AddWindowsPrinterConnection "\\london\ProductionPrinter"
	wshNet.SetDefaultPrinter "\\london\ProductionPrinter"
	Loggingsub
End Sub

Sub Loggingsub
If objFSO.FolderExists(LogFolder) Then
	If objFSO.FileExists(LogFile) Then
		Set objFile = objFSO.OpenTextFile(LogFile, ForAppending)
		objFile.WriteBlankLines(1)
		objFile.Writeline message
		objFile.Writeline  objData1
	    objFile.Writeline objData2
	    objFile.Close
	Else
		Set objFile = objFSO.CreateTextFile(LogFile)
		objFile.Close
		Set objFile = objFSO.OpenTextFile(LogFile, ForWriting)  
		objfile.writeline message
		objFile.Writeline  objData1
	    objFile.Writeline objData2
	    objFile.Close
	End If
Else
	Set objFolder = objFSO.CreateFolder(LogFolder)
	Set objFile = objFSO.CreateTextFile(LogFile)
		objFile.Close
		Set objFile = objFSO.OpenTextFile(LogFile, ForWriting)  
		objfile.writeline message
		objFile.Writeline  objData1
	    objFile.Writeline objData2
	    objFile.Close
End If
End Sub

 

Интересное на сайте: 
0
Голосов пока нет

Оставить комментарий