Format or Copy Diskettes Using Windows API

Format or Copy Diskettes Using Windows API

The Win32 API includes a pair of functions that let you format and copy diskettes from your programs:

 Private Declare Function SHFormatDrive _        Lib "shell32" (ByVal hwnd As Long, _        ByVal Drive As Long, _        ByVal fmtID As Long, _        ByVal options As Long) As LongPrivate Declare Function GetDriveType _        Lib "kernel32" _        Alias "GetDriveTypeA" _        (ByVal nDrive As String) As Long

Add two command buttons to your form, named cmdDiskCopy and cmdFormatDrive, and place this codeinto their Click events:

 Private Sub cmdDiskCopy_Click()        ' DiskCopyRunDll takes two         ' parameters- From and To        Dim DriveLetter$, DriveNumber&, _                DriveType&        Dim RetVal&, RetFromMsg&        DriveLetter = UCase(Drive1.Drive)        DriveNumber = (Asc(DriveLetter) - _                65)        DriveType = GetDriveType_                (DriveLetter)        If DriveType = 2 Then  'Floppies, _                etc                RetVal = Shell_                        ("rundll32.exe " & _                        "diskcopy.dll," _                        & "DiskCopyRunDll " & _                        DriveNumber & "," & _                        DriveNumber, 1)         Else   ' Just in case                RetFromMsg = MsgBox_                        ("Only floppies can be " & _                        "copied", 64, _                        "DiskCopy Example")        End IfEnd SubPrivate Sub cmdFormatDrive_Click()        Dim DriveLetter$, DriveNumber&, _                DriveType&        Dim RetVal&, RetFromMsg%                DriveLetter = UCase(Drive1.Drive)        DriveNumber = (Asc(DriveLetter) - _                65)         ' Change letter to Number: A=0        DriveType = GetDriveType_                (DriveLetter)        If DriveType = 2 Then  _                'Floppies, etc                RetVal = SHFormatDrive(Me.hwnd, _                        DriveNumber, 0&, 0&)        Else                RetFromMsg = MsgBox_                        ("This drive is NOT a " & _                        "removeable drive! " & _                        "Format this drive?", _                        276, "SHFormatDrive Example")                If RetFromMsg = 6 Then                        ' UnComment to do it...                        'RetVal = SHFormatDrive_                                (Me.hwnd, _                                '   DriveNumber, 0&, 0&)                End If        End IfEnd Sub

Add one DriveListBox control named Drive1:

 Private Sub Drive1_Change()        Dim DriveLetter$, DriveNumber&, _                DriveType&        DriveLetter = UCase(Drive1.Drive)        DriveNumber = (Asc(DriveLetter) - _                65)        DriveType = GetDriveType_                (DriveLetter)        If DriveType <> 2 Then  _                'Floppies, etc                cmdDiskCopy.Enabled = False        Else                cmdDiskCopy.Enabled = True        End IfEnd Sub

Be careful: this function can even format the hard disk.

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes