Logon script

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
frederixx
Posts: 9
Joined: 06 Jun 2013 13:05

Logon script

#1 Post by frederixx » 13 Nov 2013 09:27

Hi,

I have a logon script to monitor all the logins. I have 2 things that i couldn't get to work properly.

Here's my script:

echo %date%,%time%,%computername%,%username%,%sessionname%,%logonserver% >> \\domain\Logon\LOGON.LOG
REG QUERY "HKEY_CURRENT_USER\Volatile Environment\ViewClient_Machine_Name">> \\domain\Logon\LOGON.LOG

1: The first part works OK, but sometimes it will randomly erase the file content and start all over again.

2: Second part; I'm trying to get a key from registry to get the inventory names of the terminals (VDI). Then again, it works alright, but i'm getting too much info out of it. I would like to get only the TRMxxxxx part and not what comes before it.

! REG.EXE VERSION 3.0
HKEY_CURRENT_USER\Volatile Environment
ViewClient_Machine_Name REG_SZ TRM12345

Thank you

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Logon script

#2 Post by foxidrive » 13 Nov 2013 09:55

frederixx wrote:Here's my script:

echo %date%,%time%,%computername%,%username%,%sessionname%,%logonserver% >> \\domain\Logon\LOGON.LOG
REG QUERY "HKEY_CURRENT_USER\Volatile Environment\ViewClient_Machine_Name">> \\domain\Logon\LOGON.LOG

1: The first part works OK, but sometimes it will randomly erase the file content and start all over again.

Nothing in the batch file above will do that.

2: Second part; I'm trying to get a key from registry to get the inventory names of the terminals (VDI). Then again, it works alright, but i'm getting too much info out of it. I would like to get only the TRMxxxxx part and not what comes before it.

! REG.EXE VERSION 3.0
HKEY_CURRENT_USER\Volatile Environment
ViewClient_Machine_Name REG_SZ TRM12345


Use a for /f loop and tokens=3 along with find.exe to filter on the REG_SZ line, to echo the value.

frederixx
Posts: 9
Joined: 06 Jun 2013 13:05

Re: Logon script

#3 Post by frederixx » 13 Nov 2013 10:19

foxidrive wrote:
frederixx wrote:Here's my script:

echo %date%,%time%,%computername%,%username%,%sessionname%,%logonserver% >> \\domain\Logon\LOGON.LOG
REG QUERY "HKEY_CURRENT_USER\Volatile Environment\ViewClient_Machine_Name">> \\domain\Logon\LOGON.LOG

1: The first part works OK, but sometimes it will randomly erase the file content and start all over again.

Nothing in the batch file above will do that.

2: Second part; I'm trying to get a key from registry to get the inventory names of the terminals (VDI). Then again, it works alright, but i'm getting too much info out of it. I would like to get only the TRMxxxxx part and not what comes before it.

! REG.EXE VERSION 3.0
HKEY_CURRENT_USER\Volatile Environment
ViewClient_Machine_Name REG_SZ TRM12345


Use a for /f loop and tokens=3 along with find.exe to filter on the REG_SZ line, to echo the value.


If i get this correctly, i can only get rid of the last line? I'd also like to remove the first 2 lines from my logon.log:
! REG.EXE VERSION 3.0
HKEY_CURRENT_USER\Volatile Environment

Thank you

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Logon script

#4 Post by foxidrive » 13 Nov 2013 10:27

Do you know how find.exe works? Or findstr.exe?

frederixx
Posts: 9
Joined: 06 Jun 2013 13:05

Re: Logon script

#5 Post by frederixx » 13 Nov 2013 10:34

foxidrive wrote:Do you know how find.exe works? Or findstr.exe?


No.

But from what i understand, it will filter my log file afterwards and won't prevent all the lines to show up in it.

Thanks

Post Reply