Track launching of a program

Monopoly money comes in many flavors: 7, Vista, XP, 2K, ME, 98, etc.

Moderators: Flying Fox, Ryu Connor

Track launching of a program

Postposted on Fri Feb 24, 2012 9:15 am

I'm looking for a free/cheap piece of software that can use username/password to lock access to one+ programs in order to track how many times and who accesses this software. Its not a high security issue, just need to be able to track uses for funding purposes. Anyone know of an easy way to do this. We would like to not have different Windows XP users for every user, just one common Windows XP login and then a way to track the use of the program we are interested in tracking. Thank you for any suggestions.
apkellogg
Gerbil Elite
 
Posts: 894
Joined: Wed Feb 25, 2004 9:15 am

Re: Track launching of a program

Postposted on Fri Feb 24, 2012 9:27 am

I guess you will need to clarify a few things.

Do you simply want to log each time one of your users executes a certain EXE file?

I'm not sure I fully understand the lock access via username/password portion.
i7-920 @ 4.20GHz | Biostar Tpower X58 | 4870 1GB | 3x2 DDR3-1600 OCZ Gold Modules | Windows 7 Ultimate x64 | 4x 1TB Black WD Hard Disk Raid 1
Master Kenobi
Gerbil First Class
 
Posts: 121
Joined: Wed Aug 15, 2007 8:08 am

Re: Track launching of a program

Postposted on Fri Feb 24, 2012 10:15 am

Master Kenobi wrote:Do you simply want to log each time one of your users executes a certain EXE file?
Basically, yes. We also need to track who executed the exe file.
apkellogg
Gerbil Elite
 
Posts: 894
Joined: Wed Feb 25, 2004 9:15 am

Re: Track launching of a program

Postposted on Fri Feb 24, 2012 11:21 am

Simple enough. What operating systems need to be supported?
i7-920 @ 4.20GHz | Biostar Tpower X58 | 4870 1GB | 3x2 DDR3-1600 OCZ Gold Modules | Windows 7 Ultimate x64 | 4x 1TB Black WD Hard Disk Raid 1
Master Kenobi
Gerbil First Class
 
Posts: 121
Joined: Wed Aug 15, 2007 8:08 am

Re: Track launching of a program

Postposted on Fri Feb 24, 2012 11:30 am

Master Kenobi wrote:Simple enough. What operating systems need to be supported?

There are a couple WinXP and a Win2K.
apkellogg
Gerbil Elite
 
Posts: 894
Joined: Wed Feb 25, 2004 9:15 am

Re: Track launching of a program

Postposted on Fri Feb 24, 2012 1:33 pm

