Use API To See If Windows Started In Safe Mode

Level:
Level1

Visual Basic gives us access to the Windows API which allows us to do virtually anything. In this source sample we will use the GetSystemMetrics API located in the user32 dll to find out how Windows was started. This is helpful if you want to do something different with your application based on if Windows started in Safe Mode, Safe Mode with Network Support, or Normal mode.

The easiest way to call Windows API's is to declared them in a module so to try this out create a new VB project. Then go to the Project Menu and click Add Module. Inside this module add the following code.

  1. Declare Function GetSystemMetrics Lib "user32" _
  2.         (ByVal nIndex As Long) As Long
  3. Public Const SM_CLEANBOOT = 67

No go to your main form, add a command button, double click on the button to go to its click event handler, and add the following code.

  1. Select Case GetSystemMetrics(SM_CLEANBOOT)
  2.     Case 1: MsgBox "Windows was Started in Safe Mode."
  3.     Case 2: MsgBox _
  4.                 "Windows was Started in Safe Mode with Network support."
  5.     Case Else: MsgBox "Windows is running normally."
  6. End Select

Once you've added the source code run your application and click on the button. You should see a message box that corresponds to the way you started Windows.

Obviously this just barely scratches the surface on what you can do with the Windows API. Check out the links below to find out more.

If you enjoyed this post, subscribe for updates (it's free)

SQL VB6

I WANT TO KNOW HOW I MAKE LOG IN FORM IN VB6 WITH SQL DATABASE?KINDLY SEND ME SMPLES CODE FOR THIS TOPIC

hi

but how to declare a function like (windows api)?

hi does any one knw to

hi
does any one knw to develop a windows application
from an already existing source code in vb.net

HI

Any one know, how can use flexgrid for maintanance the access database .

Thilanga...

ask

hi
any one
can any one have code how to save picture from scaner to data base and how can i serch and send it to imag1.picture from visual basic 6

hi

hi

any one know about how to link box to other box

Remo Rathna

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. The supported tag styles are: <foo>, [foo].

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.