VBs Script

iowatechiowatech Member Posts: 120
I've been trying to get a vb script created that runs on "logoff" that prompts a yes/no question with an "if" in there that if the user picks No it aborts the shutdown or logoff. Everything is working except the part where the logoff and shutdown are aborted.

shutdown -a doesn't work since I'm not starting the shutdown from the cmd line. After browsing the internet and coming up dry I figured I would just ask here to see if anyone has an idea on what type of script to use.

Thank you,
IT

Comments

  • royalroyal Member Posts: 3,352 ■■■■□□□□□□
    Found this from googling "vbscript shutdown"

    http://www.windowsitpro.com/Articles/ArticleID/42982/42982.html?Ad=1

    Reboot:
    Set OpSysSet = GetObject("winmgmts:{(Shutdown)}//./root/cimv2").ExecQuery("select * from Win32_OperatingSystem where Primary=true")

    for each OpSys in OpSysSet
    OpSys.Reboot()
    next

    Shutdown:
    Change OpSys.Reboot() line to OpSys.Shutdown().

    If you want other code examples, just google what I googled above. There's tons of vbscript code out there on Google for this.
    “For success, attitude is equally as important as ability.” - Harry F. Banks
  • iowatechiowatech Member Posts: 120
    I appreciate your help truely, however I did run across that stuff this afternoon/evening however I just could find the "abort" trigger for VB. The reboot/logoff/shutdown was all there though as you just shown.

    Hope that makes more sense, sorry if it sounds confusing.
  • sprkymrksprkymrk Member Posts: 4,884 ■■■□□□□□□□
    Can you post what you have so far? Might give us a better idea what the problem might be.

    Also, can I ask what the purpose/goal of the script is?
    All things are possible, only believe.
  • JDMurrayJDMurray Admin Posts: 13,023 Admin
    If you need to find code examples, give Krugle and Google Code Search a try. Both support searching for VBScript (VBA or Visual Basic) projects and files.
  • iowatechiowatech Member Posts: 120
    Can you post what you have so far? Might give us a better idea what the problem might be.

    Also, can I ask what the purpose/goal of the script is?

    Tomorrow when I have the scripts in front of me I'll do that. The goal is sometimes users logoff before going to a website that they need to go to first before leaving for the day. Right now the script says. "Are you sure you want to logoff? Have you done X job for the day? Then it prompts a yes/no. If they click No I need it to abort the shutdown and take them back to the website.

    Everything right now works except the shutdown abort.

    However tomorrow, as requested, I will post the script.

    Thank you for the replies so far,
  • SieSie Member Posts: 1,195
    Remove the shutdown option with a GPO and run it from a batch file instead which calls the cmd line and would accept the -a switch and IF statement.

    Not quite what you want but it would work, i will have a think about the original post and i'll possibly post later when i've finished and had chance to sleep!!
    Foolproof systems don't take into account the ingenuity of fools
  • royalroyal Member Posts: 3,352 ■■■■□□□□□□
    Sie wrote:
    Remove the shutdown option with a GPO and run it from a batch file instead which calls the cmd line and would accept the -a switch and IF statement.

    I was thinking of that too, but then that computer would need a batch file placed on their system. Or they can use a remote batch. But if you're gonna run a script, might as well just have the vb code directly in the script to consolidate where things are located.
    “For success, attitude is equally as important as ability.” - Harry F. Banks
  • iowatechiowatech Member Posts: 120
    Set objShell = CreateObject("Wscript.Shell")
    
    
    intMessage = Msgbox("Did you do X job already?", _
        vbYesNo, "Job Monitor")
    
    If intMessage = vbNo Then
        objShell.Run("Aborting Shutdown should go here")
    Else
        Wscript.Quit
    End If
    



    That's the script

    There isn't much to the actual script its just a matter of finding the proper abort code.
  • JDMurrayJDMurray Admin Posts: 13,023 Admin
    When Windows shuts down or logs off, it sends a WM_QUERYENDSESSION message to all running programs giving them a chance to respond to prevent Windows from exiting. In your case, you want a script to be kicked off during the shutdown/logoff event, allowing the user to possibly abort the exit. If Windows sends a WM_QUERYENDSESSION to any process that starts during shutdown/logoff, your script can respond to this message in its message loop.

    Googling for WM_QUERYENDSESSION vbscript, I see a possible solution on Expert's Exchange, but I don't have access to read it.
  • iowatechiowatech Member Posts: 120
    Thanks JD.

    I think that just gave me enough to get this solved. I can read EE.
  • JDMurrayJDMurray Admin Posts: 13,023 Admin
    Cool! Please do post your working solution.
Sign In or Register to comment.