Click here to Skip to main content
15,881,803 members
Articles / Desktop Programming / Win32
Tip/Trick

USB Reset Attribute

Rate me:
Please Sign up or sign in to vote.
5.00/5 (6 votes)
6 Apr 2014CPOL1 min read 21.3K   1.4K   10   4
Ultimate USB Reset Attribute with powerful option

Image 1

Introduction

What do you do when your Removal Device or USB gets affected by a virus and files are hidden? Most of the Antivirus scan the device and delete the virus only. So we can't see the files in our USB device which is hidden by the virus. So here, the "Ultimate USB Reset Attribute" comes with a powerful option.

Idea Behind the Code

I just embed my code with the existing one which is already available in here (CodeProject). So my first sincere thanks to CodeProject, without this I could not do it.

Using the Code

Using this code, the number of USB or removal devices is listed in a dropdown which is currently connected to a computer.

C#
if(!Directory .Exists (currDir ))
            return;
            //set the progress bar max value
            pbar.Maximum += Directory.GetFileSystemEntries(currDir).Count();
            //iterate over the files
            foreach (string ff in Directory.GetFiles(currDir))
            {   //super cast to the parent class FileSystemInfo
                ResetAttribute((new FileInfo(ff)) as FileSystemInfo );
             }
          
            foreach (string dr in Directory.GetDirectories(currDir))
            {
                if (!Directory.Exists(dr))
                    return;
                //reset the directory attribute
               ResetAttribute((new DirectoryInfo(dr)) as FileSystemInfo);
                      ScanFiles(dr); //scan the directory  
//Changing the file attributes by using this code.
try
            { //bitwise operator on the file attribute
                fsi.Attributes &= ~FileAttributes.Hidden;
                fsi.Attributes &= ~FileAttributes.System;

                fsi.Attributes &= ~FileAttributes.ReadOnly;
            pbar.Value += 1;
            }
            catch (Exception ex)
            {
                return;
            } 
//Whenever the main form is loaded, it checks and gets drive details by using this code.
var drv = from dr in DriveInfo.GetDrives()
                     where dr.IsReady == true && dr.DriveType == DriveType.Removable
                     select dr;
            foreach (DriveInfo dinfo in drv)
            {
                cmbUSB.Items.Add(dinfo.Name);
                cmbUSB.SelectedIndex = 0;
              } 
 
  DriveInfo dr = new DriveInfo(cmbUSB.SelectedItem.ToString());
    lblusb.Text = dr.VolumeLabel + " (" + dr.Name + ")"; 

Command Line Reseter

Just enter the Drive Letter that you want to reset. Using this code:

set /p letter=
attrib -s -h -a /s /d %letter%:\*.* 

Points of Interest

Hope this version helps you. This is the general idea which I got in my dreams!!!

Screenshots

Image 2

Image 3

History

What is new in USB Reset Attribute?

  • Command Line Reseter (you can reset your USB attributes using through Command Prompt too)
  • For any file or folder "Access Denied" error is fixed by Take Ownership Registry Tweak.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Junior)
India India
Workaholic!
Sr Software Developer.
Web Developer and Desktop Application Development.

Comments and Discussions

 
QuestionMissing screenshots Pin
Nelek7-Aug-15 5:46
protectorNelek7-Aug-15 5:46 
GeneralMy vote of 5 Pin
Volynsky Alex6-Apr-14 1:20
professionalVolynsky Alex6-Apr-14 1:20 
GeneralRe: My vote of 5 Pin
Prabakaran T6-Apr-14 3:10
professionalPrabakaran T6-Apr-14 3:10 
GeneralRe: My vote of 5 Pin
Volynsky Alex6-Apr-14 3:31
professionalVolynsky Alex6-Apr-14 3:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.