5

I've read the TechNet pages that describe using computer/user startup/shutdown scripts, and that's great, but I'd like to create those scripts via the command-line (and not have to click around in gpedit.msc).

It looks like scripts.ini and psscripts.ini in %SYSTEMROOT%\System32\GroupPolicy\Machine\Scripts specifies the scripts to run, but those don't exist until running gpedit.msc for the first time. Is it safe to create and edit those directly? Or do I need to muck around with Set-GPO or something similar? Thanks!

  • Create your shutdown script, deploy to computers, tell users to use the new shortcut on their desktop (that points to your script) to shutdown their computers. You may have to deal with local permissions for users if they are restricted. Otherwise alternative is to just use GPO. – Shawn Melton May 28 '14 at 10:34
  • Thank you for your suggestion, but as I commented below, the shutdown is externally triggered, and there are no users with sessions running to click shortcuts. – David Rubin May 28 '14 at 18:26
  • 1
    stackoverflow.com/a/52585110/45375 uses PowerShell to script installation of shutdown scripts, but note its caveats. – mklement Oct 1 '18 at 18:09
1

Group Policy assumes you are in an Active Directory domain environment, in which case Group Policy Objects (GPOs) are centrally managed and assigned to computers. For individual machines, the Local Security Policy can be used to produce similar results to centrally managed GPOs.

Typically in Active Directory, login scripts are assigned to User objects, though you can also do this through Group Policy.

If you're not using Active Directory, or you only want to configure this on a relatively small number of computers, you can certainly do this with PowerShell using the Task Scheduler. With Task Scheduler you can create events to run at startup, session end, or logon.

  • Thank you for your response. When creating a task in Task Scheduler, I see "At Log On" and "At Startup", but not "At Shutdown". Are you certain? Googling points towards using "Local Computer Policy", which is why I was pursuing that approach in the first place. – David Rubin May 27 '14 at 20:31
  • You're correct. You can kick off tasks when a session ends, such as when a user logs off, but not at the shutdown event itself. If a user is initiating the shutdown this would have the same effect. If the shutdown is automated perhaps there is another event that would coincide with the shutdown? – Tim Ferrill May 27 '14 at 20:44
0

Can you use the shutdown command?

Technet shutdown command syntax

  • Unfortunately I cannot - the shutdown is externally triggered (i.e. VM gets forcefully terminated, etc.). – David Rubin May 27 '14 at 22:24
-1

I assume you are wanting a shutdown event?

It is basically impossible to run a script when a shutdown event occurs, logoff, yes, but shutdown no. I have a C# app that listens for the shutdown message, but when the message arrives, it is not possible to spawn any new processes, and the event is often missed.

  1. Windows sends the WM shutdown message to all top-level windows WM_CLOSE etc - but does to in serial order to all the desktop programs. If you are the last one to get it, you have no time left.

  2. Windows has a process load/unload module or dll lock that means when apps are terminating or unloading, that apps cannot load at the exact same instant - its a single threading "shareing-of shared stuff" protection problem. Done to save RAM, but catches us here by slowing things down at a busy period for the O/S.

  3. Windows has a internal flag to say don't start any new processes or scripts we are terminating. This means whatever listens, can only write to a remote file or use a TCP connection or similar to let somebody know its closing. You can normally not run any new scripts during shutdown.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.