www.homeseer.com    
 

Go Back   HomeSeer Message Board > General Home Automation > Off Topic

Off Topic Post your jokes, funny stories, current events and antecdotes here.

Reply
 
Thread Tools Display Modes
  #1  
Old February 13th, 2017, 10:54 AM
TeleFragger's Avatar
TeleFragger TeleFragger is offline
OverSeer
 
Join Date: Jun 2004
Location: Williamstown, NJ
Posts: 4,623
vbscript help....

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

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
__________________
HW - i5 4570T @2.9ghz runs @11w | 8gb ram | 128gb ssd OS - Win10 x64

HS - HS3 Pro Edition 3.0.0.344

Plugins - BLLAN 2.0.35.0 | BLRF 2.0.91.0 | Concord 4 3.1.13.7 | FitbitSeer 0.2.0.0 | HSTouch Server 3.0.0.68 | RFXCOM 30.0.0.35 | X10 3.0.0.36 | Z-Wave 3.0.1.130

Hardware - EdgePort/4 DB9 Serial | RFXCOM 433MHz USB Transceiver | Superbus 2000 for Concord 4 | TI103 X-10 Interface | WGL Designs W800 RF | Z-Troller Z-Wave Interface
Reply With Quote
  #2  
Old February 14th, 2017, 01:00 AM
zwolfpack zwolfpack is online now
Seer Master
 
Join Date: Sep 2015
Location: Orange County, California, USA
Posts: 638
Try replacing
Code:
x = 0  
do until temp(Ubound(temp) - x) <> ""
    x = x + 1  
loop  
lastline = temp(ubound(temp)-x)
with
Code:
x = Ubound(temp)  
do while x >= 0 and instr(temp(x), "=") is Nothing 
    x = x - 1  
loop  
lastline = temp(x)
I'm not a VB coder; "is Nothing" might need to be "= Nothing".
Also if its possible that there are no lines containing "=", you should test for that.

Last edited by zwolfpack; February 14th, 2017 at 01:11 AM.
Reply With Quote
  #3  
Old February 14th, 2017, 09:49 AM
TeleFragger's Avatar
TeleFragger TeleFragger is offline
OverSeer
 
Join Date: Jun 2004
Location: Williamstown, NJ
Posts: 4,623
hmmm object required error - code 800A01A8
Reply With Quote
  #4  
Old February 14th, 2017, 12:14 PM
zwolfpack zwolfpack is online now
Seer Master
 
Join Date: Sep 2015
Location: Orange County, California, USA
Posts: 638
try changing "is Nothing" to " = 0"
Code:
x = Ubound(temp)   
do while x >= 0 and instr(temp(x), "=") = 0      
    x = x - 1   
loop   
lastline = temp(x)
the idea is to search for the last line containing an "=" rather than the last non-blank line.
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
VBScript help chewie HomeSeer General Discussion Area 3 June 4th, 2013 05:47 PM
VBscript to VB Net jbbtex Programming with HomeSeer 0 March 15th, 2012 10:47 PM
Help on Vbscript frichmond1 Programming with HomeSeer 3 September 20th, 2011 10:58 PM
Help with asp vbscript supergee Web Server and Interface 12 April 13th, 2005 03:09 PM
vbscript guedelmalin Script & Plug-In Development 2 April 2nd, 2004 10:41 AM


All times are GMT -4. The time now is 12:44 AM.


Copyright HomeSeer Technologies, LLC