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

Benjamin Jones
  • 987
  • 4
  • 22
  • 50
  • 1
    I would set it to boot in safe mode, and have a runonce that removes that option. – Brad Nov 07 '12 at 18:50
  • 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. – Benjamin Jones Nov 07 '12 at 18:50
  • Thanks for the suggestion brad. I am unfamiliar on how to set safemode to run once? – Benjamin Jones Nov 07 '12 at 18:51
  • 2
    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. http://support.microsoft.com/kb/179365 – Brad Nov 07 '12 at 18:52
  • I will look into that for sure. Thanks! Any other suggestions or example from anyone else would be great as well. – Benjamin Jones Nov 07 '12 at 18:55
  • Boot.ini was removed in W7 I believe. – Arran Nov 07 '12 at 18:59
  • 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. – Benjamin Jones Nov 07 '12 at 19:01
  • Yes this is really a security feature why would you auto run something in safe mode that just sounds problematic – Micah Armantrout Nov 07 '12 at 19:03
  • @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. – Brad Nov 07 '12 at 19:34

2 Answers2

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

Micah Armantrout
  • 6,781
  • 4
  • 40
  • 66
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