1. You are viewing our forum as a guest. For full access please Register. WindowsBBS.com is completely free, paid for by advertisers and donations.

VB Script not working at Windows logoff

Discussion in 'Windows XP' started by farmerste, 2007/01/03.

  1. 2007/01/03
    farmerste

    farmerste Inactive Thread Starter

    Joined:
    2006/11/14
    Messages:
    16
    Likes Received:
    0
    i have a problem, i have a log off .vbs script that works perfectly on windows 2000 machines, but does nothing on windows xp machines.
    on windows 2k the script can will run either from a domain group policy,or a local one using gpedit.msc

    the script is as below :-

    Const LOGOFF = 0
    Const SHUTDOWN = 1
    Const REBOOT = 2
    Const FORCE = 4
    Const POWEROFF = 8
    For Each objPC In GetObject( "winmgmts:{(shutdown)} ").ExecQuery( "Select * from Win32_OperatingSystem ")
    objPC.Win32Shutdown REBOOT
    Next

    ...........
    what i am trying to achieve is a force reboot when any user logs off a machine.
    this works perfectly on windows 2000, but nothing happens on windows xp.
    Xp is bang up to date with sp2, and all current updates.

    can anyone tell me why this will not run at all on windows xp?

    thanks in advance:cool:
     
  2. 2007/01/03
    Bill Castner

    Bill Castner Inactive

    Joined:
    2006/08/30
    Messages:
    1,980
    Likes Received:
    0
    I rewrote it for you:
    Code:
    Option Explicit
    
    dim objPC, objColl
    
    Const LOGOFF = 0
    Const SHUTDOWN = 1
    Const REBOOT = 2
    Const FORCE_REBOOT = 6
    Const FORCE_LOGOFF = 4
    Const POWEROFF = 8
    Const FORCE_POWEROFF = 12
    
    Set objColl = GetObject( "winmgmts:{(shutdown)}//./root/cimv2 ").ExecQuery( "Select * from Win32_OperatingSystem where Primary=true ")
    
    For each objPC in objColl
    objPC.Win32Shutdown(FORCE_REBOOT)
    Next
    
    -----------------------------
    Different code, same result
    -----------------------------
    Code:
    Set objPCSet = GetObject( "winmgmts:{(Shutdown)}//./root/cimv2 ").ExecQuery( "select * from Win32_OperatingSystem where Primary=true ")
    
    for each objPC in objPCSet
    objPC.Reboot()
    next
    
    ----------------------------------
    Third method
    ----------------------------------
    Code:
    Set WshShell = WScript.CreateObject( "WScript.Shell ") 
    WshShell.Run  "C:\WINDOWS\RUNDLL32.EXE shell32.dll,SHExitWindowsEx 2 ", 2, false
    
     
    Last edited: 2007/01/03

  3. to hide this advert.

  4. 2007/01/04
    farmerste

    farmerste Inactive Thread Starter

    Joined:
    2006/11/14
    Messages:
    16
    Likes Received:
    0
    thankyou for editing the script for me, but i cant get any of those to work on xp either. as a logoff script

    if i double click them they will run and reboot the machine, ( third version i could not get to work although i used to use something similar in windows 98)

    the machine says running logoff scripts and then just goes to the ctrl-alt-del logon screen without rebooting. Yet these scripts will work on a windows 200 machine without any problems.

    has anyone got any ideas how i can find out why these scripts do not run on my xp machines?

    many thanks
     
  5. 2007/01/04
    Bill Castner

    Bill Castner Inactive

    Joined:
    2006/08/30
    Messages:
    1,980
    Likes Received:
    0
    Do you have Fast User Switching enabled?

    What happens if you test:

    Start, Run, shutdown -r -f -t0
     
  6. 2007/01/05
    farmerste

    farmerste Inactive Thread Starter

    Joined:
    2006/11/14
    Messages:
    16
    Likes Received:
    0
    i have tried running shutdown , and nothing happens, except a quick flash of what appears to be a dos window.

    fast switching is turned off, the machines i am working on are members of a domain, so i think it is off by default, and even on a machine that is not on a domain , fast switching is off.

    if i put your .vbs script on a network share any user can run it and the machine reboots perfectly, it just wont run from an active directory logoff folder, or a local logoff folder ( using gpedit.msc)

    anyone got any more ideas

    thanks
     
  7. 2007/01/05
    farmerste

    farmerste Inactive Thread Starter

    Joined:
    2006/11/14
    Messages:
    16
    Likes Received:
    0
    oh and by the way i also tried these scripts on a windows xp without any service packs and got the same problem, so its not a sp2 issue

    :rolleyes:
     
  8. 2007/01/05
    Bill Castner

    Bill Castner Inactive

    Joined:
    2006/08/30
    Messages:
    1,980
    Likes Received:
    0
    Fast User Switching is off for Domains, you are correct.
    As the GPOs for a logoff script apply even to a stand-alone machine, I had to ask.

    What you are missing is an ACE permission, also called NTRIGHTS. Please advise if you are a Domain Admin or not. I will not answer the question otherwise.

    (And I do not recall suggesting this was a Service Pack 2 issue).
     
  9. 2007/01/08
    farmerste

    farmerste Inactive Thread Starter

    Joined:
    2006/11/14
    Messages:
    16
    Likes Received:
    0
    hi again,
    it was me that was convinced that it was a service pack 2 issue, as i have had so many problems with other things since this service pack came out.
    yes i am a system admin for several domains, and have not had any of these problems until i wanted to use a vbs script as a logoff script on xp.

    thanks
     
  10. 2007/01/08
    Bill Castner

    Bill Castner Inactive

    Joined:
    2006/08/30
    Messages:
    1,980
    Likes Received:
    0
    You can have a LUA issue under XP. It is somewhat obscure. The problem is that when something other than "logoff" is specified, XP tries to enable both the SeShutdownPrivilege ( "Shut down the system ") and the SeRemoteShutdownPrivilege ( "Force shutdown from a remote system "), even if local shutdown or reboot is all that is being requested. On XP, Users have SeShutdownPrivilege by default, but they don't have SeRemoteShutdownPrivilege.

    Fix using Group Policy:

    Start, Run, gpedit.msc
    Local Computer Policies
    .Computer Policies
    ...Windows Settings
    ....Security Settings
    .....Local Policies
    .......User Rights

    Add the Group INTERACTIVE to:
    "Force Shutdown from a Remote system. "
    "Shutdown the computer "

    Fix for non-Domain Workgroups:

    If you do not have the Resource Kit for Windows 2003:
    http://www.microsoft.com/downloads/...69-57ff-4ae7-96ee-b18c4790cffd&DisplayLang=en
    Option I. Script it remotely. Need only be done once.

    e.g. the computername is FARMERSTE
    ntrights -m \\FARMERSTE -u INTERACTIVE +r SeRemoteShutdownPrivilege

    Option II. Set nrights on SeRemoteShutdownPrivilege with an email, or other distribution.

    1. Use the startup, an email, or other means to copy ntrights.exe from the Reskit to %windir%\System32 on each machine;

    2. Write a small .cmd file to be distributed and run on each machine. The .cmd file would contain:

    ntrights -u INTERACTIVE +r SeRemoteShutdownPrivilege

    Comment: You are correct in thinking this related to Service Pack 2. It was due to LUA changes in support of SHUTDOWN.EXE, and is in my opinion a bug. Note as well by using Group INTERACTIVE we are granting the right to the local console user, but not changing any security for a remote user.
     
  11. 2007/01/09
    farmerste

    farmerste Inactive Thread Starter

    Joined:
    2006/11/14
    Messages:
    16
    Likes Received:
    0
    just wont do it

    hi, firstly let me say thanks for all your help, but i still cant get it to work on xp.
    i have added the group 'interactive' by using the local gpedit.msc, and on the domian policy, but neither would work. i tried with the.vbs you re wrote, and a batch file :-

    c:\windows\system32\shutdown -r -f -t 01

    both would run when any user was logged on, but not by gpedit.msc or from a group policy ( from PDC)

    i'm afaraid i just don't understand it, it only confirms my theory

    windows 2000 - does what you ask it most of the time

    windows xp - does what it **** well likes most of the time

    thanks:(
     
  12. 2007/01/09
    Bill Castner

    Bill Castner Inactive

    Joined:
    2006/08/30
    Messages:
    1,980
    Likes Received:
    0
    Then open notepad and create a .cmd file.
    The .cmd file would have the shutdown command with parameters.

    For the script choice, point to the newly created .CMD file rather than a .js or .vbs script.

    Three thoughts:

    . I hope a gpupdate was done. The changes would not be in force otherwise.
    . While NT Authority/SYSTEM has both rights, 'Local System' does not. Add 'Local System' to both: Shut down the computer, and Force shut down from a remote system. I have never checked, but it is not unambiguous to me that you are running under the user security token at the time the script is run.
    . All Workstations should have the WHS update applied:
    http://www.microsoft.com/downloads/...FamilyID=C717D943-7E4B-4622-86EB-95A22B832CAA
     
  13. 2007/01/10
    farmerste

    farmerste Inactive Thread Starter

    Joined:
    2006/11/14
    Messages:
    16
    Likes Received:
    0
    failure once again

    thanks again,
    i have ensured that that every workstation had the wsh update applied, and even with this i still cannot get a logoff script to work.
    made a .cmd file in notepad - shutdown -r -f -t 01, and asked it to run at logoff and nothing happened. 9 although it worked fine when any user ran it.
    i used gpupdate / force , to ensure that all settings are applied to group policy, the only thing i couldn't ad was 'local system' i have 'system' i presume you meant that one.

    could anyone please tell me if they can get a script to run at logoff, as i just can't ?????? :confused:

    i can however use psshutdown, run from any machine to shut down another one in the domain.

    i remember reading somewhere that domain applied logoff scripts might not run if the network card disconnects prematurely from the server, but as i am trying to run a local script i guess that doesn't apply.
     
  14. 2007/01/10
    Bill Castner

    Bill Castner Inactive

    Joined:
    2006/08/30
    Messages:
    1,980
    Likes Received:
    0
    Last question.

    Since you have a .CMD file using shutdown.exe, what happens if you use Scheduled Tasks, with a schedule that specifies the file be run at logoff?
     
  15. 2007/01/11
    farmerste

    farmerste Inactive Thread Starter

    Joined:
    2006/11/14
    Messages:
    16
    Likes Received:
    0
    hi again,
    as far as i am aware there is no option available to run a scheduled task at logoff, there is one for logon, but that is all.

    a scheduled task at a set time running my .cmd file works perfectly

    i should also mention the reason that shutdown -r -f -t1 didn't work was because you need to have a space between the t, and the number of seconds, that is why it flashed what appeared to be a dos screen.

    thanks again, bit syill no joy, can anyone get a logoff scrip to work under xp?
     
  16. 2007/01/15
    farmerste

    farmerste Inactive Thread Starter

    Joined:
    2006/11/14
    Messages:
    16
    Likes Received:
    0
    [Script not working at logoff ]

    hi, could someone please try to run a script at logoff on an xp machine, as i think i am going mad. Scripts will work on windows 2000, but not on xp.
    could someone please paste the following into notepad and save as a .vbs extension on c:\

    Option Explicit

    dim objPC, objColl

    Const LOGOFF = 0
    Const SHUTDOWN = 1
    Const REBOOT = 2
    Const FORCE_REBOOT = 6
    Const FORCE_LOGOFF = 4
    Const POWEROFF = 8
    Const FORCE_POWEROFF = 12

    Set objColl = GetObject( "winmgmts:{(shutdown)}//./root/cimv2 ").ExecQuery( "Select * from Win32_OperatingSystem where Primary=true ")

    For each objPC in objColl
    objPC.Win32Shutdown(FORCE_REBOOT)
    Next

    could someone please try to save the following as a .bat file

    shutdown -r -f -t 01

    .......................
    you need to then go start-run-gpedit.msc
    under user configuration expand windows settings,and click on scripts, right click on the logoff script in right window, and select properties.Click on show files button, and copy the script there.
    close the logoff folder, and click add- browse for the script you just pasted, and then click apply.

    now can you please tell me when you LOG OFF if the script runs and the machine restarts instead of just going back to the ctrl-alt-del logon screen

    thanks
     
  17. 2007/01/16
    farmerste

    farmerste Inactive Thread Starter

    Joined:
    2006/11/14
    Messages:
    16
    Likes Received:
    0
    I can get this to work for administrators

    if i use sysinternals psshutdown ( v2.32- an older version ,before microsoft broke it) and the syntax in a .bat or .cmd fie :-

    c:\psshutdown.exe -r -f -t 06

    this will work for members of the administrators group, but not for other users

    anyone got any ideas ?
     
  18. 2007/01/17
    farmerste

    farmerste Inactive Thread Starter

    Joined:
    2006/11/14
    Messages:
    16
    Likes Received:
    0
    hi again, anyone got any ideas?
    it's not like i am asking xp to wash my car or cook my dinner, i just want it to do what it is supposed to do.
     
  19. 2007/01/17
    farmerste

    farmerste Inactive Thread Starter

    Joined:
    2006/11/14
    Messages:
    16
    Likes Received:
    0
    anyone had any sucess ?

    has anyone tried to get their machines to reboot, or shutdown with a logoff script/bat file ?

    let me know

    thanks
     
  20. 2007/01/17
    Zander

    Zander Geek Member Alumni

    Joined:
    2002/01/07
    Messages:
    4,084
    Likes Received:
    5
    Well, to somebody who's not real familiar with scripts it's not real clear which part of your post has to be copied and pasted into the script. For instance, there's this.
    Now I think it's fairly obvious the question about the bat file doesn't belong (what do you want them to do with that bat file? ) but how about the word Next? I take it that means "Next, could someone try....." but with the line of periods beneath it gives the impression that the whole thing should be used which I'm sure is not the case. If somebody tries that and it doesn't work, it may be because the script has the wrong content copied into it. They'll report it doesn't work or they got an error of some type and it'll add to the confusion. Can you be a bit more explicit on what needs to be in the script? Perhaps put it in a quote block as I did above.
     
  21. 2007/01/17
    surferdude2

    surferdude2 Inactive

    Joined:
    2004/07/04
    Messages:
    4,009
    Likes Received:
    23
    Actually the word "next" does go with the vbs script. ;)

    So to clarify,

    the vbs script is:

    Code:
    Option Explicit
    
    dim objPC, objColl
    
    Const LOGOFF = 0
    Const SHUTDOWN = 1
    Const REBOOT = 2
    Const FORCE_REBOOT = 6
    Const FORCE_LOGOFF = 4
    Const POWEROFF = 8
    Const FORCE_POWEROFF = 12
    
    Set objColl = GetObject( "winmgmts:{(shutdown)}//./root/cimv2 ").ExecQuery( "Select * from Win32_OperatingSystem where Primary=true ")
    
    For each objPC in objColl
    objPC.Win32Shutdown(FORCE_REBOOT)
    Next
    
    and the batch file script is:

    Code:
    shutdown -r -f -t 01
    
    BTW, they both work fine on my system but I think farmerste is wanting a report from someone who runs a multiple user network. Perhaps if you move this thread to the Networking forum he'd have better advice.

    HTH
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.