Well there are a few options for you depending on your current environment. Obviously a quick google search for Software Metering solutions will net you a plethora of companies that offer full blown products that will do software metering for everything you could think of and handle the report generation process. But there is a cost associated with that, if you can afford them they are always great solutions. However, if you are stuck in the world of no budget and increasing requirements (much like most places I've worked over the years) you will likely want to go with a less robust but quicker to implement method by simply rolling your own scripts/apps in house. Scripts are generally a better bet because you can avoid many corporations Software Development Pipeline/Lifecycle.
If you use Microsoft System Center it supports Software Metering. Details here http://technet.microsoft.com/en-us/libr ... 80750.aspx and here http://www.techrepublic.com/article/loc ... ng/1046803

If you are a smaller organization and lack the servers for it. This can be done in a more quick and dirty way. Both Windows Powershell (Although Win2k isn't supported) and The Windows Script Host (WSH aka VBScript) can handle this task as well. I've whipped up a quick solution for you in vbscript, simply specify the file name and destination name. I've got the data collection to poll the user's computer every 60 seconds for the active process (The EXE file) and store the date/timestamp of the last time it was executed. Each time it changes it will append that to the log file with this format "Username,Date/Time". The log file itself is a CSV formatted file so you can easily slot it into Excel or alternative Spreadsheet programs and do the statistical analysis that way. Hope this helps. The requirements are Win2K or newer and you need to make sure this script runs on the client systems as part of their normal startup process AKA Drop it in Start Menu -> Programs -> Startup or stick it in using Group Policy. Just specify the outputfile to a network share all the users can access and let all the systems append to the same file.
Code: Select all
Option Explicit

Dim WshShell, objFSO, WshNetwork
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshNetwork = WScript.CreateObject("WScript.Network")

Dim strComputer, strProcess, strOutputFile, objFile, strComputerName
Dim strStart, strStartLast, strQuery, X, objWMIService, colProcess, objProcess, strTemp, strUser, strDomain, intRet

'Specify the EXE file to monitor
strProcesss = "cmd.exe"
'Specify the outpue file, it assumes it will be a CSV for easy loading into MSExcel or other Spreadsheet solution.
strOutputFile = "processlog.csv"

'Variable initialization
strComputerName = WshNetwork.ComputerName
strComputer = "." 'Local Computer
strStart = 0

If Not objFSO.FileExists(strOutputFile) Then
   objFSO.CreateTextFile(strOutputFile)
   Set objFile = objFSO.OpenTextFile(strOutputFile, 8)
   objFile.WriteLine("UserName,ExecuteDateTime,ComputerName")
   objFile.Close
End If

X = 1
Do Until X = 0 'Keeps the script running until the user shuts down their computer
   ProcessCheck()
   WScript.Sleep(60000) 'Re-check every 60 seconds
Loop

Sub ProcessCheck
   strQuery = "Select * from Win32_Process where name = '" & strProcess & "'"
   Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
   If objWMIService.ExecQuery(strQuery).Count > 0 Then
      Set colProcess = objWMIService.ExecQuery(strQuery)
      For Each objProcess in colProcess
         strStart = objProcess.CreationDate
         strTemp = Split(strStart, ".")
         strStart = strTemp(0)
         If strStart > strStartLast Then
            intRet = objProcess.GetOwner(strUser, strDomain)
            Log()
            strStartLast = strStart
         End If
      Next
   End If
End Sub

Sub Log
   Set objFile = objFSO.OpenTextFile(strOutputFile, 8)
   objFile.WriteLine(strUser & "," & strStart & "," & strComputerName)
   objFile.Close
End Sub
Last edited by Master Kenobi on Sun Feb 26, 2012 5:12 pm, edited 1 time in total.
i7-920 @ 4.20GHz | Biostar Tpower X58 | 4870 1GB | 3x2 DDR3-1600 OCZ Gold Modules | Windows 7 Ultimate x64 | 4x 1TB Black WD Hard Disk Raid 1
Master Kenobi
Gerbil First Class
 
Posts: 121
Joined: Wed Aug 15, 2007 8:08 am

Re: Track launching of a program

Postposted on Fri Feb 24, 2012 1:54 pm

Master Kenobi,
thank you very much for your help, I have some great things to look in to by the looks of it. For the VBscript, is this something I would make in Visual Basic 2010 Express, compile to an exe and then do all the start up stuff? Never thought to use the word metering in my search terms. Thanks again!

Oh, and as for budget, this is a research lab at a university trying to track equipment use, so yeah pretty small budget.
apkellogg
Gerbil Elite
 
Posts: 894
Joined: Wed Feb 25, 2004 9:15 am

Re: Track launching of a program

Postposted on Fri Feb 24, 2012 2:01 pm

VBScript is uncompiled and handles everything at execution. Simply copy/paste the code into notepad and give the file an extension of VBS.

Example: SoftwareMeter.vbs and double click to start execution much like an EXE file.
i7-920 @ 4.20GHz | Biostar Tpower X58 | 4870 1GB | 3x2 DDR3-1600 OCZ Gold Modules | Windows 7 Ultimate x64 | 4x 1TB Black WD Hard Disk Raid 1
Master Kenobi
Gerbil First Class
 
Posts: 121
Joined: Wed Aug 15, 2007 8:08 am

Re: Track launching of a program

Postposted on Fri Feb 24, 2012 2:04 pm

Master Kenobi wrote:VBScript is uncompiled and handles everything at execution. Simply copy/paste the code into notepad and give the file an extension of VBS.

Example: SoftwareMeter.vbs and double click to start execution much like an EXE file.

Thanks again! This is why I should stop trying to teach myself how to program. Just make headaches for myself.
apkellogg
Gerbil Elite
 
Posts: 894
Joined: Wed Feb 25, 2004 9:15 am

Re: Track launching of a program

Postposted on Fri Feb 24, 2012 9:05 pm

My question is if you use a shared XP login, how exactly can you tell who launches the program? To the system it will be the same user.
Image
The Model M is not for the faint of heart. You either like them or hate them.

Gerbils unite! Fold for UnitedGerbilNation, team 2630.
Flying Fox
Gerbil God
 
Posts: 23533
Joined: Mon May 24, 2004 1:19 am

Re: Track launching of a program

Postposted on Sat Feb 25, 2012 3:30 am

A valid point. I'm not sure from the information he listed if they are currently using a shared login or if they want to go to a shared one based on the usage of the application in question. There are other ways to differentiate the users, like if they map a network share drive to a unique credential I could pull that as well. Another option is if they use email, tie it into their email credentials. Or an even simpler method would be simply to ask the user following the login what their name is. Generally I prefer not to get information from a user whenever possible though.
i7-920 @ 4.20GHz | Biostar Tpower X58 | 4870 1GB | 3x2 DDR3-1600 OCZ Gold Modules | Windows 7 Ultimate x64 | 4x 1TB Black WD Hard Disk Raid 1
Master Kenobi
Gerbil First Class
 
Posts: 121
Joined: Wed Aug 15, 2007 8:08 am

Re: Track launching of a program

Postposted on Sun Feb 26, 2012 12:01 pm

Master Kenobi wrote:A valid point. I'm not sure from the information he listed if they are currently using a shared login or if they want to go to a shared one based on the usage of the application in question. There are other ways to differentiate the users, like if they map a network share drive to a unique credential I could pull that as well. Another option is if they use email, tie it into their email credentials. Or an even simpler method would be simply to ask the user following the login what their name is. Generally I prefer not to get information from a user whenever possible though.


There is one common/shared login for Windows XP, which is the setup we want to keep. Basically, we have a group of equipment that different labs share/use. In order to keep funding for that equipment (for repair, maintenance, upkeep), we need to show that it is being used. Right now, there is just a clip board that each user is supposed to sign so there is a log of usage. As you can imagine, compliance with this is minimal. As each piece of equipment has to be used by running software on an attached PC, the person in charge of the equipment has been looking for a way to log when the software is used. It doesn't need to be anything fancy, just a date/time when the software was started (everyone closes the software when they are done using the equipment) and who started it (or at least which lab they are associated with).
apkellogg
Gerbil Elite
 
Posts: 894
Joined: Wed Feb 25, 2004 9:15 am

Re: Track launching of a program

Postposted on Sun Feb 26, 2012 1:24 pm

So there are multiple computers connected to multiple instances of the same set of equipment that you want to track by which lab/computer uses the software? If this is the case then the script would work, you can even log the info to a centralized file as part of your script.

If it is a single computer with multiple lab users that can launch the program, then you need some unique ID mechanism. If not using Windows accounts you have to prompt for it. Problem with your own prompts and your own mechanism is it is prone to spoofing and that you are reinventing the wheel when the OS has this figured out already.
Image
The Model M is not for the faint of heart. You either like them or hate them.

Gerbils unite! Fold for UnitedGerbilNation, team 2630.
Flying Fox
Gerbil God
 
Posts: 23533
Joined: Mon May 24, 2004 1:19 am

Re: Track launching of a program

Postposted on Sun Feb 26, 2012 5:05 pm

Agreed. I don't know about which lab they are associated with, but I can add in a couple lines of code that will give you the workstation's name. I assume you guys use unique computer names on the network.

I have updated the original script accordingly.
i7-920 @ 4.20GHz | Biostar Tpower X58 | 4870 1GB | 3x2 DDR3-1600 OCZ Gold Modules | Windows 7 Ultimate x64 | 4x 1TB Black WD Hard Disk Raid 1
Master Kenobi
Gerbil First Class
 
Posts: 121
Joined: Wed Aug 15, 2007 8:08 am

Re: Track launching of a program

Postposted on Sun Feb 26, 2012 5:07 pm

Flying Fox wrote:So there are multiple computers connected to multiple instances of the same set of equipment that you want to track by which lab/computer uses the software? If this is the case then the script would work, you can even log the info to a centralized file as part of your script.

If it is a single computer with multiple lab users that can launch the program, then you need some unique ID mechanism. If not using Windows accounts you have to prompt for it. Problem with your own prompts and your own mechanism is it is prone to spoofing and that you are reinventing the wheel when the OS has this figured out already.


Actually, there are multiple pieces of equipment, each with its own PC. Not to worried about spoofing, as this isn't meant to be high security or for any billing info. Even some kind of drop box with a list of labs could work.

Actually, thinking about it now, if we changed the login from the simple login screen to the one where you have to type the name of the user in, we could have everyone log in using the common one while listing each lab as a "user" in windows. In this case, would it be possible to create a script that prompts the user to select one of the Windows users (just to select from a set of names) and add that to the log? I assume I could modify the script to then only append the log when the process create/start date/time is different than the last entry in the log.
apkellogg
Gerbil Elite
 
Posts: 894
Joined: Wed Feb 25, 2004 9:15 am

Re: Track launching of a program

Postposted on Sun Feb 26, 2012 5:18 pm

In this case, would it be possible to create a script that prompts the user to select one of the Windows users (just to select from a set of names) and add that to the log?

I've updated the script so that it will track each physical computer's name as part of the logging process. To prompt for a username is certainly an easy task you do end up with people potentially placing in false answers. I'd have to agree with Flying Fox that prompts to users are generally more trouble than they are worth for background programs.

I assume I could modify the script to then only append the log when the process create/start date/time is different than the last entry in the log.

This is how the script currently behaves. Until the application is closed and relaunched it won't be appending any additional data, it merely runs in the background and monitors silently.
i7-920 @ 4.20GHz | Biostar Tpower X58 | 4870 1GB | 3x2 DDR3-1600 OCZ Gold Modules | Windows 7 Ultimate x64 | 4x 1TB Black WD Hard Disk Raid 1
Master Kenobi
Gerbil First Class
 
Posts: 121
Joined: Wed Aug 15, 2007 8:08 am

Re: Track launching of a program

Postposted on Sun Feb 26, 2012 8:54 pm

I wonder if this violates any user rights to privacy?

How many other 3rd party apps do we use on a daily basis that do something of this nature?

The developer in me likes the concept of metrics. But the end-user in me, dislikes it! :)
thegleek
Darth Gerbil
 
Posts: 7312
Joined: Tue Jun 10, 2003 10:06 am
Location: Detroit, MI

Re: Track launching of a program

Postposted on Mon Feb 27, 2012 9:50 am

Master Kenobi,
I modified your code slightly, attempting to change the UTC date into a normal date,time and writing those to the log file instead. I made the change in the Sub Log portion of the code. Did I make this modification correctly? Also, is there a way to state the directory I want the log file created in? Thank you.

Code: Select all
Option Explicit

Dim WshShell, objFSO, WshNetwork
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshNetwork = WScript.CreateObject("WScript.Network")

Dim strComputer, strProcess, strOutputFile, objFile, strComputerName
Dim strStart, strStartLast, strQuery, X, objWMIService, colProcess, objProcess, strTemp, strUser, strDomain, intRet
Dim strDate, strTime

'Specify the EXE file to monitor
strProcesss = "cmd.exe"
'Specify the output file, it assumes it will be a CSV for easy loading into MSExcel or other Spreadsheet solution.
strOutputFile = "processlog.csv"

'Variable initialization
strComputerName = WshNetwork.ComputerName
strComputer = "." 'Local Computer
strStart = 0

If Not objFSO.FileExists(strOutputFile) Then
   objFSO.CreateTextFile(strOutputFile)
   Set objFile = objFSO.OpenTextFile(strOutputFile, 8)
   objFile.WriteLine("UserName,ExecuteDate,ExecuteTime,ComputerName,UTC")
   objFile.Close
End If

X = 1
Do Until X = 0 'Keeps the script running until the user shuts down their computer
   ProcessCheck()
   WScript.Sleep(60000) 'Re-check every 60 seconds
Loop

Sub ProcessCheck
   strQuery = "Select * from Win32_Process where name = '" & strProcess & "'"
   Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
   If objWMIService.ExecQuery(strQuery).Count > 0 Then
      Set colProcess = objWMIService.ExecQuery(strQuery)
      For Each objProcess in colProcess
         strStart = objProcess.CreationDate
         strTemp = Split(strStart, ".")
         strStart = strTemp(0)
         If strStart > strStartLast Then
            intRet = objProcess.GetOwner(strUser, strDomain)
            Log()
            strStartLast = strStart
         End If
      Next
   End If
End Sub

Sub Log
   Set objFile = objFSO.OpenTextFile(strOutputFile, 8)
   strDate=CDate(Mid(strStart,5,2) & "/" & Mid(strStart,7,2) & "/" & Left(strStart,4))
   StrTime=CDate(Mid(strStart,9,2) & ":" & Mid(strStart,11,2) & ":" & Mid(strStart,13,2))
   objFile.WriteLine(strUser & "," & strDate & "," & strTime & "," & strComputerName & "," & strStart)
   objFile.Close
End Sub
apkellogg
Gerbil Elite
 
Posts: 894
Joined: Wed Feb 25, 2004 9:15 am

Re: Track launching of a program

Postposted on Mon Feb 27, 2012 3:52 pm

Also, is there a way to state the directory I want the log file created in?

Just change the value here, the value is set up to be a path/file. It can be something like this or this.
Code: Select all
strOutputFile = "C:\Program Files\Stuff\processlog.csv"

Code: Select all
strOutputFile = "\\server1\test\Stuff\processlog.csv"


I noticed a typo in one of the variables. I've corrected it in this code piece. But otherwise, yes your modification should work, it tested fine on my system here.
Code: Select all
Option Explicit

Dim WshShell, objFSO, WshNetwork
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshNetwork = WScript.CreateObject("WScript.Network")

Dim strComputer, strProcess, strOutputFile, objFile, strComputerName
Dim strStart, strStartLast, strQuery, X, objWMIService, colProcess, objProcess, strTemp,

strUser, strDomain, intRet
Dim strDate, strTime

'Specify the EXE file to monitor
strProcess = "cmd.exe"
'Specify the output file, it assumes it will be a CSV for easy loading into MSExcel or other

Spreadsheet solution.
strOutputFile = "processlog.csv"

'Variable initialization
strComputerName = WshNetwork.ComputerName
strComputer = "." 'Local Computer
strStart = 0

If Not objFSO.FileExists(strOutputFile) Then
   objFSO.CreateTextFile(strOutputFile)
   Set objFile = objFSO.OpenTextFile(strOutputFile, 8)
   objFile.WriteLine("UserName,ExecuteDate,ExecuteTime,ComputerName,UTC")
   objFile.Close
End If

X = 1
Do Until X = 0 'Keeps the script running until the user shuts down their computer
   ProcessCheck()
   WScript.Sleep(60000) 'Re-check every 60 seconds
Loop

Sub ProcessCheck
   strQuery = "Select * from Win32_Process where name = '" & strProcess & "'"
   Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" &

strComputer & "\root\cimv2")
   If objWMIService.ExecQuery(strQuery).Count > 0 Then
      Set colProcess = objWMIService.ExecQuery(strQuery)
      For Each objProcess in colProcess
         strStart = objProcess.CreationDate
         strTemp = Split(strStart, ".")
         strStart = strTemp(0)
         If strStart > strStartLast Then
            intRet = objProcess.GetOwner(strUser, strDomain)
            Log()
            strStartLast = strStart
         End If
      Next
   End If
