Project 5.1

  • Upload
    trish

  • View
    23

  • Download
    0

Embed Size (px)

DESCRIPTION

Project 5.1

Citation preview

'Tell the script that each variable used in the script is going to be 'used specifically before it is actually used.Option Explicit'if error occurs, go to to next lineOn Error Resume Next'defines a variableDim ObjShellDim OSversionDim RegOSversionDim ComputerDim NetworkDim iDim EventFileDim FSODim FileDim NamespaceDim WMIqueryDim ObjWMIqueryDim ObjWMIserviceDim MultiItemsDim IndItemDim objDomainDim objOUDim oOUnameDim oOUDim OUDim oClassDim domainDim providerDim QueryDim ConnectionDim CommandDim RecordSetDim OS1, OS2, OS3Dim num1, num2Dim fServerDim homeDim wshNetDim ADSysInfoDim CurrentUserDim strGroupsDim GroupMemberDim a,b,c,dDim ShellDim WMIServiceDim colItemsDim objItemDim strStatusSetting the OS version to a numberOS1=2.1OS2=2.1OS3=3.0'Counteri = 0'Sets file path for file to be savedEventFile = "C:\FSO\fso.txt"'ConstantConst ForWriting = 2Const School = "cn=schoolgroup"Const Work = "cn=workgroup"Const Recreation "cn=recreationgroup"'making the variable equal to a registry keyRegOSversion = "HKLM\Software\Microsoft\Windows\CurrentVersion "'"." means this computer onlyComputer = "."'query Namespace for anything that is contained on the local computer from the'win32_windowsproductactivation namespace.Namespace = "\root\cimv2"WMIquery = "Select * from Win32_WindowsProductActivation"'automation objectSet objShell = CreateObject("WScript.Shell")Set objFileSystem = CreateObject("Scripting.FileSystemObject")Set FSO = CreateObject(Scripting.FileSystemObject")Set File = FSO.OpenTextFile(LogFile, ForWriting)'using GeObject command and ExecQuery to obtain all information pertaining to'Windows product activationSet ObjWMIquery = GetObject("wingmgmts:\\" & Computer & NamespaceSet MultiItems = ObjWMIservice.ExecQuery(WMIquery)'recod current status on fileFile.WriteLine "Beginning the process at " & NowFile.WriteLine "Working on the process at " & NowFile.WriteLine "Logging completed at " & Now'stop writing to the programFile.Close'Declaring the variable Network as an ArrayNetwork = Array("s1", "s2", "s3")'provider is windows NTprovider = "WinNT://"'creating a ou in students and the students ou is in class ou.OU = "ou=students, ou=class,"'the domain is trirose.edudomain = "dc=trirose,dc=edu"'this is the type of object I am creating - an OU, aka Organizational UnitoClass = "organizationalUnit"oOU = "ou="oOUname = "myOU"'using IADsContainer Create to create an OUSet objDomain = GetObject(provider & OU & Domain)Set ObjOU = objDomain.Create(oClass, oOU & oOUname)objOU.SetInfo'display confirmation that an ou was created and the name of that ouWScript.Echo("OU " & oOUname & " was created")'Loop that counts each computer in a network.For Each Computer In Network'outputs the computer name on the screenWScript.Echo(Network(1))'Counter function that adds 0+1 for each computer in the networki = i+1'RepeatNext'As long as the resgistry key is available, a version number will be acquiredFor Each OSversion In RegOSversion'OSversion will be equal to RegOSversionOSversion = objShell.RegRead(RegOSversion)'output the information contained in the registry keyWScript.Echo "The current version of the Operating System is " & OSversion'tell the program to output error if the registry key is not foundIf OSversion > 0 ThenWScript.Echo "Error"'repeatNext'loop that displays information for each individual object (IndItems) within in the multiple objects (MultiItems) location as defined by the WMI query commandFor Each IndItem in MultiItemsWScript.Echo "ActivationRequired: " & IndItem.ActivationRequiredWScript.Echo "IsNotificationOn: " & IndItem.IsNotificationOnWScript.Echo "ProductID: " & IndItem.ProductIdWScript.Echo "RemainingEvaluationPeriod: " & _IndItem.RemainingEvaluationPeriodWsCript.Echo "RemainingGracePeriod: " & IndItem.RemainingGracePeriodWsCript.Echo "ServerName: " & IndItem.ServerNameNext'the domain and scopeQuery = ";;name;subtree"'Creates a connection objectSet Connection = CreateObject("ADODB.Connection")'Command object that shuttles the query to active directorySet Command = CreateObject("ADODB.Command")'open the connectionConnection.Open "Provider=ADsDSOObject;"'use Connection as the active ConnectionCommand.ActiveConnection = Connection'assign the variable query as equal to CommandTextCommand.CommandText = Query'Execute the commandSet RecordSet = Command.Execute'a loop that echo's the results until you reach the end of the queryWhile Not RecordeSet.EOFWScript.Echo RecordSet.Fields("name")RecordSet.MoveNextWend'close the connectionConnection.Close'provider is windows NTprovider = "WinNT://"'the domain is trirose.edudomain = "dc=trirose,dc=edu"'the OU variable is set to workstationOU = "ou=workstations,"'the queryQuery = "Select Name From " & Provider _& OU & Domain & "where objectClass='computer'"'Creates a connection objectSet Connection = CreateObject("ADODB.Connection")'Command object that shuttles the query to active directorySet Command = CreateObject("ADODB.Command")'open the connectionConnection.Open "Provider=ADsDSOObject;"'use Connection as the active ConnectionCommand.ActiveConnection = Connection'assign the variable query as equal to CommandTextCommand.CommandText = Query'Execute the commandSet RecordSet = Command.Execute'a loop that echo's the results until you reach the end of the queryWhile Not RecordeSet.EOFWScript.Echo RecordSet.Fields("name")RecordSet.MoveNextWend'close the connectionConnection.Close'compares the os version of workstation 1 and 2num1 = OS1num2 = OS2compare'compares the os version of workstation 1 and 3num1 = OS1num2 = OS3compare'compares the os version of workstation 2 and 3num1 = OS2num2 = OS3compare'subroutine that states the compared OS versions are either the same or not the 'sameSub compareIf num1 = num2 ThenWScript.Echo (num1 & " and " & num2 & " are the same _ operating system version")ElseWScript.Echo (num1 & " and " & num2 & " are not the same _operating system version")End IfEnd Sub'name of the serverfServer = "\\trirose"'the home directoryhome = "\\trirose\users"'allows for connecting and siconnecting from network shares and network printersSet wshNet = CreateObjeect("WScript.Network")'make the hook to prepare for obtaining the usernameSet ADSysInfo = CreateObject("ADSystemInfo")'obtiains usernameSet CurrentUser = GetObject("WinNT:\\" _& ASDysInfo.UserName)'obtain membershipStrGroups = LCase(Join(CurrentUser..MemberOf))wshNet.MapNetworkDrive "r:", fServer & "\Users\" _& wshNet.UserNameWscript.Echo(wshNet.UserName & " " & strgroups)GroupMember = True'select a group membership and then jump to the subroutine for that groupSelect Case GroupMemeberCase a = InStr(strGroups, School)SchoolSubCase b = InStr(StrGroups, Work)WorkSubCase c = Instr(StrGroups, Recreation)RecreationSubEnd Select'subroutines that displays that the user made it into a group membership, makes 'a connection to the printer of that particular group, and also sets the default 'printer it as wellSub SchoolSubWScript.Echo("made it to School")wshNet.MapNetworkDrove "s:", "\\trirose\School\"wshNet.AddWindowsPrinterConnection _"\\trirose\SchoolPrinter"wshNet.SetDefaultPrinter "\\trirose\SchoolPrinter"End SubSub WorkSubWScript.Echo("made it to work")wshNet.MapNetworkDrove "w:", "\\trirose\Work\"wshNet.AddWindowsPrinterConnection _"\\trirose\WorkPrinter"wshNet.SetDefaultPrinter "\\trirose\WorkPrinter"End SubSub RecreationSubWScript.Echo("made it to recreation")wshNet.MapNetworkDrove "r:", "\\trirose\Recreation\"wshNet.AddWindowsPrinterConnection _"\\trirose\RecreationPrinter"wshNet.SetDefaultPrinter "\\trirose\RecreationPrinter"End Sub'display when the script startsWscript.Echo("beginning " & Now)'create an instance of the AshShell clasSet Shell = CreateObject("WScript.Shell")'use the reg.exe save command, specify the registry key to save and the file to 'save it intoShell.Exec "%comspec% /k reg.exe export hklm C:\HKLM.REG"'display when the script completedWScript.Echo("Completed " & Now)Computer = "."Namespace = "\trirose\Printers"Query = "Select * from WinNT_Printer"Set WMIService = GetObject("WinNT:\\" _& Computer & NamespaceSet colItems = WMIService.ExecQuery(Query)For Each objItem in colItemsWScript.Echo "Name: " & objItem.NameWScript.Echo "Location: " & objItem.LocationWScript.Echo "Printer Status: " & strStatusWScript.Echo "Server Name: " & objItem.ServerNameWScript.Echo "Share Name: " & objItem.ShareNameWScript.EchoNextSub subEvalStatusSelect Case objItem.PrinterStatusCase 1strStatus = "Other"Case 2strStatus = "Unknown"Case 3strStatus = "Idle"Case 4strStatus = "Printing"Case 5strStatus = "Warmup"Case 6strStatus = "Stopped Printing"Case 7strStatus = "Offline"Case 8strStatus = "Out of Ink"Case 9strStatus = "Out of Paper"Case 10strStatus = "Error"End SelectEnd Sub