ok so i use google to be able to get things done.
i have a need where i need to look through a txt file to the last line and then pull out what is behind the = sign...which is a user name... and place it into a reg key.
well my code works BUT...
last line if does not have a = it doesnt get what i want.
how would i have it go backwards up a line looking and keep going until it finds the line with it...
fyi the app is Transparent Screen Lock Pro. an app we use to lock screens on machines....
so when you unlock the screen it puts in user name.. however after 15 minutes (our setting) it then locks screen adding a line into the txt file messing it up for me. was working great while testing as i was the last one to unlock the screen. i just didnt account for this.. hah
any help appreciated..
sample lock file...
i have a need where i need to look through a txt file to the last line and then pull out what is behind the = sign...which is a user name... and place it into a reg key.
well my code works BUT...
last line if does not have a = it doesnt get what i want.
how would i have it go backwards up a line looking and keep going until it finds the line with it...
fyi the app is Transparent Screen Lock Pro. an app we use to lock screens on machines....
so when you unlock the screen it puts in user name.. however after 15 minutes (our setting) it then locks screen adding a line into the txt file messing it up for me. was working great while testing as i was the last one to unlock the screen. i just didnt account for this.. hah
any help appreciated..
Code:
'===========Find user from log file================= Dim fso, file, temp, lastLine, segments, pstr Set fso = CreateObject("Scripting.FileSystemObject") If fso.FileExists("c:\btop\logs\tslp6_log\Transparent Screen Lock File.txt") then Set file = fso.OpenTextFile("c:\btop\logs\tslp6_log\Transparent Screen Lock File.txt",1) Else If fso.FileExists("c:\Program Files\Transparent Screen Lock PRO\Transparent Screen Lock File.txt") then Set file = fso.OpenTextFile("c:\Program Files\Transparent Screen Lock PRO\Transparent Screen Lock File.txt",1) Else Wscript.Quit() End If End If temp = split(file.readall,vbcrlf) x = 0 do until temp(Ubound(temp) - x) <> "" x = x + 1 loop lastline = temp(ubound(temp)-x) segments = Split(lastline,"=") pstr = segments(1) segments = Split(pstr," ") pstr = segments(1) '===========/Find user from log file================ '===========Set OS Bit================ Dim WshShell, myKey, strSubKeyPath Const HKEY_LOCAL_MACHINE = &H80000002 '===========Set 32 or 64bit Reg Key================= Set WshShell = CreateObject("WScript.Shell") OsType = WshShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE") If OsType = "x86" then strSubKeyPath = "HKLM\SOFTWARE\BMSLCS\Lab-Labacct" elseif OsType = "AMD64" then strSubKeyPath = "HKLM\SOFTWARE\Wow6432Node\BMSLCS\Lab-Labacct" end if '===========/Set 32 or 64bit Reg Key================ '===========Write Key=============================== WshShell.RegWrite strSubKeyPath, pstr, "REG_SZ" '===========/Write Key==============================
sample lock file...
Code:
07/09/2016 08:38:17AM - TEST-WIN7X32@NT AUTHORITY - Computer Locked 07/09/2016 08:38:29AM - TEST-WIN7X32@NT AUTHORITY - Computer Unlocked - UserName = User1 Domain= MyDomain 07/09/2016 08:38:39AM - TEST-WIN7X32@MyDomain - Computer Locked 07/09/2016 08:53:33AM - TEST-WIN7X32@NT AUTHORITY - Computer Locked 07/09/2016 09:34:12AM - TEST-WIN7X32@NT AUTHORITY - Computer Unlocked - UserName = User1 Domain= MyDomain 07/09/2016 09:34:38AM - TEST-WIN7X32@MyDomain - Computer Locked 23/09/2016 09:18:17AM - TEST-WIN7X32@MyDomain - Computer Locked 14/10/2016 07:29:35AM - TEST-WIN7X32@MyDomain - Computer Unlocked - UserName = User1 Domain= MyDomain 14/10/2016 07:46:22AM - TEST-WIN7X32@MyDomain - Computer Locked 19/10/2016 09:56:06AM - TEST-WIN7X32@MyDomain - Computer Locked 03/11/2016 08:31:43AM - TEST-WIN7X32@MyDomain - Computer Unlocked - UserName = User1 Domain= MyDomain 03/11/2016 08:55:18AM - TEST-WIN7X32@MyDomain - Computer Locked 03/11/2016 09:08:18AM - TEST-WIN7X32@MyDomain - Invalid Logon: Bad username/password combination for UserName: User1. 03/11/2016 09:08:21AM - TEST-WIN7X32@MyDomain - Computer Unlocked - UserName = User1 Domain= MyDomain 03/11/2016 09:23:34AM - TEST-WIN7X32@MyDomain - Computer Locked 03/11/2016 09:35:01AM - TEST-WIN7X32@MyDomain - Computer Unlocked - UserName = User1 Domain= MyDomain 03/11/2016 09:41:18AM - TEST-WIN7X32@MyDomain - Computer Locked 03/11/2016 11:30:15AM - TEST-WIN7X32@MyDomain - Computer Unlocked - UserName = User1 Domain= MyDomain 03/11/2016 11:46:59AM - TEST-WIN7X32@MyDomain - Computer Locked 04/11/2016 08:02:55AM - TEST-WIN7X32@MyDomain - Computer Unlocked - UserName = User1 Domain= MyDomain 04/11/2016 08:20:11AM - TEST-WIN7X32@MyDomain - Computer Locked 04/11/2016 09:54:00AM - TEST-WIN7X32@MyDomain - Invalid Logon: Bad username/password combination for UserName: User1. 04/11/2016 09:54:05AM - TEST-WIN7X32@MyDomain - Computer Unlocked - UserName = User1 Domain= MyDomain 04/11/2016 10:10:28AM - TEST-WIN7X32@MyDomain - Computer Locked 04/11/2016 02:35:40PM - TEST-WIN7X32@MyDomain - Computer Unlocked - UserName = User1 Domain= MyDomain 04/11/2016 02:50:38PM - TEST-WIN7X32@MyDomain - Computer Locked 10/11/2016 01:22:13PM - TEST-WIN7X32@MyDomain - Computer Unlocked - UserName = User1 Domain= MyDomain 10/11/2016 01:38:43PM - TEST-WIN7X32@MyDomain - Computer Locked 11/11/2016 08:01:14AM - TEST-WIN7X32@MyDomain - Computer Unlocked - UserName = User1 Domain= MyDomain 11/11/2016 08:18:46AM - TEST-WIN7X32@MyDomain - Computer Locked 15/11/2016 12:09:04PM - TEST-WIN7X32@MyDomain - Computer Locked 22/11/2016 10:57:00AM - TEST-WIN7X32@MyDomain - Computer Unlocked - UserName = User1 Domain= MyDomain 22/11/2016 11:13:47AM - TEST-WIN7X32@MyDomain - Computer Locked 03/01/2017 08:59:03AM - TEST-WIN7X32@MyDomain - Computer Locked 09/01/2017 11:40:07AM - TEST-WIN7X32@MyDomain - Computer Unlocked - UserName = User1 Domain= MyDomain 09/01/2017 12:14:02PM - TEST-WIN7X32@MyDomain - Computer Locked 03/02/2017 11:13:55AM - TEST-WIN7X32@MyDomain - Computer Unlocked - UserName = User1 Domain= MyDomain 03/02/2017 11:31:56AM - TEST-WIN7X32@MyDomain - Computer Locked 03/02/2017 03:09:21PM - TEST-WIN7X32@MyDomain - Computer Unlocked - UserName = User1 Domain= MyDomain 03/02/2017 03:25:07PM - TEST-WIN7X32@MyDomain - Computer Locked 06/02/2017 07:36:25AM - TEST-WIN7X32@MyDomain - Computer Unlocked - UserName = User1 Domain= MyDomain 06/02/2017 07:54:53AM - TEST-WIN7X32@MyDomain - Computer Locked 06/02/2017 10:40:08AM - TEST-WIN7X32@MyDomain - Computer Unlocked - UserName = User1 Domain= MyDomain 06/02/2017 10:55:09AM - TEST-WIN7X32@MyDomain - Computer Locked 07/02/2017 09:18:05AM - TEST-WIN7X32@MyDomain - Computer Unlocked - UserName = User1 Domain= MyDomain 07/02/2017 09:34:57AM - TEST-WIN7X32@MyDomain - Computer Locked 09/02/2017 11:17:24AM - TEST-WIN7X32@MyDomain - Computer Unlocked - UserName = User1 Domain= MyDomain 09/02/2017 11:33:41AM - TEST-WIN7X32@MyDomain - Computer Locked 10/02/2017 03:32:11PM - TEST-WIN7X32@MyDomain - Computer Unlocked - UserName = User1 Domain= MyDomain 10/02/2017 03:47:28PM - TEST-WIN7X32@MyDomain - Computer Locked 10/02/2017 03:47:28PM - TEST-WIN7X32@MyDomain - Computer Locked 10/02/2017 03:47:28PM - TEST-WIN7X32@MyDomain - Computer Locked 10/02/2017 03:47:28PM - TEST-WIN7X32@MyDomain - Computer Locked
Comment