End Sub

Sub Log
   Set objFile = objFSO.OpenTextFile(strOutputFile, 8)
   strDate=CDate(Mid(strStart,5,2) & "/" & Mid(strStart,7,2) & "/" & Left(strStart,4))
   StrTime=CDate(Mid(strStart,9,2) & ":" & Mid(strStart,11,2) & ":" & Mid(strStart,13,2))
   objFile.WriteLine(strUser & "," & strDate & "," & strTime & "," & strComputerName & "," &

strStart)
   objFile.Close
End Sub
i7-920 @ 4.20GHz | Biostar Tpower X58 | 4870 1GB | 3x2 DDR3-1600 OCZ Gold Modules | Windows 7 Ultimate x64 | 4x 1TB Black WD Hard Disk Raid 1
Master Kenobi
Gerbil First Class
 
Posts: 121
Joined: Wed Aug 15, 2007 8:08 am

Re: Track launching of a program

Postposted on Mon Feb 27, 2012 4:07 pm

Master Kenobi wrote:
Also, is there a way to state the directory I want the log file created in?

Just change the value here, the value is set up to be a path/file. It can be something like this or this.

I noticed a typo in one of the variables. I've corrected it in this code piece. But otherwise, yes your modification should work, it tested fine on my system here.

Just wanted to let you know that I have started using this on some of the computers in question. So far, everything seems to be working. Now we are just going to let it run and see how it works. Thank you for all of your help.
apkellogg
Gerbil Elite
 
Posts: 894
Joined: Wed Feb 25, 2004 9:15 am


Return to Windows

Who is online

Users browsing this forum: No registered users and 5 guests