Sign in to follow this  
Followers 0
DavidLago

Script to Logoff from a server, check session time and create logs

7 posts in this topic

Hello.

The tittle says it all.

I want to create a script that will be compiled and post into the folder "C:\.....\All Users\Desktop" for all users to make use of it.

The script must:

1. Create logs of the Logoff Date/Time and User, and Do the math (using the Session Time) to discover when was the logon.

2. Check if MS Word is on and kill it (once its known that it makes the logoff request fail)

3. Logoff

Here's what I have done so far:

Sleep(500)

#include <NetShare.au3>
Global $PathLOG = "\\LogServer\SERVER\_LOGS\"
If Not FileExists($PathLOG & "LogoffLog.log") Then
FileWriteLine($PathLOG & "LogoffLog.log", "###########################################################################")
FileWriteLine($PathLOG & "LogoffLog.log", "########                      LOGOFF LOG SCRIPT                    ########")
FileWriteLine($PathLOG & "LogoffLog.log", "###########################################################################")
EndIf

FileWriteLine($PathLOG & "LogoffLog.log", "                                                                          ")
FileWriteLine($PathLOG & "LogoffLog.log", "                                                                          ")
FileWriteLine($PathLOG & "LogoffLog.log", " =========================================================================")
FileWriteLine($PathLOG & "LogoffLog.log", " === " & @ComputerName & " === " & @MDAY & "/" & @MON & "/" & @YEAR & " - " & @HOUR & ":" & @MIN & ":" & @SEC & "  =============== user: " & @UserName & "" & @CRLF & " =========================================================================")
FileWriteLine($PathLOG & "LogoffLog.log", " === " & " Event: Logoff")
FileWriteLine($PathLOG & "LogoffLog.log", " =========================================================================" & @CRLF & " =========================================================================")
FileWriteLine($PathLOG & "LogoffLog.log", "                                                                          ")

Sleep(500)

If Not ProcessExists("winword.exe") Then
Shutdown(16)
Else
ProcessClose("winword.exe") ; or ; RunWait(cmd.exe c  & tskill winwor,@ScriptDir,@SW_HIDE)
RunWait("cmd.exe" & " /c " & @SystemDir & "logoff.exe", @SystemDir, @SW_HIDE) ; or Shutdown(16)
EndIf

Does anyone have an idea how to get the session time?


Just a server analyst that has never been into programming that much. So, small fish here :)

Share this post


Link to post
Share on other sites



Anyone?

Danm... Why I just came up with the most unusual questions, enough to have no response at a high level forum :/


Just a server analyst that has never been into programming that much. So, small fish here :)

Share this post


Link to post
Share on other sites

Is the server yours? If yes, you could write some PHP in order to show you the logout time on the logout page.

Share this post


Link to post
Share on other sites

Is the server yours? If yes, you could write some PHP in order to show you the logout time on the logout page.

No, it's the enterprises, but I am a domain admin. But we got 3 shifts, with 3 domain admins each. It would be good to track down whenever we login and logout of servers.


Just a server analyst that has never been into programming that much. So, small fish here :)

Share this post


Link to post
Share on other sites

Have you tried looking at the Security Event Logs to see when someone logs on and off the server? If that's any help, use the _EventLog_xx functions to read these log files.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Have you tried looking at the Security Event Logs to see when someone logs on and off the server? If that's any help, use the _EventLog_xx functions to read these log files.

Hey Brewman! That was a good idea, but unfortunately, Windows EventViewer has once again disappointed me with the lack of information on their logs. The logoff event doesn't show the user session time.

I was thinking that the script wouldn't be able to create a logoff event, read it and FileWriteLine on a network located file. After he created the Logoff event, nothing would work anymore... So, that's probably not an option.

I'm starting to think that it would be better for me to go on with this script without the session time info :P


Just a server analyst that has never been into programming that much. So, small fish here :)

Share this post


Link to post
Share on other sites

You could look for when they logged onto the system, and then when they logged off from it, and with a little math (or _DateDiff), you could calculate the session time.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0