You are on page 1of 7

'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 line
On Error Resume Next
'defines a variable
Dim ObjShell
Dim OSversion
Dim RegOSversion
Dim Computer
Dim Network
Dim i
Dim EventFile
Dim FSO
Dim File
Dim Namespace
Dim WMIquery
Dim ObjWMIquery
Dim ObjWMIservice
Dim MultiItems
Dim IndItem
Dim objDomain
Dim objOU
Dim oOUname
Dim oOU
Dim OU
Dim oClass
Dim domain
Dim provider
Dim Query
Dim Connection
Dim Command
Dim RecordSet
Dim OS1, OS2, OS3
Dim num1, num2
Dim fServer
Dim home
Dim wshNet
Dim ADSysInfo
Dim CurrentUser
Dim strGroups
Dim GroupMember
Dim a,b,c,d
Dim Shell
Dim WMIService
Dim colItems
Dim objItem
Dim strStatus
Setting the OS version to a number
OS1=2.1
OS2=2.1
OS3=3.0
'Counter
i = 0

'Sets file path for file to be saved


EventFile = "C:\FSO\fso.txt"
'Constant
Const ForWriting = 2
Const School = "cn=schoolgroup"
Const Work = "cn=workgroup"
Const Recreation "cn=recreationgroup"
'making the variable equal to a registry key
RegOSversion = "HKLM\Software\Microsoft\Windows\CurrentVersion "
'"." means this computer only
Computer = "."
'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 object
Set 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 activation
Set ObjWMIquery = GetObject("wingmgmts:\\" & Computer & Namespace
Set MultiItems = ObjWMIservice.ExecQuery(WMIquery)
'recod current
File.WriteLine
File.WriteLine
File.WriteLine

status on file
"Beginning the process at " & Now
"Working on the process at " & Now
"Logging completed at " & Now

'stop writing to the program


File.Close
'Declaring the variable Network as an Array
Network = Array("s1", "s2", "s3")
'provider is windows NT
provider = "WinNT://"
'creating a ou in students and the students ou is in class ou.
OU = "ou=students, ou=class,"
'the domain is trirose.edu
domain = "dc=trirose,dc=edu"
'this is the type of object I am creating - an OU, aka Organizational Unit
oClass = "organizationalUnit"
oOU = "ou="
oOUname = "myOU"
'using IADsContainer Create to create an OU
Set 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 ou
WScript.Echo("OU " & oOUname & " was created")
'Loop that counts each computer in a network.
For Each Computer In Network
'outputs the computer name on the screen
WScript.Echo(Network(1))
'Counter function that adds 0+1 for each computer in the network
i = i+1
'Repeat
Next
'As long as the resgistry key is available, a version number will be acquired
For Each OSversion In RegOSversion
'OSversion will be equal to RegOSversion
OSversion = objShell.RegRead(RegOSversion)
'output the information contained in the registry key
WScript.Echo "The current version of the Operating System is " & OSversi
on
'tell the program to output error if the registry key is not found
If OSversion > 0 Then
WScript.Echo "Error"
'repeat
Next
'loop that displays information for each individual object (IndItems) within in
the multiple objects (MultiItems) location as defined by the WMI query command
For Each IndItem in MultiItems
WScript.Echo "ActivationRequired: " & IndItem.ActivationRequired
WScript.Echo "IsNotificationOn: " & IndItem.IsNotificationOn
WScript.Echo "ProductID: " & IndItem.ProductId
WScript.Echo "RemainingEvaluationPeriod: " & _
IndItem.RemainingEvaluationPeriod
WsCript.Echo "RemainingGracePeriod: " & IndItem.RemainingGracePeriod
WsCript.Echo "ServerName: " & IndItem.ServerName
Next
'the domain and scope
Query = "<WinNT://dc=trirose,dc=com>;;name;subtree"
'Creates a connection object
Set Connection = CreateObject("ADODB.Connection")
'Command object that shuttles the query to active directory
Set Command = CreateObject("ADODB.Command")
'open the connection
Connection.Open "Provider=ADsDSOObject;"
'use Connection as the active Connection
Command.ActiveConnection = Connection

'assign the variable query as equal to CommandText


Command.CommandText = Query
'Execute the command
Set RecordSet = Command.Execute
'a loop that echo's the results until you reach the end of the query
While Not RecordeSet.EOF
WScript.Echo RecordSet.Fields("name")
RecordSet.MoveNext
Wend
'close the connection
Connection.Close
'provider is windows NT
provider = "WinNT://"
'the domain is trirose.edu
domain = "dc=trirose,dc=edu"
'the OU variable is set to workstation
OU = "ou=workstations,"
'the query
Query = "Select Name From " & Provider _
& OU & Domain & "where objectClass='computer'"
'Creates a connection object
Set Connection = CreateObject("ADODB.Connection")
'Command object that shuttles the query to active directory
Set Command = CreateObject("ADODB.Command")
'open the connection
Connection.Open "Provider=ADsDSOObject;"
'use Connection as the active Connection
Command.ActiveConnection = Connection
'assign the variable query as equal to CommandText
Command.CommandText = Query
'Execute the command
Set RecordSet = Command.Execute
'a loop that echo's the results until you reach the end of the query
While Not RecordeSet.EOF
WScript.Echo RecordSet.Fields("name")
RecordSet.MoveNext
Wend
'close the connection
Connection.Close
'compares the os version of workstation 1 and 2
num1 = OS1
num2 = OS2
compare

'compares the os version of workstation 1 and 3


num1 = OS1
num2 = OS3
compare
'compares the os version of workstation 2 and 3
num1 = OS2
num2 = OS3
compare
'subroutine that states the compared OS versions are either the same or not the
'same
Sub compare
If num1 = num2 Then
WScript.Echo (num1 & " and " & num2 & " are the same _
operating system version")
Else
WScript.Echo (num1 & " and " & num2 & " are not the same _
operating system version")
End If
End Sub
'name of the server
fServer = "\\trirose"
'the home directory
home = "\\trirose\users"
'allows for connecting and siconnecting from network shares and network printers
Set wshNet = CreateObjeect("WScript.Network")
'make the hook to prepare for obtaining the username
Set ADSysInfo = CreateObject("ADSystemInfo")
'obtiains username
Set CurrentUser = GetObject("WinNT:\\" _
& ASDysInfo.UserName)
'obtain membership
StrGroups = LCase(Join(CurrentUser..MemberOf))
wshNet.MapNetworkDrive "r:", fServer & "\Users\" _
& wshNet.UserName
Wscript.Echo(wshNet.UserName & " " & strgroups)
GroupMember = True
'select a group membership and then jump to the subroutine for that group
Select Case GroupMemeber
Case a = InStr(strGroups, School)
SchoolSub
Case b = InStr(StrGroups, Work)
WorkSub
Case c = Instr(StrGroups, Recreation)
RecreationSub
End 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 well
Sub SchoolSub

WScript.Echo("made it to School")
wshNet.MapNetworkDrove "s:", "\\trirose\School\"
wshNet.AddWindowsPrinterConnection _
"\\trirose\SchoolPrinter"
wshNet.SetDefaultPrinter "\\trirose\SchoolPrinter"
End Sub
Sub WorkSub
WScript.Echo("made it to work")
wshNet.MapNetworkDrove "w:", "\\trirose\Work\"
wshNet.AddWindowsPrinterConnection _
"\\trirose\WorkPrinter"
wshNet.SetDefaultPrinter "\\trirose\WorkPrinter"
End Sub
Sub RecreationSub
WScript.Echo("made it to recreation")
wshNet.MapNetworkDrove "r:", "\\trirose\Recreation\"
wshNet.AddWindowsPrinterConnection _
"\\trirose\RecreationPrinter"
wshNet.SetDefaultPrinter "\\trirose\RecreationPrinter"
End Sub
'display when the script starts
Wscript.Echo("beginning " & Now)
'create an instance of the AshShell clas
Set Shell = CreateObject("WScript.Shell")
'use the reg.exe save command, specify the registry key to save and the file to
'save it into
Shell.Exec "%comspec% /k reg.exe export hklm C:\HKLM.REG"
'display when the script completed
WScript.Echo("Completed " & Now)
Computer = "."
Namespace = "\trirose\Printers"
Query = "Select * from WinNT_Printer"
Set WMIService = GetObject("WinNT:\\" _
& Computer & Namespace
Set colItems = WMIService.ExecQuery(Query)
For Each objItem in colItems
WScript.Echo "Name: " & objItem.Name
WScript.Echo "Location: " & objItem.Location
WScript.Echo "Printer Status: " & strStatus
WScript.Echo "Server Name: " & objItem.ServerName
WScript.Echo "Share Name: " & objItem.ShareName
WScript.Echo
Next
Sub subEvalStatus
Select Case objItem.PrinterStatus
Case 1
strStatus = "Other"
Case 2
strStatus = "Unknown"
Case 3
strStatus = "Idle"

Case 4
strStatus = "Printing"
Case 5
strStatus = "Warmup"
Case 6
strStatus = "Stopped Printing"
Case 7
strStatus = "Offline"
Case 8
strStatus = "Out of Ink"
Case 9
strStatus = "Out of Paper"
Case 10
strStatus = "Error"
End Select
End Sub

You might also like