The Windows Search dialog box (press [Windows]F) is very handy for finding a variety of items including
files, computers, and documents. One way that you can make this dialog box even
more useful is by displaying it from within a VB program.

To display the Search box, you’ll mimic the normal keypress, [Windows]F, with the keybd_event API function. Its definition and a few
constants must be placed in a module:

Public Declare Sub keybd_event Lib "user32" _
    (ByValbVk As Byte, _
    ByValbScan As Byte, _
    ByValdwFlags As Long, _
    ByValdwExtraInfo As Long)

Public Const VK_LWIN = &H5B
Public Const KEYEVENTF_KEYUP = &H2
Public Const VK_APPS = &H5D

Then send the required keystrokes from the program as
follows:

Private Sub Command1_Click()
    Call keybd_event(VK_LWIN, 0, 0, 0)
    Call keybd_event(&H46, 0, 0, 0)
    Call keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0)
End Sub

While you cannot transfer information from the Search dialog
box back to your program, it can still be very useful to locate a file in this
way while running a VB program.

Advance your scripting skills to the next level with TechRepublic’s free Visual Basic newsletter, delivered each Friday. Automatically sign up today!