Format usb in NTFS && FAT32

Dani_S 4,501 Reputation points
2024-12-19T10:52:27.74+00:00

Hi,

I want to format usb with NTFS and FAT32 in .NET8 , maui app.

I blocked the acccess to usb by device control policy.

And when I tried to format it I got this error:

Access Denied as you do not have sufficient privileges or

the disk may be locked by another process.

You have to invoke this utility running in elevated mode

and make sure the disk is unlocked.

Cannot open volume for direct access.

I used this code:

Can you please fix the problem ? Not using cmd? because this will problem to enabled it from device control policy point of view.

Developer technologies | .NET | .NET MAUI
Developer technologies | .NET | Other
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2024-12-20T02:45:45.7966667+00:00

    Hello,

    I blocked the acccess to usb by device control policy.

    After blocking USB Device through the policy group, the application will not be able to read or write USB hardware.

    Formatting the file system is a write operation. If the group policy prohibits reading and writing, formatting is not possible. In other words, the group policy that prohibits USB and formatting are mutually exclusive, and only one of them can be run.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.