Online Book Reader

Home Category

Access Cookbook - Ken Getz [233]

By Root 1830 0
find that all applications get the shutdown message except the one that called this function. Check the behavior of your target operating system.

acbReboot

Reboots the computer.

acbShutDown

Shuts down the system to a point at which it is safe to turn off the power. All file buffers are flushed to disk, and all running processes are stopped.

Discussion


Normally, when you shut down Windows, it sends a message to check with every running application before shutting down. If other applications have any unsaved data files that require user intervention, you'll usually be asked if it's okay to save the files. Once all the applications have agreed to shut down, Windows shuts itself down.

Windows follows the same shutdown procedures when you use any of the functions listed in Table 11-4. The only difference is what happens after Windows shuts down.

The basExitWindows module is simple: it merely calls directly into the ExitWindowsEx API function. The entire module looks like this:

Declare Function acb_apiExitWindowsEx Lib "user32" Alias "ExitWindowsEx" _

(ByVal uFlags As Long, ByVal dwReserved As Long) As Long

' EWX_FORCE

' Forces processes to terminate. Instead of bringing up the

' "application not responding" dialog for the user, this value

' forces an application to terminate if it does not respond.

' EWX_LOGOFF

' Shuts down all processes running in the security context

' of the process that called the ExitWindowsEx function, then

' logs off the user.

' EWX_REBOOT

' Shuts down the system, then restarts the system.

' EWX_SHUTDOWN

' Shuts down the system to a point at which it is safe to turn off

' the power. All file buffers have been flushed to disk, and all

' running processes have stopped.

Const EWX_LOGOFF = 0

Const EWX_SHUTDOWN = 1

Const EWX_REBOOT = 2

Const EWX_FORCE = 4

Public Function acbReboot( )

acbReboot = acb_apiExitWindowsEx(EWX_REBOOT, 0)

End Function

Public Function acbShutDown( )

acbShutDown = acb_apiExitWindowsEx(EWX_SHUTDOWN, 0)

End Function

Public Function acbLogOff( )

acbLogOff = acb_apiExitWindowsEx(EWX_LOGOFF, 0)

' This is actually necessary only in some operating systems,

' but it can't hurt.

Application.Quit acExit

End Function

Each function listed in Table 11-4 has its own role. You're most likely to use acbShutDown when your application is meant for users who use only Access. When they're done with your application, they're done with Windows. The other functions are more useful in utility applications other than Access; use your imagination! There may be reasons why you'd need to reboot; for example, perhaps you've changed a setting in the Windows registry for the user and you want it to take effect immediately.

Certainly, these are not functions that every application will need or that you will use every day. But if you need to control what happens once your application has done its work, they are valuable indeed.

11.7. Run the Application Associated with a Data File


Problem


You'd like to find a way to provide a list of existing files, allow users to select a file, and run the appropriate application for that file. Windows knows how to do this—for instance, when you double-click on a file with a .TXT extension in Explorer, Windows runs Notepad with that file. How can you provide this sort of functionality in your own applications?

Solution


Windows provides two API functions, FindExecutable and ShellExecute, that make running a related application possible from within Access. Both functions rely heavily on the Windows registry, which tracks the relationships between filename extensions and related executable programs. Figure 11-8 shows the results of running the REGEDIT.EXE program, which ships as part of Windows. REGEDIT allows you to add, edit, modify, or delete file associations. (The registry editor is named REGEDT32.EXE under Windows NT and, though it looks different, it functions in a similar manner.)

Figure 11-8. REGEDIT.EXE, showing file types registered on a typical system

WARNING

Be sure not to change any of

Return Main Page Previous Page Next Page

®Online Book Reader