1

I have a script and I've created as Task in Task Scheduler to run the script that will uninstall a program. The trigger I am using is, On Event> System>WinLogon>Event ID 1074 (I've used ID 7002 as well). This doesn't work to run the script during reboot.

The issue I am having is the script(that works fine) is not executing right before the computer physically reboot.

My question:

If a reboot command is executed how can I run a script that will uninstall a program THEN finish the reboot. Or is this not possible and I should go another way?

The goal of this is to execute the script when the user is not interacting with the computer and logon is not an option(for other reasons). Execution of script during logon could be a option but only if there are no other options.

Any help?

3
  • 1
    Thanks for the tip. I successfully got it working as "System" with event id 1074 by USER32 (System log). I'm running shutdown /a at the begining and shutdown /r /t 00 at the end.
    – week
    Commented Oct 6, 2015 at 19:40
  • Your saying that once the task is running the script calls shutdown /a then runs what it needs to then when done calls shutdown /r /t 00? Interesting. I'll have to try that. Commented Oct 6, 2015 at 19:45
  • Yes, without that, I would worry that Windows interrupts my script. Also as you wrote, you have "Winlogon" as a source, but in my logs I see those events from "USER32".
    – week
    Commented Oct 6, 2015 at 19:53

1 Answer 1

2

You should go another way. Policies is what you want to use here. Even for computers that are not in a domain, policies allow you startup and even better logoff scripts.

I use this technique myself to backup key sections of my own profile.

First create a .cmd file which will be your script. Running that .cmd should perform the action you want with no user input required (or your computer will hang at shutdown, if its waiting for a user input that never will come)

Then configure it as your shutdown script.

Go to start and type gpedit.msc to launch Local Group Policy Editor.

There are two types you can use: Log off (applies to users) and shutdown, applies to when your computer is shutdown.

Your uninstall script sounds like something you want to prevent a 2nd time if a user were to log off, and login again, not just at the end of their computer session.

So Go to: User Configuration -> Windows Settings -> `Scripts (Logon/Logoff)

At the right, double click Logoff Press the Add... button and browse to your .cmd file. Hit OK and done.

You should note that this .cmd file is still loaded with your user rights, but your profile is not in use anymore. The script can thus delete/edit/copy/etc your entire profile without any problems.

You can even refer to the global varuables such as %USERNAME%, %APPDATA%, %LOCALAPPDATA% etc.

If you really need this to happen when the computer reboots or shuts down, use Computer Configuration and browse to the Shutdown scripts. (same place)

2
  • That is an option for sure and will work. Is there a way to create this gpo via command line to local group policy? I know I can use Group Policy Manager via Win Server to push the GPO out. However the logoff script I need to run is a part of another script that will already be part of a GPO. I need to create the logoff gpo because the user will be asked via vbscript popup if they want to reboot. If they do, then the script is added and will execute during logoff. Maybe logon script would be easier for this. Thanks! Commented Oct 6, 2015 at 19:38
  • Or you could still use vbscript at logoff, and program a checkmark. If a certain file exists during logoff, it will proceed. If not, it will skip the uninstall. You could even check if the uninstaller exists. But a simple "MyUsername_uninstall.dat" even if 0 bytes can be checked for and the uninstall script removes that file again. A simple command echo . >"myUsername_uninstall.dat" would make that file
    – LPChip
    Commented Oct 7, 2015 at 10:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .