Room Activation
From Wiki
Creator: FN-Greatermacnhester
Script Language: VBS
Forum topic Link: http://www.edugeek.net/forums/wiki-announcements/20471-room-activation.html#post201318
This script is a room activation script where it will only let students use a computer suite if the teacher on the front machine has activated the room. There are three parts to the script that work together. The activation script where the user activates a room, a deactivation script where the users deactivates the room and the logon script for the suite.
Activation Script:
<vb>im stafffilesource, WS, objFSO, objNetwork, RoomName, TeacherPC Dim logday, logmonth, logyear, today, logmonthname, serverpath, filepath, filetxt
Set objFSO = CreateObject("Scripting.FileSystemObject") Set objNetwork = CreateObject("Wscript.Network") Set WS = CreateObject("Wscript.Shell")
Const ForReading = 1, ForWriting = 2, ForAppending = 8
TeacherPC = UCASE(objNetwork.ComputerName) stafffilesource = ("C:\Documents and Settings\logoncheck\staff.txt")
If UCASE(objNetwork.ComputerName) = "HC-ICT1-T1" Then RoomName = "ICT 1" If UCASE(objNetwork.ComputerName) = "HC-ICT1-T2" Then RoomName = "ICT 2" If UCASE(objNetwork.ComputerName) = "HC-ICT1-T3" Then RoomName = "ICT 3" If UCASE(objNetwork.ComputerName) = "HC-ICT1-T4" Then RoomName = "ICT 4" If UCASE(objNetwork.ComputerName) = "HC-ICT1-T5" Then RoomName = "ICT 5"
bConfirm = MsgBox ("Please complete an inspection of this Computer Suite." & VBCR & "If any damage is present, please inform IT Support prior to using this suite." & VBCR & VBCR & "Should any damage occur during your lesson time, please inform" & VBCR & "IT Support of the damage including how it occured," & VBCR & "including information such as the student responsible and if it was accidental." & VBCR & VBCR & "Should damage occur during your lesson time that is not reported," & VBCR & "your department may be required to pay the repair costs involved." & VBCR & VBCR & "Please confirm that you have completed a room check" & VBCR & "and accept responisbility for the use of this room.", 4, "Room Activation")
If bconfirm=6 Then
bConfirm = MsgBox ("Do you wish to Activate this Suite for Student Use?", 4, "Room Activation")
If bconfirm=6 Then
objFSO.CreateTextFile stafffilesource, True
WS.Popup "This Suite as now been activated for Student Use.", 6, "Room Activation"
Else
WS.Popup "Please use Desktop Icon if you wish to Activate this Suite for Student Use.", 6, "Room Activation"
End If
Else
WS.Popup "Please report damage to IT Support before you continue to use this suite.", 6, "Room Activation"
End If
Wscript.Quit</vb>
Deactivation script
<vb>On error resume next Dim NamingConvention, ComputerQty, StartCount, Count, TeacherPC, fileserverarea Dim objFSO, objNetwork, WS, stafffilesource, filetxt, RoomName, fileserverfile Dim oFSO, oTS, sClient, oWindows, oLocator, oConnection, oSys, ClientWritten Dim logday, logmonth, logyear, today, logmonthname, serverpath, filepath, strPingResults
Set objFSO = CreateObject("Scripting.FileSystemObject") Set objNetwork = CreateObject("Wscript.Network") Set WS = CreateObject("Wscript.Shell")
Const ForReading = 1, ForWriting = 2, ForAppending = 8
stafffilesource = "C:\Documents and Settings\logoncheck\staff.txt"
If NOT objFSO.FileExists (stafffilesource) Then WS.Popup "This Suite is already deactivated for Student Use.", 6, "Room Deactiviation" Wscript.Quit End If
Count = StartCount
call logthemoff
If ClientWritten = "TRUE" Then End If
objFSO.DeleteFile (stafffilesource), TRUE WS.Popup "This Suite has now been deactivated for Student Use.", 6, "Room Deactiviation" WS.Popup "Please complete an inspection of this Computer Suite." & VBCR & "If any damage has been caused during your lesson, please inform IT Support with details" & VBCR & VBCR & "By Disabling this Suite you are confirming that you will report any damage that has been found.", 10, "Damage Check" call maintenancelogreport
WScript.Quit</vb>
Logon script:
<vb>
Dim TeacherPC, TeachPCStaffFile, stafffilesource, studentfilesource, RoomName Dim sComputer, sUser, objNetwork, objFSO, objUser, WS, objshell Dim logday, logmonth, logyear, today, logmonthname, serverpath, filepath, filetxt
Set objNetwork = CreateObject("Wscript.Network") Set objFSO = CreateObject("Scripting.FileSystemObject") Set WS = CreateObject("Wscript.Shell") Set objShell = CreateObject("WScript.Shell")
Const ForReading = 1, ForWriting = 2, ForAppending = 8
'::::::::::::::::::::::::::::::::::::::::::::::: '::: Use LDAP to find out account details ::: '::::::::::::::::::::::::::::::::::::::::::::::: Set objSystemInfo = CreateObject ("AdSystemInfo") Err.Clear Set objUser = GetObject ("LDAP://" & objSystemInfo.UserName) If Err.Number <> 0 Then MsgBox Err.Number & vbTab & Err.Description End If
TeacherPC = "HC-ICT1-T1" TeachPCStaffFile = "\\" & TeacherPC & "\" & TeacherPC & "\staff.txt" RoomName = "ICT 1"
sComputer = UCASE(objNetwork.ComputerName) sUser = lcase(objNetwork.UserName)
stafffilesource = "C:\Documents and Settings\logoncheck\staff.txt" studentfilesource = "C:\Documents and Settings\logoncheck\student.txt"
If IsMember ("CN=Administrators") Then call DualLogons If IsMember ("CN=staff") Then call DualLogons If IsMember ("CN=students") Then call StudentLogon
WScript.Quit '*********************************************************************************************************************************8
'::::::::::::::::::::::::::::: '::: Run Student Logon Set ::: '::::::::::::::::::::::::::::: Sub StudentLogon On error resume next If NOT objFSO.FileExists (TeachPCStaffFile) Then ShowBox "This Logon is unauthorised." & VBCR & VBCR & "Your supervising Staff Member needs to enable access to this computer," & VBCR & "before you will be able to logon on successfully.", 6 call logmeoff Wscript.Quit End If objFSO.CreateTextFile studentfilesource, True End Sub
'::::::::::::::::::::::::::: '::: Dual Logon Accounts ::: '::::::::::::::::::::::::::: Sub DualLogons On error resume next Wscript.Quit End Sub
'::::::::::::::::::::::::: '::: Confirmed log off ::: '::::::::::::::::::::::::: Sub logmeoff
'Call WMI query to collect parameters for reboot action
Set OpSysSet = GetObject("winmgmts:{(Shutdown)}//" & sComputer & "/root/cimv2").ExecQuery("select * from Win32_OperatingSystem"_
& " where Primary=true")
Const EWX_LOGOFF = 0
Const EWX_SHUTDOWN = 1
Const EWX_REBOOT = 2
Const EWX_FORCE = 4
Const EWX_POWEROFF = 8
For each OpSys in OpSysSet
opSys.win32shutdown EWX_REBOOT + EWX_FORCE
Next
End Sub
'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: '::: CHECK WHETHER USER IS A MEMBER OF A CERTAIN GROUP ::: '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Function IsMember (strGroup) Dim objGroup IsMember = FALSE For Each objGroup In objUser.Groups 'Message "TESTING - PLEASE IGNORE", 1, strUserName & " is a member of " & objGroup.Name & " " & objGroup.Class, 1 strThisGroup = Replace (objGroup.Name, "CN=\", "") If strThisGroup = strGroup Then IsMember = TRUE Exit For End If Next End Function</vb>
Tips:
1. I would place shortcuts to the script on the desktop of the front machine.
2. Apply the logon script to a OU of computers using loopback, you could use other methods of getting the script to run in one room.
3. In your logoff script and startup script place few lines so it deletes the staff.txt file, this stops teachers logging off and just pressing the reset button keeping the room activated.


