Announcement

Collapse
No announcement yet.

Server Logoff Script

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Server Logoff Script

    Hi,

    Our support center manages multiple servers.

    Now what we want is that when a Admin Logs off that a script will run and asks what the reason was to enter the server and what his actions where.

    This so that we always can look back what has been done.

    Is it possible to write this into a text file or something like that? maybe even e-mail it.

    I know i have to create a script and put in in the Group Policy (gpedit.msc) as loggoff script but i don't know how to write such a script.

  • #2
    Re: Server Logoff Script

    Is all your server work not carried out under Change Control Procedures? I can tell you how often you will find "." written in your text file if you like... People will not fill in the text and they will get very annoyed.

    You are better to look at ITIL based Change, Incident and Problem Management and then all work is properly recorded centrally rather than in a text file on each server.


    Tom
    For my own and your protection, I do not provide support by private message under any circumstances. All such messages will be deleted and ignored.

    Anything you say will be misquoted and used against you

    Comment


    • #3
      Re: Server Logoff Script

      Hi,

      Ok first of all thanks for the efford but i found a solution myself.

      By a vb script i managed exacly what i want and the sendmail script on this site was also a great help... Thanks for that!!

      Comment


      • #4
        Re: Server Logoff Script

        Hi danny,

        Mind sharing what the script you use look like?

        There are several ways to ask the user for input using a vbscript.
        I think three sequential inputboxes will do fine,
        - popup 1: inputbox asked for person's name
        - popup 2: inputbox asked or purpose for logging on
        - popup 3: inputbox asked for changes if there were made.
        > Then the scripts can add also a date and computername to the log.
        All the output can be written to one message/file.


        VBScript To Send Email Using CDO


        \Rems



        EDIT -

        Or..., you could also choose for one less strict approach.
        Just opening one simple logfile for appending, and save changes each time.

        Here is an example how to create a simple logfile (with a little fun);
        Code:
        'DoWhenLoggingOff.vbs
        'http://forums.petri.com/showthread.php?t=17013
        
        sOutFile = "c:\Captains Log ?yy-?mm ?computername.txt"
        
        '// Use variables-> '?yy' or+ '?mm' or+ '?dd'  ,_ 
        '//       to create resp. a yearly, monthly or daily new report.
        '//
        '// Use variable-> ?computername to add the name of the computer.
        '//
        '// (these strings will automatically filled-in by the script)
        '
        '
        ' The path to this script must be local (or on a UNC-path) and 
        '   readable for 'everyone' and the 'system'.
        ' The path to the log-file must be local (or on a UNC-path) and 
        '   readable for 'everyone' and the 'system'.
        
        '------------------------------Start Script-----------------------------
        'On Error Resume Next
        
        Const ForAppending = 8
        
        strEditor = "WordPad.exe"   '<-- incl. exe-extension !!!
        strComputer = WScript.CreateObject("WScript.Network").ComputerName
        
        sOutFile = replace(LCase(sOutFile),"?yy",Year(date))
        sOutFile = replace(LCase(sOutFile),"?mm",month(date))
        sOutFile = replace(LCase(sOutFile),"?dd",day(date))
        sOutFile = replace(LCase(sOutFile),"?computername",strComputer)
        
        With WScript.CreateObject("Scripting.FileSystemObject")
         With .OpenTextFile(sOutFile, ForAppending, True):.close:End With
         strProc = .GetFileName(sOutFile) &" - "& Replace(strEditor,".exe","")
        End With
        set WshShell = WScript.CreateObject("WScript.Shell")
        Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
                     & strComputer & "\root\cimv2")
          wmiQuery = "Select * From Win32_Process Where " _
                     & "Name = '" & strEditor & "'" 
          Set colItems = objWMI.ExecQuery(wmiQuery)
           For Each objProcess in colItems
            objProcess.Terminate()
           Next
        
        If (Err.Number) Then wscript.quit
        sReturn = WshShell.Run(strEditor&" "&chr(34)&sOutFile&chr(34))
        If sReturn = 0 Then
           Comment(strProc)
           timeCycle(30) 'seconds before first popup
        End If
        WshShell.AppActivate strProc
        If WshShell.AppActivate(strProc) then WshShell.SendKeys "{ESC}^(s)"
        wscript.sleep 200
        
        'wmiQuery = "Select * From Win32_ProcessStopTrace Where " _
        '             & "ProcessName = '" & strEditor & "'"
        'Set colItems = objWMI.ExecNotificationQuery(wmiQuery)
        ' Do
        '   If (Err.Number) Then wscript.quit
        '   Set objItem = colItems.NextEvent
        '   Exit Do
        ' Loop
        
        Set colItems = objWMI.ExecQuery(wmiQuery)
           For Each objProcess in colItems
            objProcess.Terminate()
           Next
        
        wscript.sleep 600
        WshShell.popup "Thank you", 1'second
        Set objWMI = Nothing
        set WshShell = Nothing
        Wscript.Quit
        
        
        '|///////////////////////////////////////|
        sub Comment(strProc)
        
        theString= "             : Write log here ...!"
        
        '   On Error Resume Next
           Set oRE = New Regexp 
           oRE.Pattern = ".":oRE.Global = True
           Set colMatches = oRE.Execute(theString)
           With WScript.CreateObject("WScript.Shell")
            WScript.Sleep 1000 'wait till workpad file is opened
            .AppActivate strProc
             If .AppActivate(strProc) then .SendKeys "----------------------"
            .AppActivate strProc
             If .AppActivate(strProc) then .SendKeys "----------------------"
            .AppActivate strProc
             If .AppActivate(strProc) then .SendKeys "----------------------"
            .AppActivate strProc:If .AppActivate(strProc) then .SendKeys "~"
            .AppActivate strProc
             If .AppActivate(strProc) then .SendKeys "Administrators event"
            .AppActivate strProc
             If .AppActivate(strProc) then .SendKeys " "& date() &"/"& time()
            .AppActivate strProc:If .AppActivate(strProc) then .SendKeys "~"
            .AppActivate strProc:If .AppActivate(strProc) then .SendKeys "~"
            .AppActivate strProc:If .AppActivate(strProc) then .SendKeys "~"
            .AppActivate strProc:If .AppActivate(strProc) then .SendKeys "~"
            .AppActivate strProc:If .AppActivate(strProc) then .SendKeys "~"
            n=3
            .AppActivate strProc
             If .AppActivate(strProc) then .SendKeys "{Up 3}"
        
          For Each oMatch In colMatches
            n=n+1
            WScript.Sleep 10
            .AppActivate strProc
             If .AppActivate(strProc) then .SendKeys oMatch.Value 
          Next
        
           .AppActivate strProc
            If .AppActivate(strProc) then .SendKeys "{HOME}"
           WScript.Sleep 500
        
           Do until n=0
           .AppActivate strProc
            If .AppActivate(strProc) then .SendKeys "{RIGHT}{BS}"
            n=n-1
            WScript.Sleep 5
           Loop
        
           .AppActivate strProc
            If .AppActivate(strProc) then .SendKeys "{Up 1}"
           .AppActivate strProc
            If .AppActivate(strProc) then .SendKeys "Your name    : "
           .AppActivate strProc:If .AppActivate(strProc) then .SendKeys "~"
           .AppActivate strProc
            If .AppActivate(strProc) then .SendKeys "Logon Purpose: "
           .AppActivate strProc:If .AppActivate(strProc) then .SendKeys "~"
           .AppActivate strProc
            If .AppActivate(strProc) then .SendKeys "Activities   : "
           .AppActivate strProc:If .AppActivate(strProc) then .SendKeys "~"
           .AppActivate strProc
            If .AppActivate(strProc) then .SendKeys "{ESC}^(s)"
           'set cursor
           .AppActivate strProc
            If .AppActivate(strProc) then .SendKeys "^({Home}){Down 2}{End}"
           End With
        End Sub
        '|///////////////////////////////////////|
        
        
        Sub timeCycle(sTime)
          If sTime < 5 then sTime = 5
          cTime=4:sTime=sTime*1000:i=1
          Do Until cTime=0
            wscript.sleep sTime
            intReturn=WScript.CreateObject("WScript.Shell").popup _
            (vbNewLine&"   Save and Exit now ?" _
              ,3,"Logoff",4+256+48+4096)
            If (intReturn =  6) Then
             Exit Do
            ElseIf (intReturn =  7) Then
             sTime = i*(ABS(sTime-Fix(sTime/10))+500)
             i = 1
            ElseIf (intReturn = -1) Then
             i = 2
             sTime = Fix(sTime/i)+500
            Else mgBox "invalid":End If
            cTime=cTime-1
          Loop
        End Sub
        Last edited by Rems; 12th July 2007, 18:22.

        This posting is provided "AS IS" with no warranties, and confers no rights.

        __________________

        ** Remember to give credit where credit's due **
        and leave Reputation Points for meaningful posts

        Comment


        • #5
          Re: Server Logoff Script

          Hi,

          We use a very simple script.

          Sinds we have multiple accounts the username is writen allready.

          Code:
          strUserIn = InputBox("Uitgevoerde Acties") 
          Set fs = CreateObject("Scripting.FileSystemObject") 
          strFileName = "D:\\Monitoring\\Acties\\Acties.log"
          Set ts = fs.OpenTextFile(strFileName, 8, True) 
          ts.WriteLine Now & " " & strUserIn 
          ts.Close
          You see this is a very very simple script, but is is effective i can tell you that.

          We hade a problem yesterday and we could trace what has been done by this file.

          A collegue of mine had deleted a file ths was not meant to be deleted.....
          Problem was solved in less than 1 min.

          Also this collegue had his holiday that day, so if we did not had this we would have to set up a search parade....

          Comment


          • #6
            Re: Server Logoff Script

            It is simple but perfect.
            Very user friendy and that is what, besites writing log, is also important for succes.

            Thanks for sharing

            This posting is provided "AS IS" with no warranties, and confers no rights.

            __________________

            ** Remember to give credit where credit's due **
            and leave Reputation Points for meaningful posts

            Comment


            • #7
              Re: Server Logoff Script

              Rems,

              I have updated the script a little bit.

              Now it asks for a username and you have to enter some data now. Cannot leave empty.

              Code:
              dim username
              Do While username = ""
              username = InputBox("Gebruikersnaam:", "Actie Log")
              loop
              strUserIn = ""
              Do while strUserIn = ""
                 strUserIn = InputBox("Uitgevoerde Acties", "Actie Log")
              loop
              Set fs = CreateObject("Scripting.FileSystemObject") 
              strFileName = "D:\\Monitoring\\Acties\\Acties.log"
              Set ts = fs.OpenTextFile(strFileName, 8, True)
              ts.WriteLine "---------------------------------------"
              ts.WriteLine Now & " " & "Acties Uigevoerd Door: " & username
              ts.WriteLine strUserIn
              ts.WriteLine ""
              ts.Close
              I mostly like your script...

              ths only thing my chef does not like in this is the sort of animation and the box on the end asking if you want to logoff. Besides that it's super effective...

              Comment


              • #8
                Re: Server Logoff Script

                ths only thing my chef does not like in this is the sort of animation and the box on the end asking if you want to logoff.
                Oh no you showed my script to your boss? LL

                (OK I agree that 'marquee' thing was complete useless, but it is funny though)

                Like you could tell of the presention of it, my example was not meant to be a script to use as it is. Just a box of tricks and ideas.
                One of the things I had in mind was handling log size. I was looking if there is a way to append to the top of the log. And I was looking how to create periodically a new logfile. So it is possible to cleanup some of the old files (could be done by the same script) after some time.

                As I mensioned before I do prefere the use of static inputboxes here, like you use in your script. This will also better protect the content of the existing log.


                We hade a problem yesterday and we could trace what has been done by this file.

                A collegue of mine had deleted a file ths was not meant to be deleted.....
                Top!
                And I agree with your chef, these kind of colleagues don't deserve a funny script.
                ,, don't say I said that


                \Rems

                This posting is provided "AS IS" with no warranties, and confers no rights.

                __________________

                ** Remember to give credit where credit's due **
                and leave Reputation Points for meaningful posts

                Comment

                Working...
                X