We help IT Professionals succeed at work.

Logon Script not working .. specific failure circumstances

Mark Cary
Mark Cary asked
Last Modified: 2018-02-06
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 ...
Watch Question

Distinguished Expert 2019


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)


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
Distinguished Expert 2019

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!!!
Distinguished Expert 2019

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.
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
Distinguished Expert 2019

Good job!


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

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions