Log on script to log off user after log on for 30 mins

Author Message
azmantek

  • Total Posts : 14
  • Scores: 0
  • Reward points : 0
  • Joined: 3/15/2005
  • Location:
  • Status: offline
Log on script to log off user after log on for 30 mins Wednesday, December 28, 2005 5:19 PM (permalink)
0
To whom it may concern,
 
I would like to have a log on script that log off user after he logs on for 30 mins.
 
I was thinking of having it to check group membership first and then start the count down timer to forcefully log that user off.
 
Please help. Happy holidays and Thank you very much.
 
Regards,
 
 
#1
    crazymatt

    • Total Posts : 310
    • Scores: 0
    • Reward points : 0
    • Joined: 3/4/2005
    • Location:
    • Status: offline
    RE: Log on script to log off user after log on for 30 mins Thursday, December 29, 2005 12:06 AM (permalink)
    0
    Hi, i´ve cut out the following parts from a bigger script i once made, so i havnt tried the code myself, but it should atleast point you in the right direction for getting the "logout" part of ur script. You can prolly clean it up a lil as well. Add a timer in the beginning of the script and/or make some popups waring about "5 mins left" and you  should have a good start.
     
     Const ForcedLogoff = 4
     Set oShell = CreateObject("WScript.Shell")
     Set oNetwork = CreateObject("WScript.Network")
     sSkriptPath=left(wscript.scriptfullname,len(wscript.scriptfullname)-len(wscript.scriptname)) 
     strOption = 4
     strComputer = "."
     on error resume Next
      
     Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown)}\\" & _
      strComputer & "\root\cimv2")
     Set colOperatingSystems = objWMIService.ExecQuery ("SELECT * FROM Win32_OperatingSystem")
     For Each objOperatingSystem in colOperatingSystems
     ObjOperatingSystem.Win32Shutdown(strOption)
     Next 
     
     

     
    Hope it helps!
     
    /CM
    -There is only 10 sorts of people, those who understand binary and those who dont.
     
    #2
      azmantek

      • Total Posts : 14
      • Scores: 0
      • Reward points : 0
      • Joined: 3/15/2005
      • Location:
      • Status: offline
      RE: Log on script to log off user after log on for 30 mins Thursday, December 29, 2005 6:18 AM (permalink)
      0
      Hi Matt,
       
      Thank you very much for your help. I'm still very new with VBScript, so this is kinda over head for me. I want to help out a friend. Would you please help me with a full script? or if you are busy, please point me to a good place where I can start learning VBScript as quick as I can. Thank you.  I really appreciate your kindness.
       
      Regards,
       
       
      #3
        DocHolliday

        • Total Posts : 3
        • Scores: 0
        • Reward points : 0
        • Joined: 12/29/2005
        • Status: offline
        RE: Log on script to log off user after log on for 30 mins Thursday, December 29, 2005 7:58 AM (permalink)
        0
        Here, try this one.  Please, test it first!
         
        '
        ' ***********************************************************************
        ' *
        ' * LogoffIn30 - Logs off the current user in 30 minutes
        ' * John Holliday - 12/29/2005 - 1.0
        ' * ChangeAuthorName - DateOfChange - IteratedVersionNumber
        ' *
        ' ***********************************************************************
        '
        Option Explicit

         
        Public gobjWshShell
         
        Sub ScriptInit()
         Set gobjWshShell = CreateObject("WScript.Shell")
        End Sub

         
        Function Sleep(lintNumOfSeconds, lblnUseMilliseconds)
         ' Put False as the second argument to use standard seconds.
         ' Put True to use milliseconds.
         If lblnUseMilliseconds = False Then
          lintNumOfSeconds = lintNumOfSeconds * 1000
         End If
         WScript.Sleep lintNumOfSeconds
        End Function

         
        Sub ShutDown(lintShutdownType)
         Dim strComputer
         Dim OpSys
         Dim OpSysSet
         strComputer = "."
         If lintShutDownType = "" then
          lintShutDownType = 4
         End If
         Set OpSysSet = GetObject("winmgmts:{(Debug,Shutdown)}//" & strComputer & "/root/cimv2").ExecQuery("select * from Win32_OperatingSystem where Primary=true")
         For Each OpSys in OpSysSet
          OpSys.win32Shutdown(lintShutdownType)
         Next
        ' The numbers in the Decimal column are for the lintShutDownType variable.
        ' Action  Decimal  Binary
        ' Logoff   0  0000
        ' Reboot   2  0010
        ' Force Logoff  4  0100
        ' Force Reboot  6  0110
        ' Powerdown   8  1000
        ' Force Powerdown 12  1100
        End Sub

         
        Sub RunFor30()
         On Error Resume Next
         Dim lblnIsDone
         Dim lintNumMinutes
         lintNumMinutes = 0
            Do
           lblnIsDone = False
                Sleep 60, False
                lintNumMinutes = lintNumMinutes + 1
          Select Case lintNumMinutes
           Case 25
            gobjWshShell.Popup "Warning!" & vbCrLf & vbCrLf & "This workstaion will be logged off in 5 minutes!" & vbCrLf & "Please save your data and close any open applications." & vbCrLf & "This box will close in 15 seconds.", 15, "Logoff Warning", vbExclamation + vbOKOnly + vbSystemModal
           Case 30
            lblnIsDone = True
            ShutDown 4       
           Case Else
            ' Do nothing
          End Select
            Loop Until lblnIsDone = True
        End Sub

         
        ' Processing starts here
         
        ScriptInit
        RunFor30
        WScript.Quit

         
        ' ***************
         
        That's the end of the script.  Remember that the "gobjWshShell.Popup" line is all on ONE line, not two.  Let me know if it works.
         
         - Doc
         
         
        #4
          ehvbs

          • Total Posts : 3321
          • Scores: 110
          • Reward points : 0
          • Joined: 6/22/2005
          • Location: Germany
          • Status: offline
          RE: Log on script to log off user after log on for 30 mins Thursday, December 29, 2005 8:54 AM (permalink)
          0
          Hi DocHolliday,

          I hope you won't mind being called 'a fast gun'! I do like your script/style. Using "Public"
          instead of simple "Dim" to mark global variables, stating variable types explicitly, splitting
          the script in reusable, independent parts, explaining the used numeric constants - I'm
          very impressed.

          So don't take my following questions as criticism - I just want to lure you into a discussion
          about "VBScript - Best Practices".

          1. Why is gobjWshShell global - it's used in RunFor() only?
          2. Why do you use "lblnUseMilliseconds = False" or "lblnIsDone = True"?
          3. Woudn't RunFor() be more usefull if given the MinutesToRun as a parameter?
          4. Why did you code the action to do after the N minutes into RunFor()?
           
          #5
            azmantek

            • Total Posts : 14
            • Scores: 0
            • Reward points : 0
            • Joined: 3/15/2005
            • Location:
            • Status: offline
            RE: Log on script to log off user after log on for 30 mins Thursday, December 29, 2005 6:05 PM (permalink)
            0
            Thank you very much John. The scripts work perfectly. I do appreciate your help.

            Regards,
             
            #6
              crazymatt

              • Total Posts : 310
              • Scores: 0
              • Reward points : 0
              • Joined: 3/4/2005
              • Location:
              • Status: offline
              RE: Log on script to log off user after log on for 30 mins Thursday, December 29, 2005 7:54 PM (permalink)
              0

              ORIGINAL: DocHolliday

              Here, try this one.  Please, test it first!


               
              Good job Doc and welcome here!
               
              Dont forget to use the "code" tags to enbedd your code a separate window within the post (its the "<%" symbol next to the font size when you are creating a new post)
               
              Regards Matt
              -There is only 10 sorts of people, those who understand binary and those who dont.
               
              #7
                Jubaru

                • Total Posts : 2
                • Scores: 0
                • Reward points : 0
                • Joined: 11/18/2009
                • Status: offline
                Re:Log on script to log off user after log on for 30 mins Wednesday, November 18, 2009 10:24 AM (permalink)
                0
                Hi,

                I have also found this very useful - thanks  :o)

                I am just starting out with VB and am not sure where to put this.  I have tried running it as a scheduled task and also as a script to run on startup but neither of them have worked in exactly the way I want them to.

                When I added it as a scheduled task I got the warning message and the computer logged off but only when I was logged on as the person who added the task - my computers will have many users and these are the ones that I want to time restrict.

                When I added it as a startup script I didn't get any warning message although the computer did log off.  Why didn't I get a warning?

                To give you an idea of my problem - I need to restrict all users of a small group of computers (6) to a maximum of 1 hour and I also need warning messages that the computer is about to logoff/shutdown.

                Have you any idea how I can resolve my problem please?

                Thanks
                Jubaru
                 
                #8

                  Online Bookmarks Sharing: Share/Bookmark

                  Jump to:

                  Current active users

                  There are 0 members and 1 guests.

                  Icon Legend and Permission

                  • New Messages
                  • No New Messages
                  • Hot Topic w/ New Messages
                  • Hot Topic w/o New Messages
                  • Locked w/ New Messages
                  • Locked w/o New Messages
                  • Read Message
                  • Post New Thread
                  • Reply to message
                  • Post New Poll
                  • Submit Vote
                  • Post reward post
                  • Delete my own posts
                  • Delete my own threads
                  • Rate post

                  2000-2012 ASPPlayground.NET Forum Version 3.9