.comment-link {margin-left:.6em;}

kHSw

Sunday, November 28, 2004

Stop users from opening an Access application on the network

If you have an Access application and you want to force your users to copy it locally before using it (so multiple users can work on the same database on the same time), there's an easy way to stop them from running it over the network.

Create a module in your Access application and paste this code:
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long

Private Const DRIVE_UNKNOWN = 0
Private Const DRIVE_NO_ROOT_DIR = 1
Private Const DRIVE_REMOVABLE = 2
Private Const DRIVE_FIXED = 3
Private Const DRIVE_REMOTE = 4
Private Const DRIVE_CDROM = 5
Private Const DRIVE_RAMDISK = 6

Public Function CheckDrive()
If GetDriveType(Left(CurrentProject.Path, 3)) <> DRIVE_FIXED Then
MsgBox "Please do not run this program from the network drive!"
DoCmd.Quit
End If
End Function

Now create a new Macro and call it AUTOEXEC (this macro will be automatically run when the application is opened). In the Action column you select RunCode(), on the bottom of the screen type the name of the function you want to execute, this is CheckDrive() in my example.

I know, there's an easy way to circumvent this 'protection', but most end-users don't know the 'secret-Access-key'. I'm not going to put it here, because this key is well-known to all developers ;-)

I included the other drive-types if case you want to check for an other type of drive.

And a little bonus:
If you want to check if a drive is a CD or DVD (with the GetDriveType()-API you'll get DRIVE_CDROM for both), you can use this little piece of code:

Declare Function GetDiskFreeSpaceEx Lib "kernel32" Alias "GetDiskFreeSpaceExA" (ByVal lpRootPathName As String, lpFreeBytesAvailableToCaller As Currency, lpTotalNumberOfBytes As Currency, lpTotalNumberOfFreeBytes As Currency) As Long

Private Function IsDriveADVD() as Boolean
Dim UserSpaceFree as Currency
Dim TotalUserSpace as Currency
Dim TotalFreeSpace As Currency

GetDiskFreeSpaceEx("E:\", UserSpaceFree, TotalUserSpace, TotalFreeSpace)

Return (TotalUserSpace > 1073741824)
End Function

If the total bytes on the disk (independant of the number of bytes used) is more than 1GB, we assume it's a DVD...

0 Comments:

Post a Comment

<< Home


 
Stefanie Worm is het liefste vrouwtje van de wereld.
Melina is de liefste schatsie van de wereld (Erik De Maeyer).