Kaseya Community

Final Safe Mode Script (Req)

  • Long story short. The safemode script I have been using failed on a machine because of a non-standard boot.ini file. Searched around on the forums for a newer script but and all the different safemode scripts and vbs files are confusing. Can someone please post a reliable safemode script that will work no matter the layout of the partitions and boot.ini file.

    Hopefully this will end future confusion with this particular script.


    Thank you.

    Legacy Forum Name: Final Safe Mode Script (Req),
    Legacy Posted By Username: Resistance2Fly
  • bump... anyone?

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: Resistance2Fly
  • I found a thread or two in these forums that helped me create my Reboot to Safe Mode script. I wish I could recall whom to credit. It did require that I download 2 .vbs files (SafeModeBoot.vbs and SafeModeNormal.vbs), as well as 2 .reg files (SafeMode_Reboot_KaUsrTsk.reg & SafeMode_Reboot_KaUsrTskWin2k.reg). I included the filenames so you could search for them in forum. If you can't find them, I could attach. FYI you need to copy these 4 files to your KServer's \Kaseya\WebPages\ManagedFiles\VSASharedFiles folder.

    Oops, just noticed there's a 5th file to place in your VSASharedFiles folder - instsrv.exe. Again, search forum for this file...

    It has worked very reliably for me the half dozen or so times I needed to remotely force a machine into safe mode and get rid of some spyware. But all my client machines had normal partitions (single drive: C), so no idea how this will work for your needs. Good luck!

    Here is an export of my Reboot to Safe Mode script:
    Script Name: Reboot to Safe Mode
    Script Description:

    IF True
    THEN
    Get Variable
    Parameter 1 : 10
    Parameter 2 :
    Parameter 3 : temp
    OS Type : 0
    Get Variable
    Parameter 1 : 0
    Parameter 2 : HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\AgentMon.Exe\Path
    Parameter 3 : installpath
    OS Type : 0
    Write File
    Parameter 1 : #temp#\SafeModeBoot.vbs
    Parameter 2 : VSASharedFiles\VB Files\safemodeboot.vbs
    OS Type : 0
    Write File
    Parameter 1 : #temp#\safemode_reboot_kausrtsk.reg
    Parameter 2 : VSASharedFiles\safemode_reboot_kausrtsk.reg
    OS Type : 0
    Write File
    Parameter 1 : #temp#\safemode_reboot_kausrtskwin2k.reg
    Parameter 2 : VSASharedFiles\safemode_reboot_kausrtskwin2k.reg
    OS Type : 13
    Write File
    Parameter 1 : #temp#\instsrv.exe
    Parameter 2 : VSASharedFiles\instsrv.exe
    OS Type : 0
    Execute Shell Command
    Parameter 1 : #temp#\instsrv.exe "KaUsrTsk" #installpath#kausrtsk.exe
    Parameter 2 : 1
    OS Type : 0
    Execute Shell Command
    Parameter 1 : regedit.exe /s "#temp#\safemode_reboot_kausrtsk.reg"
    Parameter 2 : 0
    OS Type : 0
    Execute Shell Command
    Parameter 1 : regedit.exe /s "#temp#\safemode_reboot_kausrtskwin2k.reg"
    Parameter 2 : 0
    OS Type : 13
    Execute Shell Command
    Parameter 1 : wscript "#temp#\SafeModeBoot.vbs"
    Parameter 2 : 1
    OS Type : 0
    Delete File
    Parameter 1 : #temp#\safemode_reboot_kausrtsk.reg
    OS Type : 0
    Delete File
    Parameter 1 : #temp#\safemode_reboot_kausrtskwin2k.reg
    OS Type : 0
    Delete File
    Parameter 1 : #temp#\SafeModeBoot.vbs
    OS Type : 0
    Reboot
    OS Type : 0
    ELSE

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: ReedMikel
  • Yeah... that is a good script! I have used it several times with high sucess.

    However be aware of the following "gotchas":


    1. It modifies the boot.ini file. So if you're dealing with a system that has goofy partitions, don't use it without adjusting the script first!
    2. Vista does not have a boot.ini file, so this will not work with it (anyone came up with something for Vista yet?


    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: boudj
  • Anyone figured a way around the dialoge box asking for permission to enter safe mode, or go to system restore?

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: charles.russell
  • Charles,

    I run a script to disable UAC before my maintenance scripts, and a script to enable it again afterward. Note that after running each of these scripts you need to reboot for it to take effect. I call this script from a master script for all of my maintenance, which includes the reboots where required.



    Script Name: Disable UAC
    Script Description:

    IF Check Registry Value
    Parameter 1 : HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\ConsentPromptBehaviorAdmin
    not = :0
    THEN
    Set Registry Value
    Parameter 1 : HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Security Center\UACDisableNotify
    Parameter 2 : 1
    Parameter 3 : REG_DWORD
    OS Type : 10
    Pause Script
    Parameter 1 : 5
    OS Type : 10
    Set Registry Value
    Parameter 1 : HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\EnableLUA
    Parameter 2 : 1
    Parameter 3 : REG_DWORD
    OS Type : 10
    Set Registry Value
    Parameter 1 : HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\ConsentPromptBehaviorAdmin
    Parameter 2 : 0
    Parameter 3 : REG_DWORD
    OS Type : 10
    Pause Script
    Parameter 1 : 5
    OS Type : 10
    ELSE








    Script Name: Enable UAC
    Script Description:

    IF Check Registry Value
    Parameter 1 : HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\ConsentPromptBehaviorAdmin
    not = :2
    THEN
    Set Registry Value
    Parameter 1 : HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Security Center\UACDisableNotify
    Parameter 2 : 0
    Parameter 3 : REG_DWORD
    OS Type : 10
    Pause Script
    Parameter 1 : 5
    OS Type : 10
    Set Registry Value
    Parameter 1 : HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\EnableLUA
    Parameter 2 : 1
    Parameter 3 : REG_DWORD
    OS Type : 10
    Set Registry Value
    Parameter 1 : HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\ConsentPromptBehaviorAdmin
    Parameter 2 : 2
    Parameter 3 : REG_DWORD
    OS Type : 10
    Pause Script
    Parameter 1 : 5
    OS Type : 10
    ELSE

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: djmundy
  • Not tested in Vista, but this command works on 2000 and XP regardless of partitioning:

    bootcfg /Raw "/safeboot:network /sos /bootlog /noguiboot" /id 1

    Make sure Kaseya is set to run in safe-mode:

    Set Registry Value
    Parameter 1 : HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SafeBoot\Network\WinVNC4\
    Parameter 2 : Service
    Parameter 3 : REG_SZ
    OS Type : 0
    Set Registry Value
    Parameter 1 : HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SafeBoot\Network\KaseyaAgent\
    Parameter 2 : Service
    Parameter 3 : REG_SZ
    OS Type : 0


    And when you're ready to reboot into normal mode:

    bootcfg /Raw "/noexecute=optin /fastdetect" /id 1

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: nevesis
  • nevesis,

    Thats got to be the best way to boot into safemode. So simple and no need to worry about partitions!

    Thanks so much!

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: Resistance2Fly
  • THANKS nevesis - that is a nice clean script. I've replaced my old Boot to safe/normal scripts with this...

    I wish Kaseya would expand/improve their Public script offerings by taking advantage of generous contributions like this...

    Imagine if Kaseya used a staffer to cull thru these forums looking for the best scripts, then packaged the best ones into Public scripts available to all. They do not seem to have the time to write scripts, as I have not noticed any new Public scripts in the year since I came onboard. This would be an inexpensive way for them to improve the core product...

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: ReedMikel
  • ReedMikel

    Imagine if Kaseya used a staffer to cull thru these forums looking for the best scripts, then packaged the best ones into Public scripts available to all. They do not seem to have the time to write scripts, as I have not noticed any new Public scripts in the year since I came onboard. This would be an inexpensive way for them to improve the code product...


    Great idea...
    +1

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: Resistance2Fly
  • Great Script - thanks for sharing! I tweaked it for my own purposes, but the command lines were the things I was really looking for.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: geoff@lynxcomputing.com
  • Some nice stuff here... sure is better then the other scripts I've had. I went ahead and captured everything into one script. I've tested this with XP and Vista tonight... works great. If someone can test with Win2003 and Win2008 servers, that would be very cool.

    This script will set you up for safe mode properly, then write a CMD file in the Kaseya temp dir that will resetup your system for normal boot.

    You must make sure you have the VNC remote control install prior to going into safe mode, you can't install it once you are in safe mode.


    Script Name: Config Boot to safe mode
    Script Description: Configure machine to run Kaseya and VNC agents when booted in safe mode, then flip machine to safe mode via a reboot. A script called ExitSafeMode.cmd is written to the Kaseya agent temp location (usually C:\TEMP) which will reconfigure back to normal mode. You can then reboot at will and you should be cool!

    Connections for Business - David Bennett

    IF True
    THEN
    Set Registry Value
    Parameter 1 : HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SafeBoot\Network\WinVNC4\
    Parameter 2 : Service
    Parameter 3 : REG_SZ
    OS Type : 1
    Set Registry Value
    Parameter 1 : HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SafeBoot\Network\KaseyaAgent\
    Parameter 2 : Service
    Parameter 3 : REG_SZ
    OS Type : 1
    Execute Shell Command
    Parameter 1 : bootcfg /Raw "/safeboot:network /sos /bootlog /noguiboot" /id 1
    Parameter 2 : 1
    OS Type : 3
    Execute Shell Command
    Parameter 1 : bootcfg /Raw "/safeboot:network /sos /bootlog /noguiboot" /id 1
    Parameter 2 : 1
    OS Type : 8
    Execute Shell Command
    Parameter 1 : bootcfg /Raw "/safeboot:network /sos /bootlog /noguiboot" /id 1
    Parameter 2 : 1
    OS Type : 9
    Execute Shell Command
    Parameter 1 : bcdedit /set {current} safeboot network
    Parameter 2 : 1
    OS Type : 10
    Execute Shell Command
    Parameter 1 : bcdedit /set {current} safeboot network
    Parameter 2 : 1
    OS Type : 11
    Send Message
    Parameter 1 : Your computer will boot into SAFE MODE in 10 seconds. Please close all your applications NOW!
    Parameter 2 : 1
    OS Type : 1
    Pause Script
    Parameter 1 : 10
    OS Type : 1
    Execute Shell Command
    Parameter 1 : echo bcdedit /deletevalue {current} safeboot >>#vAgentConfiguration.AgentTempDir#\ExitSafeMode.cmd
    Parameter 2 : 1
    OS Type : 10
    Execute Shell Command
    Parameter 1 : echo bcdedit /deletevalue {current} safeboot >>#vAgentConfiguration.AgentTempDir#\ExitSafeMode.cmd
    Parameter 2 : 1
    OS Type : 11
    Execute Shell Command
    Parameter 1 : echo bootcfg /Raw "/noexecute=optin /fastdetect" /id 1 >>#vAgentConfiguration.AgentTempDir#\ExitSafeMode.cmd
    Parameter 2 : 1
    OS Type : 9
    Execute Shell Command
    Parameter 1 : echo bootcfg /Raw "/noexecute=optin /fastdetect" /id 1 >>#vAgentConfiguration.AgentTempDir#\ExitSafeMode.cmd
    Parameter 2 : 1
    OS Type : 8
    Execute Shell Command
    Parameter 1 : echo bootcfg /Raw "/noexecute=optin /fastdetect" /id 1 >>#vAgentConfiguration.AgentTempDir#\ExitSafeMode.cmd
    Parameter 2 : 1
    OS Type : 3
    Reboot
    OS Type : 1
    ELSE



    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: dbennett
  • Very nice! Thank you.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: SMason
  • Have a notebook that si bluescreeing when trying to go into safe mode after running the safemode.vbs
    First time, not had an issue with until now.

    Anyway to get it to boot normally?

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: Steve Morris
  • f8 > boot to safemode command prompt, the edit the bootcfg?

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: thirteentwenty