Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- OPTION EXPLICIT
- Dim objNet, strComputer, objWMI, colitems, objItem, fso, Shell
- If Instr(1, WScript.FullName, "CScript", vbTextCompare) = 0 Then
- Shell.Run "cscript """ & WScript.ScriptFullName & """", 1, False
- WScript.Quit
- End If
- Set objNet = WScript.CreateObject("WScript.Network")
- WScript.StdOut.Write "Hi " & objNet.UserName & ". Welcome to the World" & _
- " of Scripting and Automation. You have connected to " & objNet.UserDomain & "/" & objNet.ComputerName & _
- " and running "
- Call OS()
- WScript.StdOut.Write "operating system. You are running your script from "
- Call Directory()
- WScript.StdOut.Write "and the path is "
- Call Path()
- WScript.StdOut.Write "The team members are: "
- WScript.Echo "Brent Wright, 100424357"
- WScript.Echo "Matthew Alex, 100428584"
- WScript.Echo "Kameron Chan, 100373050"
- WScript.Echo "Joshua Boyer, 100427919"
- Function Menu()
- Dim choice
- WScript.StdOut.Write "Administration Scripting - Durham College" & vbCrLf
- WScript.StdOut.Write "------------------------------------------" & vbCrLf
- WScript.StdOut.Write vbCrLf & "A - Desktop Management" & vbCrLf
- WScript.StdOut.Write "B - Logon and Logoff" & vbCrLf
- WScript.StdOut.Write "C - User Management" & vbCrLf
- WScript.StdOut.Write "D - Disk Management" & vbCrLf
- WScript.StdOut.Write "E - Utilites" & vbCrLf
- WScript.StdOut.Write "Q - Quit from the menu" & vbCrLf
- WScript.StdOut.Write "Enter your selection: "
- choice = WScript.StdIn.ReadLine
- Select Case choice
- Case "a","A" 'Brent Wright
- WScript.Echo ""
- WScript.Echo ""
- Call functionA()
- Case "b","B" 'Kameron Chan
- WScript.Echo ""
- WScript.Echo ""
- Call functionB()
- Case "c","C" 'Brent Wright
- WScript.Echo ""
- WScript.Echo ""
- Call functionC()
- Case "d","D" 'Josh Boyer
- WScript.Echo ""
- WScript.Echo ""
- Call functionD()
- Case "e","E" 'Kameron Chan/Matthew Alex
- WScript.Echo ""
- WScript.Echo ""
- Call functionE()
- Case "q","Q"
- Call functionQ()
- End Select
- End Function
- Call Menu()
- Function functionA() 'Brent Wright
- Dim selectionA, objNet
- Set objNet = CreateObject("WScript.Network")
- WScript.StdOut.Write "DeskTop Management" & vbCrLf
- WScript.StdOut.Write "----------------------" & vbCrLf
- WScript.StdOut.Write "A - Desktop Settings" & vbCrLf
- WScript.StdOut.Write "B - Shortcuts" & vbCrLf
- WScript.StdOut.Write "C - Events" & vbCrLf
- WScript.StdOut.Write "D - Scheduled Tasks" & vbCrLf
- WScript.StdOut.Write "Q - Exit to Main Menu" & vbCrLf
- WScript.StdOut.Write "What is your selection? "
- selectionA = WScript.StdIn.ReadLine
- Select Case selectionA
- Case "a","A"
- WScript.Echo ""
- WScript.Echo ""
- Call aDesktop()
- Case "b","B"
- WScript.Echo ""
- WScript.Echo ""
- Call aShortcut()
- Case "c","C"
- WScript.Echo ""
- WScript.Echo ""
- Call aEvent()
- Case "D"
- WScript.Echo ""
- WScript.Echo ""
- Call aTasks()
- Case "Q"
- WScript.Echo ""
- WScript.Echo ""
- Call Menu()
- Case else
- WScript.Echo "error"
- WScript.Echo ""
- WScript.Echo ""
- End Select
- Call Menu()
- WScript.Echo ""
- End Function
- 'Call functionA() 'End Brent
- Function functionB() ' Kameron Chan /Matthew Alex
- Dim menuchoice, ans', WScript
- 'Set WScript = CreateObject ("WScript.Shell")
- ans = "y"
- 'do
- WScript.Echo "1. Restart a computer"
- WScript.Echo "2. Logon script"
- WScript.Echo "3. Logoff script"
- WScript.Echo "4. Shutdown a computer"
- WScript.Echo "5. Exit to the Main menu"
- WScript.StdOut.WriteLine "Please choose an option: "
- menuchoice = WScript.StdIn.ReadLine
- 'loop while ans = "y"
- Select Case menuchoice
- Case "1"
- option1()
- ans = "n"
- Case "2"
- option2()
- ans = "n"
- Case "3"
- option3()
- ans = "n"
- Case "4"
- option4()
- ans = "n"
- Case "5"
- ans = "n"
- Call Menu()
- Case Else
- WScript.Echo "You did not insert a value corresponding with a menu option"
- ans = "y"
- End Select
- End Function
- 'Call functionB()
- Function functionC() 'Brent Wright
- Dim selectionC
- WScript.StdOut.Write "A - Create a Group" & vbCrLf
- WScript.StdOut.Write "B - Create Users" & vbCrLf
- WScript.StdOut.Write "C - List Users" & vbCrLf
- WScript.StdOut.Write "D - List Groups" & vbCrLf
- WScript.StdOut.Write "E - Delete User" & vbCrLf
- WScript.StdOut.Write "F - List Inactive Users" & vbCrLf
- WScript.StdOut.Write "Q - Exit to Main Menu" & vbCrLf
- WScript.StdOut.Write "Enter your selection: "
- selectionC = WScript.StdIn.ReadLine
- Select Case selectionC
- Case "a","A"
- WScript.Echo ""
- WScript.Echo ""
- Call cGroup()
- WScript.Echo ""
- WScript.Echo ""
- Case "b","B"
- WScript.Echo ""
- WScript.Echo ""
- Dim group
- Call cUser(group)
- Case "c","C"
- WScript.Echo ""
- WScript.Echo ""
- Call cUsersList()
- Case "d","D"
- WScript.Echo ""
- WScript.Echo ""
- Call cGroupsList()
- Case "e","E"
- WScript.Echo ""
- WScript.Echo ""
- Call cDelete()
- Case "f","F"
- WScript.Echo ""
- WScript.Echo ""
- Call cDisplayInactive()
- Case "Q"
- Call Menu()
- WScript.Echo ""
- WScript.Echo ""
- End Select
- Call Menu()
- End Function
- 'Call functionC() 'End Brent
- Function functionD()
- dim options
- dim strComputer
- dim objWMIservice
- dim colvolumes
- dim objvolume
- dim oXL
- dim i
- dim freespace(30)
- dim j
- dim volname(30)
- dim volsize(30)
- dim freespaceperc(30)
- Dim fso
- Dim ObjFolder
- Dim ObjFiles
- Dim ObjFile
- WScript.Echo "A - Display Drive Size and Store in Excel doc"
- WScript.Echo "B - Display Folder Properties and locate folders over 10mb"
- WScript.Echo "Z - Exit to Main Menu"
- WScript.StdOut.Write "Option: "
- options = WScript.StdIn.ReadLine
- 'function declarations
- Select Case options
- case "A"
- drivesize()
- case "B"
- folderprop()
- case "Z"
- WScript.Quit
- End Select
- End Function
- 'Call functionD()
- Function functionE()
- 'Variables are global
- dim suboption, menuoption
- WScript.Echo "1. Math Game"
- WScript.Echo "2. Dictionary"
- WScript.Echo "3. Software"
- WScript.StdOut.Write "Choose an option: "
- menuoption = WScript.StdIn.ReadLine
- Select Case menuoption
- Case 1
- option1()
- Case 2
- option2()
- Case 3
- option3()
- End Select
- Call Menu()
- End Function
- 'Call functionE()
- 'Math Game
- Function option1()
- dim h,s,e
- WScript.Echo "What is 5 * 5 + 20 / 5?"
- WScript.Echo "H - Help me S - Solve E - Exit"
- suboption = WScript.StdIn.ReadLine
- Select Case ucase(suboption)
- Case "H"
- help()
- Case "S"
- solve()
- Case "E"
- WScript.Quit
- End Select
- End Function
- Function help()
- dim objword, objdoc, objselection
- Set objWord = CreateObject("Word.Application")
- objWord.Caption = "Test Caption"
- objWord.Visible = True
- Set objDoc = objWord.Documents.Add()
- Set objSelection = objWord.Selection
- objSelection.Font.Name = "Arial"
- objSelection.ParagraphFormat.Alignment=1
- objSelection.Font.Underline= true
- objSelection.Font.Size = "12"
- objSelection.TypeText "Equipment Cost"
- objSelection.Font.Underline= false
- objSelection.TypeParagraph()
- objSelection.ParagraphFormat.Alignment=0
- objSelection.TypeText"10 * 10 + 15 / 3"
- WScript.Sleep 2000
- objSelection.TypeParagraph()
- objSelection.TypeText"100 + 5"
- WScript.Sleep 2000
- objSelection.TypeParagraph()
- objSelection.TypeText"105"
- WScript.Sleep 2000
- objSelection.TypeParagraph()
- objDoc.SaveAs("C:\Scripts\finalprojectmathgame.docx")
- WScript.Sleep 3000
- objWord.Quit
- 'menu()
- End Function
- Function solve()
- dim mathans, wshshell
- WScript.Echo "Please enter your answer: "
- mathans = WScript.StdIn.ReadLine
- if mathans = 29 then
- 'menu()
- else
- set WshShell = WScript.CreateObject("WScript.Shell") ' invoke applications
- WshShell.Run "calc"
- WshShell.AppActivate "Calculator" ' activate the calculator
- WScript.Sleep 1000
- WshShell.SendKeys "%2"
- WshShell.SendKeys "5{*}"
- WScript.Sleep 2000
- WshShell.SendKeys "5"
- WScript.Sleep 2000
- WshShell.SendKeys "{+}"
- WScript.Sleep 2000
- WshShell.SendKeys "20{/}"
- WScript.Sleep 2000
- WshShell.SendKeys "5"
- WScript.Sleep 2000
- WshShell.SendKeys "{ENTER}"
- WScript.Sleep 2500
- wshshell.SendKeys "%{F4}"
- menu()
- End If
- End Function
- 'Dictionary
- Function option2()
- WScript.Echo "How would you like to modify the server detials list?"
- WScript.Echo "A - Add L - List D - Delete E - Exit"
- suboption = WScript.StdIn.ReadLine
- End Function
- Dim objDict
- Set objDict = CreateObject("Scripting.Dictionary")
- ' fill the items in the dictionary
- function DisplayServerDetails(ObjDict)
- Select Case ucase(suboption)
- Case "A"
- addentry()
- Case "L"
- display()
- Case "D"
- delentry()
- Case "E"
- WScript.Quit
- End Select
- end function
- Function functionQ() 'Josh Boyer
- dim array(9)
- Array(0)="Thank you for running this program"
- Array(1)="Have a good summer! Program exited."
- Array(2)="We hope you enjoyed our program."
- Array(3)="Program exited. Thank you."
- Array(4)="We appreciate that you ran the program."
- Array(5)="This program was made by: Joshua Boyer, Kameron Chan, Matthew Alex and Brent Wright."
- Array(6)="All of these options were made using VBScript."
- Array(7)="Thank you. Have a great summer."
- Array(8)="Please use this program again."
- Array(9)="Thank you for executing this VBScript."
- Randomize
- Wscript.Echo array(Int(rnd*10))
- Wscript.Sleep 2000
- WScript.Quit
- End Function
- Function aDesktop 'Brent Wright
- Dim WshShell, wallpaper, sleepTime, FSO, HKEY_CURRENT_USER
- HKEY_CURRENT_USER = &H80000001
- WScript.StdOut.Write "Enter the path for the picture you want to use: "
- wallpaper = WScript.StdIn.ReadLine
- sleepTime = 30000
- Set FSO = CreateObject("Scripting.FileSystemObject")
- Set WshShell = WScript.CreateObject("Wscript.Shell")
- WshShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", wallpaper
- WScript.Sleep sleepTime
- WshShell.Run "%windir%\System32\RUNDLL32.EXE user32.dll, UpdatePerUserSystemParameters", 1, False
- strComputer = "."
- Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
- strKeyPath = "Control Panel\Desktop"
- objReg.CreateKey HKEY_CURRENT_USER, strKeyPath
- ValueName = "ScreenSaveTimeout"
- strValue = "300"
- objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, ValueName, strValue
- Set WshShell = Nothing
- End Function
- Function aShortcut 'Brent Wright
- Dim MyShortcut, URL, favourite, deleted,objStartFolder
- Dim objFolder, colFiles, objFile, confirm, WSHShell, Link
- Dim objNet, FSO
- Set WSHShell = WScript.CreateObject("WScript.Shell")
- Set objNet = CreateObject("WScript.Network")
- MyShortcut = "C:\Users\" & objNet.username & "\Desktop\Computer Management.LNK"
- Set Link = WSHShell.CreateShortcut(MyShortcut)
- Link.TargetPath = ("C:\Windows\System32\compmgmt.msc")
- Link.WorkingDirectory =("C:\Windows\System32")
- Link.WindowStyle = 4
- Link.Save
- WScript.StdOut.Write "Enter your website URL: "
- URL = WScript.StdIn.ReadLine
- Set favourite = WSHShell.CreateShortcut("C:\Users\" & objNet.UserName & "\Favorites\favourite.url")
- favourite.TargetPath = URL
- favourite.Save
- WScript.StdOut.Write "Enter a shortcut to delete: "
- deleted = WScript.StdIn.ReadLine
- WScript.StdOut.Write "Do you want to delete the shortcut?[Y/N]"
- confirm = WScript.StdIn.ReadLine
- if confirm = "Y" then
- FSO.DeleteFile deleted
- elseif confirm = "N" then
- WScript.Echo "Not deleted"
- End If
- Set FSO = CreateObject("Scripting.FileSystemObject")
- objStartFolder = "C:\Users\" & objNet.Username & "\Desktop"
- Set objFolder = FSO.GetFolder(objStartFolder)
- Wscript.Echo objFolder.Path
- Set colFiles = objFolder.Files
- For Each objFile in colFiles
- If UCase(FSO.GetExtensionName(objFile.name)) = "LNK" Then
- Wscript.Echo objFile.Name
- End If
- Next
- Wscript.Echo
- End Function
- Function aEvent ' Brent Wright
- Dim objEvent, ScriptContext, text, FSO, WshShell, strCommand
- Dim objWMIService, colLogFiles, objLogFile, errBackupLog
- Dim colLoggedEvents, loggedevent
- Set FSO = CreateObject("Scripting.FileSystemObject")
- Set WshShell = CreateObject("WScript.Shell")
- strCommand = "eventcreate /T Error /ID 100 /L Shortcuts /D " & _
- Chr(34) & "Shortcut Created" & Chr(34)
- WshShell.Run strcommand
- strComputer = "."
- Set objWMIService = GetObject("winmgmts:" _
- & "{impersonationLevel=impersonate,(Backup)}!\\" & _
- strComputer & "\root\cimv2")
- Set colLogFiles = objWMIService.ExecQuery _
- ("SELECT * FROM Win32_NTEventLogFile WHERE LogFileName='Application'")
- For Each objLogfile in colLogFiles
- errBackupLog = objLogFile.BackupEventLog("c:\scripts\application.evt")
- If errBackupLog <> 0 Then
- Wscript.Echo "The Application event log could not be backed up."
- Else
- objLogFile.ClearEventLog()
- End If
- Next
- strComputer = "."
- Set objWMIService = GetObject("winmgmts:" _
- & "{impersonationLevel=impersonate,(Security)}!\\" & strComputer & "\root\cimv2")
- Set colLoggedEvents = objWMIService.ExecQuery _
- ("Select * from Win32_NTLogEvent Where Logfile = 'Security' and CategoryString='Account Management'")
- For each loggedEvent in colLoggedEvents
- Set text = FSO.OpenTextFile("account_events.txt", 8)
- text.WriteLine "Security Events: " & loggedEvent.Name
- text.Close
- Next
- End Function
- Function aTasks 'Brent Wright
- Dim source, destination, copy, FSO, objWMIService, objNewJob, JobID, errJobCreated, colScheduledJobs, objJob
- Set FSO = CreateObject("Scripting.FileSystemObject")
- strComputer = "."
- Set objWMIService = GetObject("winmgmts:" _
- & "{impersonationLevel=impersonate}!\\" _
- & strComputer & "\root\cimv2")
- Set objNewJob = objWMIService.Get("Win32_ScheduledJob")
- errJobCreated = objNewJob.Create _
- ("c:\defrag.bat", "********220000.000000-300", _
- True , 16, , True, JobId)
- If errJobCreated <> 0 Then
- Wscript.Echo "Error: Task creation failed"
- Else
- Wscript.Echo "Task created successfully"
- End If
- strComputer = "."
- Set objWMIService = GetObject("winmgmts:" _
- & "{impersonationLevel=impersonate}!\\" _
- & strComputer & "\root\cimv2")
- Set objNewJob = objWMIService.Get("Win32_ScheduledJob")
- errJobCreated = objNewJob.Create _
- ("c:\backup.bat", "********220000.000000-300", _
- True , 16, , True, JobId)
- If errJobCreated <> 0 Then
- Wscript.Echo "Error: Task creation failed"
- Else
- Wscript.Echo "Task created successfully"
- End If
- strComputer = "."
- Set objWMIService = GetObject("winmgmts:" _
- & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
- Set colScheduledJobs = objWMIService.ExecQuery _
- ("Select * from Win32_ScheduledJob")
- For Each objJob in colScheduledJobs
- Wscript.Echo "Caption: " & objJob.Caption
- Wscript.Echo "Command: " & objJob.Command
- Wscript.Echo "Days of Month: " & objJob.DaysOfMonth
- Wscript.Echo "Days of Week: " & objJob.DaysOfWeek
- Wscript.Echo "Description: " & objJob.Description
- Wscript.Echo "Elapsed Time: " & objJob.ElapsedTime
- Wscript.Echo "Install Date: " & objJob.InstallDate
- Wscript.Echo "Interact with Desktop: " & objJob.InteractWithDesktop
- Wscript.Echo "Job ID: " & objJob.JobID
- Wscript.Echo "Job Status: " & objJob.JobStatus
- Wscript.Echo "Name: " & objJob.Name
- Wscript.Echo "Notify: " & objJob.Notify
- Wscript.Echo "Owner: " & objJob.Owner
- Wscript.Echo "Priority: " & objJob.Priority
- Wscript.Echo "Run Repeatedly: " & objJob.RunRepeatedly
- Wscript.Echo "Start Time: " & objJob.StartTime
- Wscript.Echo "Status: " & objJob.Status
- Wscript.Echo "Time Submitted: " & objJob.TimeSubmitted
- Wscript.Echo "Until Time: " & objJob.UntilTime
- Next
- WScript.Echo ""
- WScript.Echo ""
- End Function
- Function option1() 'Kameron Chan
- dim objShell
- Set objShell = WScript.CreateObject("WScript.Shell")
- objShell.Run "C:\WINDOWS\system32\shutdown.exe -r -t 0"
- End Function
- Function option2() 'Kameron Chan
- Dim objNetwork, objNet, colDrives, i, objWMIService, colPrinters
- Set objNetwork = CreateObject("WScript.Network")
- WScript.Echo "Hi" & objNetwork.UserName & ", Welcome to Windows." 'welcome message
- Set objNet = CreateObject("Wscript.Network")
- Set colDrives = objNetwork.EnumNetworkDrives
- For i = 0 to colDrives.Count-1 Step 2
- objNetwork.RemoveNetworkDrive colDrives.Item(i) 'deletes mapped drives
- Next
- Set objNet = CreateObject("WScript.Network")
- strComputer = "."
- Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
- Set colPrinters = objWMIService.ExecQuery("Select * From Win32_Printer")
- 'adds three drives
- Set objNetwork = CreateObject("WScript.Network")
- objNetwork.MapNetworkDrive "S:", "PATH"
- Set objNetwork = CreateObject("WScript.Network")
- objNetwork.MapNetworkDrive "J:", "PATH"
- Set objNetwork = CreateObject("WScript.Network")
- objNetwork.MapNetworkDrive "R:", "PATH"
- 'removes printers
- For Each objPrinter in colPrinters
- If objPrinter.Attributes And NETWORK Then
- strPrinter = objPrinter.Name
- objNet.RemovePrinterConnection strPrinter
- End If
- Next
- ' readd printers and part d
- objNetwork.AddWindowsPrinterConnection "\\server\H134"
- objNetwork.AddWindowsPrinterConnection "\\server\SW214"
- objNetwork.AddWindowsPrinterConnection "\\server\B221"
- objNetwork.SetDefaultPrinter "\\Server\B221"
- 'part e
- Set objFSO=CreateObject("Scripting.FileSystemObject")
- Set objNetwork = CreateObject("WScript.Network")
- Set colPrinters = objNetwork.EnumPrinterConnections
- ' list all the drives
- wscript.echo "Current Mapped Paths"
- Set colDrives=objFSO.Drives
- For Each Drive In colDrives
- WScript.Echo "Path: " & Drive.Path
- WScript.Echo String(20,".") & vbCRLF
- Next
- ' print only the printer names
- wscript.echo "Current Printer Assignments: " & colPrinters.Count/2 &vbCRLF
- For i = 1 to colPrinters.Count - 1 Step 2
- wscript.echo colPrinters.Item(i)
- Next
- ' Part f
- Set objNetwork = CreateObject("Wscript.Network")
- Set objShell = WScript.CreateObject("WScript.Shell")
- strComputer = objNetwork.ComputerName
- strUser = objNetwork.UserName
- isAdministrator = false
- 'Checks to see if current user is a admin sets isadministrator variable accordingly
- Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators")
- For Each objUser in objGroup.Members
- If objUser.Name = strUser Then
- isAdministrator = true
- End If
- Next
- If isAdministrator Then
- Wscript.Echo strUser & " is a local administrator."
- objNetwork.AddWindowsPrinterConnection "\\server\B221" 'adds printer
- objShell.Run "NET TIME" 'synchronizes time
- 'Turn off the wallpaper setting
- objShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", ""
- objShell.RegWrite "HKCU\Control Panel\Colors\Background", "255 255 255" 'Sets wall paper to white
- Else
- Wscript.Echo strUser & " is not a local administrator."
- End If
- ' PART G Retrieve computers IP address
- ' strComputer = "."
- ' Set objWMIService = GetObject( _
- ' "winmgmts:\\" & strComputer & "\root\cimv2")
- ' Set colNics = objWMIService.ExecQuery _
- ' ("Select * From Win32_NetworkAdapter " _
- ' & "Where NetConnectionID = " & _
- ' "'Local Area Connection'")
- ' For Each objNic in colNics
- ' Set colNicConfigs = objWMIService.ExecQuery _
- ' ("ASSOCIATORS OF " _
- ' & "{Win32_NetworkAdapter.DeviceID='" & _
- ' objNic.DeviceID & "'}" & _
- ' " WHERE AssocClass=Win32_NetworkAdapterSetting")
- ' For Each objNicConfig In colNicConfigs
- ' For Each strIPAddress in objNicConfig.IPAddress
- ' Wscript.Echo "IP Address: " & strIPAddress
- ' Next
- ' Next
- ' Next
- End Function
- Function option3() 'Kameron Chan
- Const NETWORK = 22
- Dim objNetwork, objNet, objWMIService, colPrinters, strComputer, strPrinter, objPrinter
- Set objNet = CreateObject("WScript.Network")
- strComputer = "."
- Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
- Set colPrinters = objWMIService.ExecQuery("Select * From Win32_Printer")
- For Each objPrinter in colPrinters
- If objPrinter.Attributes And NETWORK Then
- strPrinter = objPrinter.Name
- objNet.RemovePrinterConnection strPrinter
- End If
- Next
- objNetwork.RemoveNetworkDrive "J:"
- Set objNetwork = CreateObject("WScript.Network")
- MsgBox("Hi" & objNetwork.UserName & ", You will be logged out soon")
- End Function
- Function option4() 'Kameron Chan
- dim objShell
- Set objShell = WScript.CreateObject("WScript.Shell")
- objShell.Run "C:\WINDOWS\system32\shutdown.exe -t 0"
- End Function
- Function cGroup() 'Brent Wright
- Dim group, colAccounts, objGroup, groupPass
- group = InputBox("Enter the name of a group to create: ")
- strComputer = "."
- Set colAccounts = GetObject("WinNT://" & strComputer & "")
- if lcase(trim(colAccounts.Name)) = lcase(trim(group)) then
- WScript.Echo "The group is already created"
- else
- Set objGroup = colAccounts.Create("group", group)
- objGroup.SetInfo
- End If
- End Function
- Function cUser(group) 'Brent Wright
- Dim user, pass, colAccounts, objUser, objGroup, newgroup, replacer, objNet
- Set objNet = CreateObject("WScript.Network")
- 'newgroup = cGroup(groupPass)
- newgroup = group
- Do until user = "NOMORE"
- WScript.StdOut.Write "Enter a username: "
- user = WScript.StdIn.ReadLine
- if not user = "NOMORE" then
- WScript.StdOut.Write "Enter a password: "
- pass = WScript.StdIn.ReadLine
- end if
- strComputer = "."
- Set colAccounts = GetObject("WinNT://" & strComputer & "")
- Set objUser = colAccounts.Create("user", user)
- Do until Len(pass) <= 8
- if Len(pass) <= 8 then
- objUser.SetPassword pass
- objUser.SetInfo
- else
- WScript.Echo "That password is invalid."
- WScript.StdOut.Write "Enter a password: "
- pass = WScript.StdIn.ReadLine
- End If
- Loop
- Loop
- strComputer = "."
- Set objGroup = GetObject("WinNT://" & objNet.ComputerName & "/" & newgroup)
- For each objUser in colAccounts
- Set objUser = GetObject("WinNT://" & objNet.ComputerName & "/" & user)
- objGroup.Add(objUser.ADsPath)
- Next
- End Function
- Function cUsersList 'Brent Wright
- Dim FSO, colAccounts, strComputer, text, objUser, create
- Set FSO = CreateObject("Scripting.FileSystemObject")
- Set create = FSO.CreateTextFile("c:\scripts\user_list.txt")
- Set create = nothing
- strComputer = "."
- Set colAccounts = GetObject("WinNT://" & strComputer & "")
- colAccounts.Filter = Array("user")
- For Each objUser In colAccounts
- Wscript.Echo objUser.Name
- Set text = FSO.OpenTextFile("c:\scripts\user_list.txt", 8)
- text.WriteLine "Users: " & objUser.Name
- text.Close
- Next
- End Function
- Function cGroupsList 'Brent Wright
- Dim strComputer, colAccounts, objGroup, FSO, text, doc
- Set FSO = CreateObject("Scripting.FileSystemObject")
- Set doc = FSO.CreateTextFile("c:\scripts\groups.docx")
- Set doc = nothing
- strComputer = "."
- Set colAccounts = GetObject("WinNT://" & strComputer & "")
- colAccounts.Filter = Array("group")
- For Each objGroup In colAccounts
- Wscript.Echo objGroup.Name
- Set text = FSO.OpenTextFile("c:\scripts\groups.docx", 2)
- text.WriteLine "Groups: " & objGroup.Name
- text.Close
- Next
- End Function
- Function cDelete() 'Brent Wright
- Dim objComputer, delete, confirm, objNet
- Set objNet = CreateObject("WScript.Network")
- WScript.StdOut.Write "What user do you want to delete? "
- delete = WScript.StdIn.ReadLine
- WScript.StdOut.Write "Are you sure[Y/N]"
- confirm = WScript.StdIn.ReadLine
- Set objComputer = GetObject("WinNT://" & objNet.ComputerName & "")
- if confirm = "Y" then
- objComputer.Delete "user", delete
- else
- WScript.Echo "Operation Aborted"
- End If
- End Function
- Function cDisplayInactive() 'Brent Wright
- strComputer = "."
- Dim flag, colAccounts, objUser
- Const ADS_UF_ACCOUNTDISABLE = &H0002
- Set colAccounts = GetObject("WinNT://" & strComputer & "")
- colAccounts.Filter = Array("user")
- For Each objUser In colAccounts
- if objUser.UserFlags and ADS_UF_ACCOUNTDISABLE then
- Wscript.Echo objUser.Name
- WScript.Echo ""
- else
- end if
- Next
- WScript.Echo ""
- WScript.Echo ""
- End Function
- Function OS() 'Brent Wright
- strComputer = "."
- Set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
- Set colItems = objWMI.ExecQuery("SELECT * FROM Win32_OperatingSystem",,48)
- For Each objItem in colItems
- Wscript.Echo objItem.Caption
- Next
- End Function
- Function Directory() 'Brent Wright
- Set Shell = CreateObject("WScript.Shell")
- Set fso = CreateObject("Scripting.FileSystemObject")
- Shell.CurrentDirectory = FSO.GetParentFolderName(Wscript.ScriptFullName)
- WScript.Echo Shell.CurrentDirectory
- End Function
- Function Path() 'Brent Wright
- Dim pathing
- Set fso = CreateObject("Scripting.FileSystemObject")
- pathing = fso.GetAbsolutePathName("finalmenu.vbs")
- WScript.Echo pathing
- End Function
- Function addentry()
- Dim SERVER, DOMAIN, LOCATION, TOTALSIZE, USERS, STATICIP, COST
- Const SERVERDICT = 0
- Const DOMAINDICT = 1
- const LOCATIONDICT = 2
- const TOTALSIZEDICT = 3
- const USERSDICT = 4
- const STATICIPDICT = 5
- Const COSTDICT = 6
- Dim objDict
- Set objDict = CreateObject("Scripting.Dictionary")
- WScript.StdOut.Write "Enter server name: "
- SERVER = WScript.StdIn.ReadLine
- WScript.StdOut.Write "Enter domain name: "
- DOMAIN = WScript.StdIn.ReadLine
- WScript.StdOut.Write "Enter location: "
- LOCATION = WScript.StdIn.ReadLine
- WScript.StdOut.Write "Enter total disk size(GB): "
- TOTALSIZE = WScript.StdIn.ReadLine
- WScript.StdOut.Write "Enter total users: "
- USERS = WScript.StdIn.ReadLine
- WScript.StdOut.Write "Enter static IP: "
- STATICIP = WScript.StdIn.ReadLine
- WScript.StdOut.Write "Enter cost: "
- COST = WScript.StdIn.ReadLine
- Dim strItemAdd(7)
- Dim strKey
- ' Populate the list, using phone number as the key.
- ' Add values to temp array, then add temp array to dictionary.
- strItemAdd(SERVERDICT) = SERVER
- strItemAdd(DOMAINDICT) = DOMAIN
- strItemAdd(LOCATIONDICT) = LOCATION
- strItemAdd(TOTALSIZEDICT) = TOTALSIZE
- strItemAdd(USERSDICT) = USERS
- strItemAdd(STATICIPDICT) = STATICIP
- strItemAdd(COSTDICT) = COST
- ' key is Server Name
- strKey = strItemAdd(SERVERDICT)
- ' add to the dictionary where strItemAdd is an array
- objDict.Add strKey, strItemAdd
- 'menu()
- End Function
- function display()
- Dim n,keys,k,v,i,strItemRead, objdict
- n = objDict.Count
- keys = objDict.Keys()
- for i=0 to n-1
- k = keys(i)
- If objDict.Exists(k) Then
- strItemRead = objDict.Item(k)
- Wscript.echo vbNewLine & _
- "Server Name : " & strItemRead(0) & vbNewLine & _
- "Domain Name : " & strItemRead(1) & vbNewLine & _
- "Location : " & strItemRead(2) & vbNewLine & _
- "Total Disk Size: " & strItemRead(3) & vbNewLine & _
- "Total Users : " & strItemRead(4) & vbNewLine &_
- "Static IP: " & strItemRead(5) & vbNewLine & _
- "Cost: " & strItemRead(6) & vbNewLine
- End If
- next
- End function
- Function delentry()
- End Function
- 'Software
- Function option3()
- WScript.Echo "What would you like to do?"
- WScript.Echo "1. List installed software"
- WScript.Echo "2. Delete software"
- WScript.Echo "3. Install software"
- suboption = WScript.StdIn.ReadLine
- Select Case suboption
- Case "1"
- listsoftware()
- Case "2"
- delsoftware()
- Case "3"
- installsoftware()
- End Select
- end function
- Function listsoftware()
- Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
- dim strcomputer, strkey, strentry1a, strentry1b, strentry2,strentry3,strentry4,strentry5, obj reg, strsubkey, arrsubkeys
- strComputer = "."
- strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
- strEntry1a = "DisplayName"
- strEntry1b = "QuietDisplayName"
- strEntry2 = "InstallDate"
- strEntry3 = "VersionMajor"
- strEntry4 = "VersionMinor"
- strEntry5 = "EstimatedSize"
- Set objReg = GetObject("winmgmts://" & strComputer & _
- "/root/default:StdRegProv")
- objReg.EnumKey HKLM, strKey, arrSubkeys
- WScript.Echo "Installed Applications" & VbCrLf
- For Each strSubkey In arrSubkeys
- intRet1 = objReg.GetStringValue(HKLM, strKey & strSubkey, _
- strEntry1a, strValue1)
- If intRet1 <> 0 Then
- objReg.GetStringValue HKLM, strKey & strSubkey, _
- strEntry1b, strValue1
- End If
- If strValue1 <> "" Then
- WScript.Echo VbCrLf & "Display Name: " & strValue1
- End If
- objReg.GetStringValue HKLM, strKey & strSubkey, _
- strEntry2, strValue2
- If strValue2 <> "" Then
- WScript.Echo "Install Date: " & strValue2
- End If
- objReg.GetDWORDValue HKLM, strKey & strSubkey, _
- strEntry3, intValue3
- objReg.GetDWORDValue HKLM, strKey & strSubkey, _
- strEntry4, intValue4
- If intValue3 <> "" Then
- WScript.Echo "Version: " & intValue3 & "." & intValue4
- End If
- objReg.GetDWORDValue HKLM, strKey & strSubkey, _
- strEntry5, intValue5
- If intValue5 <> "" Then
- WScript.Echo "Estimated Size: " & Round(intValue5/1024, 3) & " megabytes"
- End If
- Next
- End Function
- Function delsoftware()
- dim strcomputer, software, colSoftware, objWMIService, objSoftware
- strComputer = "."
- WScript.Echo "What software would you like to remove?"
- software = WScript.StdIn.ReadLine
- Set objWMIService = GetObject("winmgmts:" _
- & "{impersonationLevel=impersonate}!\\" _
- & strComputer & "\root\cimv2")
- Set colSoftware = objWMIService.ExecQuery _
- ("Select * from Win32_Product " _
- & "Where Name =" & software)
- For Each objSoftware in colSoftware
- objSoftware.Uninstall()
- Next
- End Function
- Function installsoftware()
- End Function
- function drivesize()
- strComputer = "."
- Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
- Set colVolumes = objWMIService.ExecQuery("Select * from Win32_Volume")
- For Each objVolume in colVolumes
- Set oXL = Wscript.CreateObject("Excel.Application")
- ' Ensure that its visible to the end-user
- oXL.Visible = TRUE
- ' Add a workbook
- oXL.WorkBooks.Add
- For i=0 to colVolumes.Count-1
- freespace(i) = objVolume.FreeSpace / 1024
- freespaceper(i) = objVolume.FreeSpacePercent
- volname(i) = objVolume.VolumeName
- volsize(i) = objVolume.VolumeSize / 1024
- Next
- j = i + 2
- oXL.Cells(1,1).Value = "Drive name:"
- oXL.Cells(2,1).Value = "Volume size:"
- oXL.Cells(3,1).Value = "Free space:"
- oXL.Cells(1,j).Value = volname(i)
- oXL.Cells(2,j).Value = volsize(i)
- oXL.Cells(2,j).Value = freespace(i)
- Next
- For i = 0 to colVolumes.Count-1
- If freespaceper > 29 then
- WScript.Echo "Volume name: " & volname(i)
- Else
- WScript.Echo "All drives have less than 30% free space"
- End If
- Next
- end function
- function folderprop()
- dim foldername, i, colFolders
- WScript.Echo "Please enter a folder name(absolute path): "
- foldername = WScript.StdIn.ReadLine
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set ObjFolder = fso.GetFolder(foldername)
- Set ObjFiles = ObjFolder.Files
- For Each ObjFile In ObjFiles
- WScript.Echo ObjFile.Name & String(50 - Len(ObjFile.Name), " ") & ObjFile.Path
- Next
- dim foldernames(100), drivename
- strComputer = "."
- Set objWMIService = GetObject("winmgmts:" _
- & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
- Set colFolders = objWMIService.ExecQuery("Select * from Win32_Directory")
- For Each objFolder in colFolders
- for i = 0 to colFolders.Count - 1
- foldernames(i)=objFolder.Name
- Next
- Next
- WScript.Echo "Please enter the drive name: "
- drivename = WScript.StdIn.ReadLine
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- Set objFolder = objFSO.GetFolder(drivename)
- foldersizemb = objFolder.Size * 1024
- if foldersizemb > 9 then
- for i = 0 to colFolders.Count - 1
- WScript.Echo "Folder name: " & foldernames(i)
- Next
- End If
- end function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement