programmatically reboot in safe mode then execute program
Asked Answered
E

2

8

I have a program and once the is button clicked I want a message to appear that will tell user that the computer is rebooting (with ok/cancel option), then the computer will reboot. Yet the kicker is, I want it to reboot into safe mode. Then when the user is logged into safe mode, it will automatically start a program on startup.

Now I realize that this is possible by programmatically editing boot.ini with /safemode, task to start program once computer logs in,then telling the computer to reboot.However, the end user is assumed to have not enough knowledge of Windows to reverse these settings manually.

What I want is, after the end user is done with the program in Windows Safe Mode, they can simply reboot the computer and resume using Windows with out manually changing any settings to the way they were before booting into safe mode.

NOTE* the program that will run in safe mode, has been tested to work in safe mode. I just need to know how to get the end user to safe mode and run the program automatically with out the end user having any knowledge of how to reverse these settings.

Could anyone suggest a method to execute all this madness? An example in C# or vb.net would be great!

Thank you in advance!

Ben

Ensphere answered 7/11, 2012 at 18:47 Comment(9)
I would set it to boot in safe mode, and have a runonce that removes that option.Tracay
Why boot into safe mode you ask? The program that will be launched in safe mode is a anti-malware program that works best off in safe mode.Ensphere
Thanks for the suggestion brad. I am unfamiliar on how to set safemode to run once?Ensphere
I don't know either, but I am referring to having a program you write runonce to remove the boot.ini parameter to boot in safe mode. support.microsoft.com/kb/179365Tracay
I will look into that for sure. Thanks! Any other suggestions or example from anyone else would be great as well.Ensphere
Boot.ini was removed in W7 I believe.Gowk
Ah, it says that the run once key will be ignored in safe mode. So it might work to boot safe mode once, but it won't run in safe mode to run program once.Ensphere
Yes this is really a security feature why would you auto run something in safe mode that just sounds problematicRhonarhonchus
@MicahArmantrout, Good call, but I could have sworn I saw some autorun stuff going into safe mode before. Perhaps it was on an older OS.Tracay
R
7

You can call a process that runs this command

bcdedit /set {current} safeboot Minimal

then make your application a windows service and add a registry key with the name of the service to

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SafeBoot\Minimal\Your Service Name

Rhonarhonchus answered 7/11, 2012 at 19:18 Comment(3)
Thanks! That will work. Any tips or links that will help me create a service that will launch the program in safe mode?Ensphere
Very useful post! And how I reset boot back to normal state?Cyclops
I'd look here for more info technet.microsoft.com/en-us/library/cc709667(v=ws.10).aspxRhonarhonchus
P
4

You can reset the safeboot parameter by putting a value in the registry at, HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce and it will run once the user reboots into safe mode

I'm not sure about this part, but I use this in a batch file to reset the bcdedit value, so it may, or may not work with your program.

/v "*UndoSB" /t REG_SZ /d "bcdedit /deletevalue {current} safeboot"`

Original bat command:

bcdedit /set {current} safeboot network
REG ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce /v "*UndoSB" /t REG_SZ /d "bcdedit /deletevalue {current} safeboot"
SHUTDOWN -r -f -t 07
Palestrina answered 20/12, 2012 at 15:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.