Script to run before Shut Down

bawldiggle

GrayGhost2 ret.
Pro User
VIP
Local time
12:22 PM
Messages
895
Location
Australia
I have a script run by a shortcut to open a specific external HD.
If the HD is not connected shows my preferred message.
(Loops through all drives, to identify the HD unique ID)

How would I stage a script to run before Shut Down to capture the HD if it is still connected, and cancel Shut Down.

Is it possible ?

Would appreciate any help :)
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Toshiba, Lenovo (laptops) + 4 rigs
OS
XP Pro (x86) | 7 HP (x86) & (x64) | 7 Pro (x64)

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Home Made
OS
Linux Mint 17 Cinnamon | Win 7 Ult x64
CPU
Intel I7-3770K @ 4.2ghz
Motherboard
ASRock Extreme 4
Memory
32GB G-Skill C10Q
Graphics Card(s)
EVGA GTX 670 2GB SC
Sound Card
Creative Fatality ExtremeGamer
Monitor(s) Displays
LG E2742V x 2
Screen Resolution
1920x1080
Hard Drives
256GB Vertex 4 SSD
2TB Seagate ST2000DM001
1TB Seagate ST1000DM003
PSU
Corsair HX 650
Case
HAF 932 advanced
Cooling
Corsair H100i liquid cooler
Keyboard
Logitech Wireless
Mouse
Logitech Wireless
Internet Speed
OptusNet NBN 100/40
Antivirus
Malwarebytes
Browser
Firefox 30
Other Info
Router: Sagemcom F@st 3846 Crippled by Optus.
Thanks TanyaC for your response :)

I failed to tell you I am using Win7 Home Premium. Obviously no Group Policy.
-----
EDIT
-----
Just found ...
At Open the Local Group Policy Editor I found ...

To open the Local Group Policy Editor as an MMC snap-in
  1. Open MMC. (Click Start , click in the Start Search box, type mmc , and then press ENTER .)
  2. On the File menu, click Add/Remove Snap-in .
  3. In the Add or Remove Snap-ins dialog box, click Group Policy Object Editor , and then click Add .
  4. In the Select Group Policy Object dialog box, click Browse .
  5. Click This computer to edit the Local Group Policy object, or click Users to edit Administrator, Non-Administrator, or per-user Local Group Policy objects.
  6. Click Finish .
Would this process enable me to run my script as planned -- OR AM I snookered with Home Premium ?
 
Last edited:

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Toshiba, Lenovo (laptops) + 4 rigs
OS
XP Pro (x86) | 7 HP (x86) & (x64) | 7 Pro (x64)
Hi,

Yes, this is another way to access the group policy editor, assuming the snap in is installed on Home Premium. All my computers were either professional or ultimate so I always had access to the GPO.

In any case, even if you cannot get access to the GP editor all is not lost, because for the most part it is simply an interface to the registry, and generally speaking mosst things you can do with GP Editor can be done with manual registry entries.

I found this example discussing how to do it via the registry.. (It is a bit technical), if you can't run the GPO from MMC and want have a go via the registry, make sure you back it up first, or at least create a restore point.

http://en.kioskea.net/faq/3358-execute-a-script-a-startup-and-shutdown

(Credit to Kioskea.net for the code).

Get back to us if you need more help with this.

Edit: The only thing I'm not sure of is if Windows Home Premium will honour the scripts, but reading through the KioskEa.net solution , it certainly implies it will.

HTH
Tanya
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Home Made
OS
Linux Mint 17 Cinnamon | Win 7 Ult x64
CPU
Intel I7-3770K @ 4.2ghz
Motherboard
ASRock Extreme 4
Memory
32GB G-Skill C10Q
Graphics Card(s)
EVGA GTX 670 2GB SC
Sound Card
Creative Fatality ExtremeGamer
Monitor(s) Displays
LG E2742V x 2
Screen Resolution
1920x1080
Hard Drives
256GB Vertex 4 SSD
2TB Seagate ST2000DM001
1TB Seagate ST1000DM003
PSU
Corsair HX 650
Case
HAF 932 advanced
Cooling
Corsair H100i liquid cooler
Keyboard
Logitech Wireless
Mouse
Logitech Wireless
Internet Speed
OptusNet NBN 100/40
Antivirus
Malwarebytes
Browser
Firefox 30
Other Info
Router: Sagemcom F@st 3846 Crippled by Optus.
Thanks TanyaC,

So close to Xmas it will be a week or two before I can get to "my script" experiment.
I have been out of the country for about 8 weeks (not holidays) and my daughter is on my case to downgrade her Win8 Dell, to Win7.

I will get back here when I get the script working.

One question, can I suspend "Shut Down" with script or is shut-down inevitable.?
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Toshiba, Lenovo (laptops) + 4 rigs
OS
XP Pro (x86) | 7 HP (x86) & (x64) | 7 Pro (x64)
Thanks TanyaC,
One question, can I suspend "Shut Down" with script or is shut-down inevitable.?

Let's say your script says "Shutdown /s /t 30"

If you intercept that shutdown command before the 30 seconds expires with "shutdown /a" it will cancel the pending shutdown.

I always use a value > 0 when I used automated shutdowns, because that gives you the chance to cancel it, but, it also gives the system time to finish of anything when the kill signal is sent to the processes, or so I'm told.

Tanya
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Home Made
OS
Linux Mint 17 Cinnamon | Win 7 Ult x64
CPU
Intel I7-3770K @ 4.2ghz
Motherboard
ASRock Extreme 4
Memory
32GB G-Skill C10Q
Graphics Card(s)
EVGA GTX 670 2GB SC
Sound Card
Creative Fatality ExtremeGamer
Monitor(s) Displays
LG E2742V x 2
Screen Resolution
1920x1080
Hard Drives
256GB Vertex 4 SSD
2TB Seagate ST2000DM001
1TB Seagate ST1000DM003
PSU
Corsair HX 650
Case
HAF 932 advanced
Cooling
Corsair H100i liquid cooler
Keyboard
Logitech Wireless
Mouse
Logitech Wireless
Internet Speed
OptusNet NBN 100/40
Antivirus
Malwarebytes
Browser
Firefox 30
Other Info
Router: Sagemcom F@st 3846 Crippled by Optus.
Back
Top