1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Logoff Script in Windows XP Home

Discussion in 'Windows XP' started by des000, Jul 7, 2008.

Thread Status:
Not open for further replies.
Advertisement
  1. des000

    des000 Thread Starter

    Joined:
    May 29, 2008
    Messages:
    245
    I need a free program to run a logoff script in Windows XP Home or Windows XP Professional. It has to not depend on the network, so no netlogon share or something.

    I've ended up being made aware of several ways to do this from searching, but I can't find an already built program that does this. There's HSLAB shutdown folder lite, but it has quick shutdown. I just want a logoff script, no other changes to Windows XP. There's group policy which is perfect, but doesn't support Windows XP Home. I don't want to get it to run on Home, that might be illigal.

    You can create a script to shutdown and execute that script instead of shutdown, but I just want to execute a regular shutdown or whatever and have the program run. There's a NEW GINA program, but I don't want the rest of that New GINA, just the logoff feature if I were to use it.

    Some programs shut down after a certain amount of time, and then run a logoff script before the computer shuts down, but I don't want timed shutdowns.

    I could write a program to wait for a logoff event and then execute a script from the background, which would work I think if I could find a program to do that. It would also seem to work fine as I've saw searching to have a system tray icon that just waits until the icon is gone and then runs a script, but I can't find a program to do that already, just a thing that says how it works. Do you know any program that exists for free that does this?
     
  2. Aitrusskyy

    Aitrusskyy

    Joined:
    Jun 3, 2008
    Messages:
    272
  3. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,731
    Could you clarify something for me?
    You just want a way to run a script that will run when the user performs a log off?
    Or you want a script to force a logoff?
     
  4. des000

    des000 Thread Starter

    Joined:
    May 29, 2008
    Messages:
    245
    Thanks for replying. It's the second one I'm looking for. I'm looking for a way to run a script when the user performs a log off in Windows XP Home, but that works also in Windows XP Proffessional/Media Center Edition.
     
  5. Aitrusskyy

    Aitrusskyy

    Joined:
    Jun 3, 2008
    Messages:
    272
    No problem. From both those links I derived that in order to do what is in the second link, you need to download the package listed in the first link to obtain the winexit.scr file.

    Hope it works for you.
     
  6. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,731
    I don't have an XP Home Machine to test this on, but could you check to see if you have this Registry key.
    Code:
    HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts\Logoff
     
  7. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,731
  8. des000

    des000 Thread Starter

    Joined:
    May 29, 2008
    Messages:
    245
    Looks as if after lots of research, autoit is the only closest thing I've found so far. Here's the current autoit code:

    Code:
    [/SIZE][/FONT]
    [FONT=Georgia][SIZE=2]shutdown_preparation()[/SIZE][/FONT]
    [FONT=Georgia][SIZE=2]While 1
        Sleep(1000)
    WEnd[/SIZE][/FONT]
    
    [FONT=Georgia][SIZE=2]Func OnAutoItStart()
     AutoItSetOption("TrayIconHide", 1) 
    EndFunc[/SIZE][/FONT]
    [FONT=Georgia][SIZE=2]Func OnAutoItExit()
     ;If @ExitMethod = 3 Then execute_logoff_script()
     ;If @ExitMethod = 4 Then execute_shutdown_script()
    EndFunc[/SIZE][/FONT]
    [FONT=Georgia][SIZE=2]Func _ShutdownInitiated($hWndGUI, $MsgID, $WParam, $LParam)
     $close = 0x00000001
     $logoff = 0x80000000
     $shutdown_or_restart = 0x0
      
     
     ;If $LParam = $logoff Then execute_logoff_script()
     ;If $LParam = $shutdown_or_restart Then execute_shutdown_script()[/SIZE][/FONT]
    [FONT=Georgia][SIZE=2] return True
    EndFunc[/SIZE][/FONT]
    [FONT=Georgia][SIZE=2]Func _DoShutdownCleanup($hWndGUI, $MsgID, $WParam, $LParam)
     $close = 0x1
     $logoff = 0x0
     
     If $LParam = $logoff Then execute_logoff_script()
     If $LParam = $close Then execute_shutdown_script()
      
     return 0
    EndFunc[/SIZE][/FONT]
    
    [FONT=Georgia][SIZE=2]Func shutdown_preparation()
     $WM_QUERYENDSESSION = 0x0011
     $WM_ENDSESSION = 0x0016 
     
     
     DllCall("kernel32.dll", "int", "SetProcessShutdownParameters", "long", 0x3FF, "long", 0) ;makes this program get a "Shutdown" message before other programs, but after the system[/SIZE][/FONT]
    [FONT=Georgia][SIZE=2] GUICreate("ShutdownNotificationGUI",1,1) ; dummy gui for shutdown message
     GUIRegisterMsg($WM_QUERYENDSESSION, "_ShutdownInitiated")
     GUIRegisterMsg($WM_ENDSESSION, "_DoShutdownCleanup")
     GUISetSTate(@SW_HIDE)
    EndFunc[/SIZE][/FONT]
    [FONT=Georgia][SIZE=2]Func execute_logoff_script()
     FileDelete("C:\BATCH\logoffwait.tmp")
     
     While Not FileExists("C:\BATCH\logoffwait.tmp")
      sleep(1000)
     WEnd
    EndFunc[/SIZE][/FONT]
    [FONT=Georgia][SIZE=2]Func execute_shutdown_script() 
     execute_logoff_script()
     FileDelete("C:\BATCH\shutdownwait.tmp")
     
     While Not FileExists("C:\BATCH\shutdownwait.tmp")
      sleep(1000)
     WEnd
    EndFunc[/SIZE][/FONT]
    [FONT=Georgia][SIZE=2]


    For now, until this file is ready, I'll leave out the 2 services I'd used to run the scripts. I could just run the scripts in the autoit code, except for Windows XP won't seem to let me at the time I need to. It gives a too late message of a type, so they need to run as services all the time. If they run all the time, but are NOT services, then it won't work. The processes have to survice the logout, appearently.

    Well, if I uncomment the code for the WM_QUERYENDESSION part, it acutally seems to work just fine. However, if shutdown.exe were to be called, it doesn't honor the WM_QUERYENDSESSION request. Therefore I have issues as shutdown.exe is used frequently. So do you know any code I guess to hook the Windows shutdown function that all types of shutdown requests would always use perhaps? Then no matter how I shutdown, it would work. Maybe that's the answer. However, unless you can point to both a free tool to compile and run the code you know of, assuming you know of code that will do that, I'm stuck right there anyway.

    I could replace that function with very simple code. I could simply ensure that my scripts are run, and then pass on code to the default Windows XP code. That way it would add code, but not replace any code.

    In edition, if I didn't do it that way, maybe I could simply use a type of GINA? I tried once a NEW GINA thing that somebody made, but again, if I did that, that would be fine, but I don't want to change anything else, I just want to add code for a logoff and shutdown script. After that task, if I replaced any Windows XP code, I want to just add that, and then call the origional code. I don't want to try to rewrite the Windows XP code at all. I don't want to figure out how it shuts down and re-invent the wheel on Windows XP. I don't want either to replace GUI part of the GINA if I do that either.

    Sorry it took so long to post back, but I had just found the autoit script and was tweaking it, and it worked fine up until this point. The active exit program is not freeware, exactly, and I don't quite like the interface, but thank you.

    Looking at the HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts\Logoff key, it is just what I want to do, unfortunately I checked, and I just double checked too. It doesn't exist on Windows XP Home. If it did exist, even manually, I'd have absolutely no trouble. I whish it existed!

    So it's not going to be a Microsoft tool, but a 3rd party tool that does this I guess! Well, I think I can get even a little tiny bit further too, IF I'M RIGHT. From my searches, it appears that Advapi32.dll contains the shutdown function I might need, and is located in C:\WINDOWS\system32. If that's really true, then I need a replacement Advapi32.dll that would execute the logoff code I need and then continue to the origional code. Well, that's all the new information I know.
     
  9. des000

    des000 Thread Starter

    Joined:
    May 29, 2008
    Messages:
    245
    Oh! I guess what I'm wanting this for might help finally at this point. I've heard of "Roaming Profiles", and I desire a custom roaming profile solution that works in a workgroup and makes sure that the profiles are copied correctly, unlike Windows XP. I've determined that this has to happen at logoff, and I can't use task scheduler to handle it every so often. I want it only at logoff. Unfortunately, this takes a batch file. I've found some cool synchronization tools, but it has to be command line so I can set it up in the blink of an eye on a machine in batch mode, plus it has to be at logoff. No other time will work.
     
  10. des000

    des000 Thread Starter

    Joined:
    May 29, 2008
    Messages:
    245
    It's become pretty clear to me that unless the Windows shutdown code that's common between the GUI and the shutdown.exe command, and which is also common to every program that does not shut down completely according to it's own power (by completely bypassing the OS), is hooked to make the code run properly, then it simply cannot be done. There's no reliable way to accomplish it, I guess. Does anybody have code to do this? I do want to keep the Windows code, just add to it, if not, I guess it's simply impossible. All shutdown script programs seem to work the same way. They don't execute unless the GUI is told to. This is clearly evidence of a very poor shutdown.exe program, plus a completely poor shutdown procedure for the OS, and bad shutdown API, however unless there's the proper code written by someone, it simply appears to be impossible.
     
  11. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/728218