[gptalk] Re: Determining Who Has Run a Login Script

  • From: "Bean, Scott" <beans@xxxxxxxxxxxxxxxxx>
  • To: <gptalk@xxxxxxxxxxxxx>
  • Date: Mon, 22 Oct 2007 13:26:28 -0400

We do something similar but in our case it logs who logins into what
machine into a SQL database.  Below is the code (somewhat sloppy) but
hopefully it will get you started.  This is more than likely overkill
for what you want (my assumption), since you only want to see if it has
been installed and then you probably won't care after that.



'Find User/Computer SQL

Call SQLInsert

Sub SQLInsert

On Error Resume Next

Const adClipString = 2 

Const adOpenStatic = 3 

Const adLockOptimistic = 3 


strComputer = "."

Set wshNet = WScript.CreateObject("WScript.Network")

Set objWMIService = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate}!\\" & strComputer& "\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * from

For Each objItem In colItems

ComputerName = objItem.CSName


strUser = ""

While strUser = ""

strUser = wshNet.UserName

MyTime = Time

MyDate = Date

MyDateTime = Date + Time


nStatus = 1 


sCS = "Provider=Microsoft.Jet.OLEDB.4.0;Data

sCS = "Provider=SQLOLEDB;Data
Source=yourServer;Trusted_Connection=Yes;Initial Catalog=yourDB;User


Set oCnct = CreateObject( "ADODB.Connection" ) 

oCnct.Open sCS 


Set oRS = CreateObject("ADODB.Recordset") 

oRS.Open    "SELECT * FROM Logon WHERE ComputerName = '" + ComputerName
+ "'", oCnct, adOpenStatic, adLockOptimistic 


If oRS.EOF Then


oRS.Fields( "ComputerName" ) = ComputerName 


End If 

oRS.Fields( "Status" ) = nStatus

oRS.Fields( "UserName" ) = strUser

oRS.Fields( "TimeStamp" ) = MyDateTime  





Set oCnct = Nothing 

End Sub

'End Find User/Computer SQL


From: gptalk-bounce@xxxxxxxxxxxxx [mailto:gptalk-bounce@xxxxxxxxxxxxx]
On Behalf Of EIS Lists
Sent: Monday, October 22, 2007 1:16 PM
To: gptalk@xxxxxxxxxxxxx
Subject: [gptalk] Determining Who Has Run a Login Script


Hi -


We want to run a little logon script (or maybe startup script) to
install fonts and make a reg change. Is there an easy way to "log" who
has run this script? I thought about writing a line to a shared text
file but have not had much luck with that. This would affect about 100





Other related posts: