Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Backup Database PID check
Dan Jackson 
            
3 years ago
Yo guys, hows it hanging?

I got to thinking. I might give the back up Database a whirl. Then I gots to thinking (yeah, still hurting). How awesome would it be if the Database could check if an external drive is connected and prompt the user to run back up?
You could run it on load or a timed event, or even on close button or unload.

Now, you could check for the drive letter fairly easily but they change and, more importantly, the drive letter could point to the wrong drive. Then I thought some more (losing consciousness at this point!) - could access check the device id? Then it would only run if the specific drive was present.

Ok, now Im thinking some more and Ive almost reached a totally different plane of existence!
- An unbound textbox for the user to paste their chosen device id into
- access looks up the value in textbox to see if the device ID is present
- would be really cool if it could then lookup the necessary drive letter and automatically present that as the backup path

Am I talking crazy or would this be achieveable? Cant wait for responses, cheers
Dan Jackson OP  @Reply  
            
3 years ago

Dan Jackson OP  @Reply  
            
3 years ago
I asked chatGPT's opinion and here's the response - it's beyond me so anyone to weigh in?

Yes, it is possible for Microsoft Access to read an external drive's device ID. You can do this by using Windows API functions from within Access. One way to do this is by using the "CreateFile" function to obtain a handle to the device, and then using the "DeviceIoControl" function to send an IOCTL_STORAGE_GET_DEVICE_NUMBER control code to retrieve the device number.

In this code, the GetDeviceID function takes a drive letter as input (e.g. "D") and returns the device ID as a long integer. You can call this function from your Access database to obtain the device ID of an external drive.

Here's an example code snippet in VBA:

code
Private Declare Function CreateFile Lib "kernel32" _
   Alias "CreateFileA" (ByVal lpFileName As String, _
   ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, _
   ByVal lpSecurityAttributes As Long, _
   ByVal dwCreationDisposition As Long, _
   ByVal dwFlagsAndAttributes As Long, _
   ByVal hTemplateFile As Long) As Long
  
Private Declare Function DeviceIoControl Lib "kernel32" _
   (ByVal hDevice As Long, _
   ByVal dwIoControlCode As Long, _
   lpInBuffer As Any, _
   ByVal nInBufferSize As Long, _
   lpOutBuffer As Any, _
   ByVal nOutBufferSize As Long, _
   lpBytesReturned As Long, _
   ByVal lpOverlapped As Long) As Long
  
Private Type STORAGE_DEVICE_NUMBER
   DeviceType As Long
   DeviceNumber As Long
   PartitionNumber As Long
End Type

Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2
Private Const GENERIC_READ = &H80000000
Private Const OPEN_EXISTING = 3
Private Const IOCTL_STORAGE_GET_DEVICE_NUMBER = &H2D1080

Function GetDeviceID(ByVal driveLetter As String) As Long
   Dim hDevice As Long
   Dim bytesReturned As Long
   Dim devNum As STORAGE_DEVICE_NUMBER
   Dim devID As Long
  
   hDevice = CreateFile("\\.\" & driveLetter & ":", _
      GENERIC_READ, FILE_SHARE_READ Or FILE_SHARE_WRITE, 0, _
      OPEN_EXISTING, 0, 0)
  
   If hDevice <> -1 Then
      If DeviceIoControl(hDevice, IOCTL_STORAGE_GET_DEVICE_NUMBER, 0, _
         0, devNum, Len(devNum), bytesReturned, 0) Then
         devID = devNum.DeviceNumber
      End If
      CloseHandle hDevice
   End If
  
   GetDeviceID = devID
End Function


Kevin Robertson  @Reply  
          
3 years ago
Have you tried it?

I had to add PtrSafe after Declare as I'm using 64 bit Access.
Private Declare PtrSafe Function

CloseHandle generates an compile error: Sub or Function not defined.
I remmed out that line and got a value returned. I don't know if it was the correct value, but at least no error.

MsgBox GetDeviceID("C") - returned a 0
MsgBox GetDeviceID("G") - returned a 2
Dan Jackson OP  @Reply  
            
3 years ago
Its waaaay beyond me at the moment. I'm still on Expert 12! I did pick up on it being 32 bit, would defo need to be 64
A Glenn Yesner  @Reply  
     
3 years ago
Didn't Richard do a video about using the PID of the drive to keep customers from loading a developer's program on more than one machine? Can't remember for sure if it was a Tech Help or a Developer (early to mid 30s) video. Probably could reverse engineer that to check for the existing PID.
Alex Hedley  @Reply  
           
3 years ago
A Glenn Yesner  @Reply  
     
3 years ago
The video I was thinking of might be Developer 35 lesson 1
A Glenn Yesner  @Reply  
     
3 years ago
The part about serial number starts at about 8:12 an goes to about 10:45.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 6/22/2026 10:06:29 PM. PLT: 0s