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 ...
VB ScriptSecurity

Avatar of undefined
Last Comment
Mark Cary

8/22/2022 - Mon


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)
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")
objDBConn.open "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?
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
Mark Cary

They are Remote Desktop Servers running 2008 R2 ...
Mark Cary

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.
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Mark Cary

View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.

Good job!
Mark Cary

Because I solved it myself?  Persistence counts ... right?