Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determining Safemode

Status
Not open for further replies.

ITXAssociates

Technical User
Feb 10, 2011
7
GB
The O/S exports a pointer to a ULONG variable called InitSafeBootMode that contains the Safe Mode settings.

Can anybody offer any guidance as to how to read the value and therefore determine if the system is in safe mode?

Thanks
 
What I found is that a device driver can refer to this:

This external variable is only resolved, if you actually compile a device driver, which you can't do in foxpro. This needs the device driver development kit DDK and it's ntoskrnl.lib and development in C++.

There is an easier method for applications. The mode is also said to be written to a registry key HKLM\SYSTEM\CurrentControlSet\Control\SafeBoot\Option\OptionValue, which I don't find in XP. But WMI also returns boot info and the windows API call to GetSystemMetrics() also can return the boot state.

Code:
objWMIService = GetObject("winmgmts:\\.\root\CIMV2") 
colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem",,48) 
For Each loItem In colItems
? "BootupState: " + loItem.BootupState
EndFor

or

Code:
#Define SM_CLEANBOOT 67
Declare Integer GetSystemMetrics In User32.dll Integer nIndex
lnBootmode = GetSystemMetrics(SM_CLEANBOOT)
? Icase(lnBootmode=0,"normal",;
    lnBootmode=1,"safe",;
    lnBootmode=2,"safe with network",;
    "unknown")

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top