Copy of pkstormy's code in post 46 (processed by SmartIndent) to help with readability
Code:
Set WSNet = CreateObject("WScript.Network")
GetUser = WSNet.UserName
varComputerName = WSNet.ComputerName
Set WSNet = Nothing
Set MyConn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
MyConn.Open = "Provider=SQLOLEDB;Data Source=144.92.222.333;Initial Catalog=WhosInOut;Integrated Security=SSPI"
'Note: use Integrated Security=SSPI for Windows Authentication
Dim rst
Set rst = CreateObject("ADODB.Recordset")
QueryString = "SELECT * FROM dbo.Users where LoginID = '" & GetUser & "'"
'rst.Open queryString, MyConn, adopenkeyset, adlockreadonly
rst.Open QueryString, MyConn
Dim CC
CC = 0
While Not rst.EOF
CC = CC + 1
rst.MoveNext
Wend
rst.Close
Set rst = Nothing
If CC < 1 Then
Dim LogID
LogID = InputBox("Your LoginID was not found for the WhosIn/Out program (one time entry only), please enter your login name: (you will not be asked this again.) - contact Paul Kohn or Nick Wiley if you have any questions." & vbCrLf & "Please enter your loginID that use to login to your computer:")
If LogID = "" Then wscript.Quit
Dim FullName
FullName = InputBox("Now Please enter your FULL name:")
If FullName = "" Then wscript.Quit
SQL = "INSERT INTO dbo.Users(LoginID, UserFullName) Select '" & LogID & "', '" & FullName & "'"
MyConn.Execute (SQL)
SQL = "UPDATE dbo.Users SET LoginStatus ='" & "LoggedIn" & "' WHERE LoginID ='" & GetUser & "'"
MyConn.Execute (SQL)
SQL = "UPDATE dbo.Users SET ComputerName ='" & varComputerName & "' WHERE LoginID ='" & GetUser & "'"
MyConn.Execute (SQL)
SQL = "INSERT INTO dbo.UsersLogHistory(LoginID, LoginStatus) Select '" & GetUser & "', 'LoggedIn'"
MyConn.Execute (SQL)
MyConn.Close
MsgBox "Thank You. " & LogID & " has been registered. If you are a WhosIn/Out tester, you're login/logout status will show for others (and you can see theirs)."
Else
SQL = "UPDATE dbo.Users SET LoginStatus ='" & "LoggedIn" & "' WHERE LoginID ='" & GetUser & "'"
MyConn.Execute (SQL)
SQL = "UPDATE dbo.Users SET ComputerName ='" & varComputerName & "' WHERE LoginID ='" & GetUser & "'"
MyConn.Execute (SQL)
SQL = "INSERT INTO dbo.UsersLogHistory(LoginID, LoginStatus) Select '" & GetUser & "', 'LoggedIn'"
MyConn.Execute (SQL)
MyConn.Close
End If
Set MyConn = Nothing