Avatar billede ferdinand.k Mester
14. august 2003 - 16:04 Der er 4 kommentarer og
1 løsning

skub drev ud

Jeg sidder med en access database. Jeg skal have en knap der laver backup på et flytbart drev (usb stick) og derefter skubber sticken ud (unmounter ell) således at jeg ikke mister data... er der nogen der har  forsøgt sig med det før?
Avatar billede ferdinand.k Mester
14. august 2003 - 16:38 #1
backup'en er ikke noget problem, det er kun "udskubningen" af disken spørgsmålet lyder på...
Avatar billede ferdinand.k Mester
20. august 2003 - 09:27 #2
er det for nemt, eller skal der flere point til? Jeg har forsøgt mig med nedenstående, men den slukker bare drevet. Det jeg skal bruge, er at drevet bliver stoppet...


Public Const DRIVE_REMOVABLE = 2
Public Const DRIVE_CDROM = 5
Public Const INVALID_HANDLE_VALUE As Long = -1&
Public Const GENERIC_READ As Long = &H80000000
Public Const FILE_SHARE_READ As Long = &H1
Public Const FILE_SHARE_WRITE As Long = &H2
Public Const FILE_ANY_ACCESS As Long = &H0
Public Const FILE_READ_ACCESS  As Long = &H1
Public Const FILE_WRITE_ACCESS As Long = &H2
Public Const OPEN_EXISTING As Long = 3
Public Const IOCTL_STORAGE_MEDIA_REMOVAL As Long = &H2D4804

Public Type PREVENT_MEDIA_REMOVAL
  PreventMediaRemoval As Byte
End Type

Public Declare Function GetLogicalDriveStrings Lib "kernel32" _
  Alias "GetLogicalDriveStringsA" _
  (ByVal nBufferLength As Long, _
  ByVal lpBuffer As String) As Long
 
Public Declare Function GetDriveType Lib "kernel32" _
  Alias "GetDriveTypeA" _
  (ByVal lpRootPathName As String) As Long
 
Public 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, _
  lpOverlapped As Any) As Long

Public Declare Function CreateFile Lib "kernel32" _
  Alias "CreateFileA" _
  (ByVal lpFileName As String, _
  ByVal dwDesiredAccess As Long, _
  ByVal dwShareMode As Long, _
  lpSecurityAttributes As Any, _
  ByVal dwCreationDisposition As Long, _
  ByVal dwFlagsAndAttributes As Long, _
  ByVal hTemplateFile As Long) As Long

Public Declare Function CloseHandle Lib "kernel32" _
  (ByVal hObject As Long) As Long

Public Function DeviceLock(sDrive As String, fLock As Boolean) As Boolean

  Dim hDevice As Long
  Dim PMR As PREVENT_MEDIA_REMOVAL
  Dim bytesReturned As Long
  Dim success As Long
 
  'the drive letter has to be passed
  'to CreateFile without a trailing slash (ie 'G:')
  sDrive = UnQualifyPath(sDrive)
 
  'obtain a handle to the device
  'using the correct device syntax
  hDevice = CreateFile("\\.\" & sDrive, _
                        GENERIC_READ, _
                        FILE_SHARE_READ Or FILE_SHARE_WRITE, _
                        ByVal 0&, _
                        OPEN_EXISTING, _
                        0&, 0&)

   
  If hDevice <> INVALID_HANDLE_VALUE Then

    'assign the fLock value to the
    'PREVENT_MEDIA_REMOVAL type
      PMR.PreventMediaRemoval = CByte(Abs(fLock))
 
    'If the operation succeeds,
    'DeviceIoControl returns a nonzero value
      success = DeviceIoControl(hDevice, _
                                IOCTL_STORAGE_MEDIA_REMOVAL, _
                                PMR, _
                                Len(PMR), _
                                ByVal 0&, _
                                0&, _
                                bytesReturned, _
                                ByVal 0&)
 
  End If
                     
  Call CloseHandle(hDevice)
  DeviceLock = success
 
End Function


Private Function UnQualifyPath(ByVal sPath As String) As String

  'removes any trailing slash from the path
  sPath = Trim$(sPath)
 
  If Right$(sPath, 1) = "\" Then
        UnQualifyPath = Left$(sPath, Len(sPath) - 1)
  Else: UnQualifyPath = sPath
  End If
 
End Function
Avatar billede shjdsi Nybegynder
21. august 2003 - 11:32 #3
Avatar billede ferdinand.k Mester
30. oktober 2003 - 10:56 #4
jeg har STADIG brug for hjælp her....
Avatar billede ferdinand.k Mester
20. november 2003 - 10:57 #5
lukker...
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester

Seneste spørgsmål Seneste aktivitet
I dag 10:21 Ny printer, men hvilken Af mort1 i Printere
I går 19:41 USB på Linux Af Uvanga i Linux
12/0818:26 Hvilken type mus Af mort1 i PC
11/0813:21 ms Forms Af leahcim i Andet software
10/0821:30 Blokeret på Snapchat? Af LineP i Chat & Messaging