Logging Windows 2003 Terminal Server Connections - Writing the Script
(Page 3 of 4 )
Now that we have the batch file that will provide us with the information, we can start to write our VB script. Again open up your preferred text editor, and type the following code. We will write the script a section at a time and then explain the code.
'Create the objects
Set objwsh = WScript.CreateObject("WScript.Shell")
Set objFSO= CreateObject("Scripting.FileSystemObject")
'set the initial vars
CONST ForReading = 1
CONST ForWriting = 2
'get the computer name from the reg
strServerName = objwsh.RegRead("HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControl
ComputerNameActiveComputerNameComputerName")
'set the current date in a format SQL will understand
strSQLDate = DatePart("yyyy", Now()) & "-" & DatePart("m", Now()) & "-" & DatePart("d", Now()) & " " & DatePart("h", Now()) & ":" & DatePart("n", Now()) & ":" & DatePart("s", Now())
'set the initial line counter
intLineCnt = 0
'run the user query batch file to get the latest user info.
objwsh.Run "c:GetTSUserInfo.bat",1,true
The couple of lines simply create two objects: objwsh is the shell object, and objFSO is the file system object.
Then we set two constants for when we read and write to our text files.
The next part uses the Shell object we created, gets the current computer name out of the registry and stores it in a variable to use later.
Then we assign the variable strSQLDate to be the current date and time, in a format that we can use successfully in the SQL query, which we will use to update our table. The next line sets the initial line count to zero.
Next: Running the Batch File >>
More BrainDump Articles
More By Luke Niland