Link to home
Start Free TrialLog in
Avatar of Mark Cary
Mark Cary

asked on

Logon Script not working .. specific failure circumstances

GPO for user logon/logoff calls VB script that logs Logon/Logoff events, 4624/4634 respectively, to a database.

Works perfectly for users logging on and off the network on their PCs/laptops.

Users going out to a Remote Desktop session have their logoff recorded but not their logon ... the Security Log, in the Event Viewer, records both, as expected, for wherever the user logs on ...
Avatar of McKnife
Flag of Germany image


It would possibly matter what server OS you use.
Also make sure that no logon script is running by adding a simple one like this one-liner batch:
md %appdata%\test\%date%

Open in new window

(verify that a folder with today's date has been created below %appdata%\test)
Avatar of Mark Cary
Mark Cary


I paired the script down to just creating a test folder ... the %date% has syntactically incorrect punctuation that causes an error on a pure test environment (my own workstation) ... but still not creating the test folder ...

There was another instruction (call it TASK#2), separate from the VB script that was and is running just fine ... ripped out TASK#2 and placed it in a separate GPO ... still works just fine ...

Again, the VB script is just not "stuffing" the SQL database with the logon event ... but it's fine with "stuffing" the logoff event ... here's a copy of the script to help visualize what we're attempting:

' -- ADODB Locktypes --
Const adLockReadOnly                              = 1               ' Default. Read-only records
Const adLockPessimistic                              = 2            ' Pessimistic locking, record by record. The provider lock records immediately after editing
Const adLockOptimistic                              = 3            ' Optimistic locking, record by record. The provider lock records only when calling update
Const adLockBatchOptimistic                        = 4            ' Optimistic batch updates. Required for batch update mode

' Attach to the database
Set objDBConn = CreateObject("ADODB.Connection") "Provider=SQLOLEDB.1;Integrated Security = SSPI;Trusted_Connection=Yes;Security=Persist Security Info=True;Initial Catalog='Audit';Data Source='sqlutil';"

Set objNetwork = CreateObject("WScript.Network")
Set objRS = CreateObject("ADODB.Recordset")

If WScript.Arguments.Count = 1 Then
      objRS.Open "EventLog", objDBConn, adOpenKeyset, adLockOptimistic
      objRS("EventHost") = UCase(objNetwork.ComputerName)
      objRS("EventUser") = LCase(objNetwork.UserName)
      objRS("EventType") = LCase(WScript.Arguments(0))
End If
Yep, I forgot the quotes
md "%appdata%\test\%date%"
Your script code does not matter. Please add the requested info: what server OS is that?
They are Remote Desktop Servers running 2008 R2 ...
Logged on to RDS with Domain Admin rights.  Ran RSOP.MSC and the Logon script is present ... along with your test ... the VB script ran and logged my Logon (event 4624) both in the Security Log of the Event Viewer and stuffed the info in the SQL database ... as expected ... but your test folder did not get created ... logging off also was logged in the Security Log and stuffed into the SQL database.

Logged on as standard domain user and nothing happened.  Logged off and the event appeared in the Security Log and the VB script was able to stuff the event into the SQL database ...

Nothing seems to be able to change these actions ... beginning to redefine "insanity" ... only with different circumstances yielding the same result!!!
I'd like to reproduce that, let's see when I find the time for that. I'll simply take my batch command and see if that folder gets created.
Avatar of Mark Cary
Mark Cary

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Good job!
Because I solved it myself?  Persistence counts ... right?