+ Post New Thread
Page 1 of 3 123 LastLast
Results 1 to 15 of 33
Windows Thread, How Can I Make This VB Script Loop?? in Technical; We have a script running which stops kids from unplugging the cable mid logon and not getting our smoothwall settings ...
  1. #1

    Join Date
    Jun 2009
    Posts
    372
    Thank Post
    14
    Thanked 3 Times in 3 Posts
    Rep Power
    20

    How Can I Make This VB Script Loop??

    We have a script running which stops kids from unplugging the cable mid logon and not getting our smoothwall settings so that thewy can get on Facebook and YouTube. The problem is they have found out that if they do a Windows Lock while the desktop loads, which is when the script runs, that it overiddes the script and doesnt log them off, they then unlock it and carry on using it.

    Basically i could do with some VB wizz telling me if there is a way to force the logoff even when the worksation is locked OR to infinitenly loop the script so that it just keeps checking for the conditions every 60 seconds. The script is;

    Code:
    Dim objNetwork
    Dim strUserName
    Dim WshShell
    
    Set objNetwork = WScript.CreateObject("WScript.Network")
    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    Set ObjFSO = CreateObject("Scripting.FileSystemObject")
    
    WScript.Sleep 5000
    
    strUserName = objNetwork.UserName
    if strUserName = "Administrator" then
    else
    strDomain = objNetwork.userdomain
    if strdomain = "MLZ" then **this is a different domain that 6th formers and college students use who dont have H: drives mapped so can be excluded
    else
    if ObjFSO.DriveExists("h:") then **this is their home drive, if they do the unplug cable logon then they dont get their network drives and this is the condition we use to determine that they have been messing around, so log them off.
    else
    WshShell.Run "logoff.exe"
    End if
    End if
    End if
    Last edited by ZeroHour; 13th July 2011 at 10:54 AM.

  2. #2

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,731
    Thank Post
    344
    Thanked 520 Times in 488 Posts
    Rep Power
    180
    How are you running this, as it should still work fine if the computer is locked or not?

    Other way to do it, "if" you're not actually cancelling the script is like this:

    Code:
    Do Until (ObjFSO.DriveExists("h:") = True)
        WshShell.Run "logoff.exe"
    Loop
    
    (or this if that doesn't work)
    
    Do Until ObjFSO.DriveExists("h:")
        WshShell.Run "logoff.exe"
    Loop
    Steve

  3. #3

    nephilim's Avatar
    Join Date
    Nov 2008
    Location
    Dunstable
    Posts
    12,270
    Thank Post
    1,670
    Thanked 2,017 Times in 1,466 Posts
    Blog Entries
    2
    Rep Power
    451
    get the script to check every 10 seconds because every 60 seconds could mean I could lock the machine, unplug it, unlock it, plug it back in and job done, leaves a BIG window of opportunity at 60 seconds.

  4. #4

    Join Date
    Jun 2009
    Posts
    372
    Thank Post
    14
    Thanked 3 Times in 3 Posts
    Rep Power
    20
    Quote Originally Posted by nephilim View Post
    get the script to check every 10 seconds because every 60 seconds could mean I could lock the machine, unplug it, unlock it, plug it back in and job done, leaves a BIG window of opportunity at 60 seconds.
    thats what i want to do but dont know how to write that. If you can tell me how i'd be interested to see.

  5. #5

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,731
    Thank Post
    344
    Thanked 520 Times in 488 Posts
    Rep Power
    180
    Quote Originally Posted by farquea View Post
    thats what i want to do but dont know how to write that. If you can tell me how i'd be interested to see.
    Why even give them 10 seconds? End of day script will only stay running while pc is locked, and you don't want them to have access to anything. It's not like it's using CPU or anything, when it's locked.

    Just my two cents :P

    Steve

  6. #6

    Join Date
    Jun 2009
    Posts
    372
    Thank Post
    14
    Thanked 3 Times in 3 Posts
    Rep Power
    20
    Quote Originally Posted by Steve21 View Post
    How are you running this, as it should still work fine if the computer is locked or not?

    Other way to do it, "if" you're not actually cancelling the script is like this:

    Code:
    Do Until (ObjFSO.DriveExists("h:") = True)
        WshShell.Run "logoff.exe"
    Loop
    
    (or this if that doesn't work)
    
    Do Until ObjFSO.DriveExists("h:")
        WshShell.Run "logoff.exe"
    Loop
    Steve
    This kidn of worked, when it loops and runs logoff.exe you get a End Process window for explorer.exe. if you click end now, it logs off fine, if you dont and then press cancel and mash the keys a bit, lock it then unlock, the start bar might have dissaperared buy you can still open up the C; drive and run iexplorer and mess about like that. So, nearly but not quite

  7. #7

    Join Date
    Jun 2009
    Posts
    372
    Thank Post
    14
    Thanked 3 Times in 3 Posts
    Rep Power
    20
    Quote Originally Posted by Steve21 View Post
    Why even give them 10 seconds? End of day script will only stay running while pc is locked, and you don't want them to have access to anything. It's not like it's using CPU or anything, when it's locked.

    Just my two cents :P

    Steve
    There has to be an initial wait (we currently have it at 5 seconds) this is so that the H: drive is mapped BEFORE the script check for it, if there is no wait it will just log everyone off we found.

  8. #8

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,731
    Thank Post
    344
    Thanked 520 Times in 488 Posts
    Rep Power
    180
    Think you misunderstood what I meant :P

    You're already doing a 5second wait. My point being why limit it to 10, or 60 second loops. End of day you want it logged off the instant it's unlocked don't you?

    And in terms of your its hanging comment, Change your use of logoff.exe to a cmd line, shutdown (with logoff, and force parameters)

    Steve

  9. #9

    Join Date
    Jun 2009
    Posts
    372
    Thank Post
    14
    Thanked 3 Times in 3 Posts
    Rep Power
    20
    Quote Originally Posted by Steve21 View Post
    Think you misunderstood what I meant :P

    You're already doing a 5second wait. My point being why limit it to 10, or 60 second loops. End of day you want it logged off the instant it's unlocked don't you?

    And in terms of your its hanging comment, Change your use of logoff.exe to a cmd line, shutdown (with logoff, and force parameters)

    Steve
    That 5 second wait is a waint until it actually runs the IF's part of the script. So windows loads, it runs the script, waits 5 seconds then checks for the conditions, if they aren't met it logs off. Without the 5 second wait EVERYONE gets logged off because it runs before the H: Drive is mapped. However if you lock the workstation before the desktop has loaded, the script runs but doesnt log you off if the workstation is locked. After this has run, they unlock and free to do as they wish. So i need the script to loop, constantly checking for a H: drive, which at the moment it isnt doing, its only looking once. But i dont know how to do this as this script was taken from from this site in the first place.

  10. #10

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,731
    Thank Post
    344
    Thanked 520 Times in 488 Posts
    Rep Power
    180
    And as I said three times :P you don't need "BOTH" timers :P

    You have a 5 second timer. That's fine.

    You don't need the loop to be on a 10/60/250505050 second loop, there's no benefit to it.

    Steve

  11. #11

    Join Date
    Jun 2009
    Posts
    372
    Thank Post
    14
    Thanked 3 Times in 3 Posts
    Rep Power
    20
    Quote Originally Posted by Steve21 View Post
    And as I said three times :P you don't need "BOTH" timers :P

    You have a 5 second timer. That's fine.

    You don't need the loop to be on a 10/60/250505050 second loop, there's no benefit to it.

    Steve
    Ok so what do i need to change then to achieve what i want to do? as like i said i know very little about VB.

  12. #12

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,731
    Thank Post
    344
    Thanked 520 Times in 488 Posts
    Rep Power
    180
    Err haven't tested, as I'd prefer not to autokill myself as I don't have H drive

    But this should work, gimme a shout if it's not

    Code:
    Dim objNetwork
    Dim strUserName
    Dim WshShell
    
    Set objNetwork = WScript.CreateObject("WScript.Network")
    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set ObjFSO = CreateObject("Scripting.FileSystemObject")
    
    WScript.Sleep 5000
    
    strUserName = objNetwork.UserName
    
    if strUserName = "Administrator" then
       else
          strDomain = objNetwork.userdomain
    
    if strdomain = "MLZ" then 
       else
    
    if ObjFSO.DriveExists("h:") then
       else
    
    Do Until ObjFSO.DriveExists("h:")
        WshShell.Run "shutdown /l /f /t 0"
    Loop
    
    End if
    End if
    End if
    Steve

  13. #13

    Join Date
    Jun 2009
    Posts
    372
    Thank Post
    14
    Thanked 3 Times in 3 Posts
    Rep Power
    20
    Quote Originally Posted by Steve21 View Post
    Err haven't tested, as I'd prefer not to autokill myself as I don't have H drive

    But this should work, gimme a shout if it's not

    Code:
    Dim objNetwork
    Dim strUserName
    Dim WshShell
    
    Set objNetwork = WScript.CreateObject("WScript.Network")
    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set ObjFSO = CreateObject("Scripting.FileSystemObject")
    
    WScript.Sleep 5000
    
    strUserName = objNetwork.UserName
    
    if strUserName = "Administrator" then
       else
          strDomain = objNetwork.userdomain
    
    if strdomain = "MLZ" then 
       else
    
    if ObjFSO.DriveExists("h:") then
       else
    
    Do Until ObjFSO.DriveExists("h:")
        WshShell.Run "shutdown /l /f /t 0"
    Loop
    
    End if
    End if
    End if
    Steve
    It kind oif works but..... when you unlock the script starts the logoff but you get a ticker box ending explorer.exe then if you press "end now" it obviously logs off like it shoud but if you press cancel you can get Internet Explorer Open and ignore the attempt at trying to logoff and you can carry on use iexplorer. would you know how to add in a line in the loop to kill iexplorer.exe so that if its open it gets closed and if its opened again just keeps getting closed (if it would work like that)
    Last edited by farquea; 13th July 2011 at 10:46 AM.

  14. #14

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,731
    Thank Post
    344
    Thanked 520 Times in 488 Posts
    Rep Power
    180
    Any idea what it's hanging on? It should only hang if something is open normally.

    To kill IE this should work: (again, will need to test it :P Don't like killing my stuff )

    Code:
    Set objShell = CreateObject("Wscript.Shell") 
    objShell.Run("taskkill /im iexplore.exe"), 1, TRUE

  15. #15

    Join Date
    Jun 2009
    Posts
    372
    Thank Post
    14
    Thanked 3 Times in 3 Posts
    Rep Power
    20
    Quote Originally Posted by Steve21 View Post
    Any idea what it's hanging on? It should only hang if something is open normally.

    To kill IE this should work: (again, will need to test it :P Don't like killing my stuff )

    Code:
    Set objShell = CreateObject("Wscript.Shell") 
    objShell.Run("taskkill /im iexplore.exe"), 1, TRUE
    On further testing, sometimes it does log the user straight off after you unlock, sometimes it gets stuck in the logoff process but get the trying to end explorer.exe process i described above BUT i dont think they can actually get anything to load when its in this state, although i've not exhaustivly checked this. Because i'm a VB noob, where exactly would i put that line to kill iexplorer.exe? above the shutdown line (i changed it to logoff on mine)?
    Thanks for all your help, i really appreciate it!

SHARE:
+ Post New Thread
Page 1 of 3 123 LastLast

Similar Threads

  1. Replies: 16
    Last Post: 14th September 2010, 06:48 AM
  2. Replies: 4
    Last Post: 28th July 2010, 11:46 AM
  3. How can I make a virtualbox disk image read only?
    By reggiep in forum Thin Client and Virtual Machines
    Replies: 13
    Last Post: 29th April 2009, 06:42 PM
  4. How can I make bootable ghost (image) CDís
    By chrisreed in forum O/S Deployment
    Replies: 4
    Last Post: 9th February 2009, 08:24 PM
  5. How can I add this code?
    By kerlj001 in forum EduGeek Joomla 1.0 Package
    Replies: 0
    Last Post: 10th December 2008, 08:43 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •