IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

Formatage clé usb [Débutant]


Sujet :

C#

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre habitué
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2011
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2011
    Messages : 8
    Par défaut Formatage clé usb
    Bonjour,
    Je suis débutant dans le langage c#, j'ai trouvé sur internet des solutions pour formater une clé usb mais je ne comprends pas comment ces personnes font et je n'arrive pas à la reproduire.

    C'est pour cela que je me tourne vers vous, pouvez vous me montrer comment formater une clé usb ?

    Merci d'avance.

  2. #2
    Membre éclairé Avatar de solo190
    Homme Profil pro
    Consultant informatique
    Inscrit en
    Avril 2007
    Messages
    412
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : Cameroun

    Informations professionnelles :
    Activité : Consultant informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 412
    Par défaut
    Bonjour,
    regarde ce lien http://pinvoke.net/default.aspx/shell32.SHFormatDrive
    il peut etre utile.

  3. #3
    Membre habitué
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2011
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2011
    Messages : 8
    Par défaut
    Tout d'abord merci de ta réponse, j'avais déjà trouvé cette page mais je ne vois pas du tout comment m'en servir. J'ai commencé le c# il y a 2semaines du coup je ne connais pas tout dessus.

    Saurais-tu concrètement quoi écrire dans mon code? ou quoi intégrer?

    merci

  4. #4
    Membre habitué
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2011
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2011
    Messages : 8
    Par défaut
    J'ai trouvé ce code qui fonctionne très bien mais ouvre l'utilitaire Windows.

    Code cs : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
     
           public enum SHFormatFlags : uint
            {
                SHFMT_ID_DEFAULT = 0xFFFF,
                SHFMT_OPT_FULL = 0x1,
                SHFMT_OPT_SYSONLY = 0x2,
                SHFMT_ERROR = 0xFFFFFFFF,
                SHFMT_CANCEL = 0xFFFFFFFE,
                SHFMT_NOFORMAT = 0xFFFFFFD,
            }
     
            public const uint SHFMT_ERROR = 0xFFFFFFFF;
            public const uint SHFMT_CANCEL = 0xFFFFFFFE;
            public const uint SHFMT_NOFORMAT = 0xFFFFFFD;
     
            [DllImport("shell32.dll")]
     
            static extern uint SHFormatDrive(IntPtr hwnd, uint drive, uint fmtID,
       uint options);
     
     
            /// <summary>
            /// Permit to check the result of the format call
            /// Throw Exception with a detailed message
            /// </summary>
            /// <param name="shFormatResult"></param>
            public static void CheckFormatResult(uint shFormatResult)
            {
                if (shFormatResult == SHFMT_ERROR)
                    throw new Exception("An error occurred during the format. This does not indicate that the drive is unformattable.");
                if (shFormatResult == SHFMT_CANCEL)
                    throw new OperationCanceledException("The format was canceled.");
                if (shFormatResult == SHFMT_NOFORMAT)
                    throw new IOException("The drive cannot be formatted.");
     
                //we can exit normally
                return;
            }
     
            public void formatUSB()
            {      
                uint result = SHFormatDrive(this.Handle,
                      4, // formatting E:
                      (uint)SHFormatFlags.SHFMT_ID_DEFAULT,
                      0); // full format of E:
                if (result == (uint)SHFormatFlags.SHFMT_ERROR)
                    MessageBox.Show("Unable to format the drive");
            }
        }

    N'y a t'il pas un moyen de la faire automatiquement sans la fenêtre de formatage Windows?

  5. #5
    Membre habitué
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2011
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2011
    Messages : 8
    Par défaut
    Pour formater sans l'utilitaire Windows :

    Code cs : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
     [DllImport("user32.dll")]
            static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
     
            public void formatClé()
            {
                Methode_Ini myIni = new Methode_Ini();
                myIni.Load("fichier_Ini");
     
                //Utilisation de la class ProcessStartInfo
                ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.CreateNoWindow = false;
                startInfo.UseShellExecute = true;
                startInfo.FileName = "format";
                startInfo.WindowStyle = ProcessWindowStyle.Hidden;
                startInfo.Arguments = myIni.GetValue("CléUSB", "cheminClé") + " " + "/q" + " " + "/y";
     
                try
                {
                    // Démarrez le processus avec les infos que nous avons spécifié.
                    using (Process exeProcess = Process.Start(startInfo))
                    {
                        exeProcess.WaitForExit();
                    }
                }
                catch
                {
                    // Log error.
                }
            }

  6. #6
    Membre éclairé Avatar de solo190
    Homme Profil pro
    Consultant informatique
    Inscrit en
    Avril 2007
    Messages
    412
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : Cameroun

    Informations professionnelles :
    Activité : Consultant informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 412
    Par défaut
    salut,
    je crois que toi meme tu as trouvé la solution à ton problème.
    Félicitation.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Formatage disque USB externe
    Par chatisis dans le forum Virtualisation
    Réponses: 2
    Dernier message: 17/12/2010, 17h21
  2. Formatage clé usb sur Mac OS X
    Par The-Most-Wanted dans le forum Apple
    Réponses: 3
    Dernier message: 01/04/2010, 05h59
  3. Formatage clé USB
    Par compdev dans le forum Composants
    Réponses: 6
    Dernier message: 10/05/2009, 12h27
  4. Formatage Clé USB
    Par Marcant dans le forum WebDev
    Réponses: 1
    Dernier message: 18/07/2008, 15h25
  5. Réponses: 12
    Dernier message: 20/05/2007, 16h38

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo