Comment monter et demonter un volume(lecteur )

petermadio Messages postés 30 Date d'inscription lundi 10 avril 2006 Statut Membre Dernière intervention 24 décembre 2011 - 4 mai 2006 à 00:26
petermadio Messages postés 30 Date d'inscription lundi 10 avril 2006 Statut Membre Dernière intervention 24 décembre 2011 - 17 mai 2006 à 18:24
Salut à tous!
Il s'agit de créer un volume(disque) virtuel , de le démonter c'est à dire de le déconnecter à tout moment pour une utilisation sécuisée.Mais j'ai une idée pour la création mais jusque là comment le démonter .
Quelqu'un a-t-il une idée de comment monter et demonter.Même pour la création je suis partent.Toute code est acceptable
Merci !

3 réponses

sebseb42 Messages postés 495 Date d'inscription dimanche 6 juillet 2003 Statut Membre Dernière intervention 9 novembre 2007 1
4 mai 2006 à 11:03
je ne puis hélas pas t'aider, mais je suis aussi vraiment tres interessé par la question... enfin surtout par les réponses :)
0
cs_coq Messages postés 6349 Date d'inscription samedi 1 juin 2002 Statut Membre Dernière intervention 2 août 2014 101
14 mai 2006 à 16:38
Salut,

La classe WMI Win32_Volume possède entre autres les méthodes Mount et Dismount.

Sinon directement côté API il y a la section Volume Management.

/*
coq
MVP Visual C#
*/
0
petermadio Messages postés 30 Date d'inscription lundi 10 avril 2006 Statut Membre Dernière intervention 24 décembre 2011
17 mai 2006 à 18:24
Salut ,
Merci coq.J'ai essayé avec ce que tu m'as montré une application mais ça ne fonctionne pas.Je suis totalement perdu,comme je suis aussi une débutant, serait-il possible que tu me donnes un exemple qui marche .
Merci !

Voici le code que j'ai testé:

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Text;
using System.IO;
using System.ComponentModel;
using System.Management;




namespace Exo16
{
 class MainClass
 {
  [DllImport("kernel32", CharSet=CharSet.Auto, BestFitMapping=false, SetLastError=true)]


    private static extern bool GetVolumeNameForVolumeMountPoint(String volumeName, StringBuilder uniqueVolumeName, int uniqueNameBufferCapacity); 


    // unique volume name must be "[file://\\?\Volume{GUID}\ \\?\Volume{GUID}\]"


    [DllImport("kernel32", CharSet=CharSet.Auto, BestFitMapping=false, SetLastError=true)]


    private static extern bool SetVolumeMountPoint(String mountPoint, String uniqueVolumeName); 


    [DllImport("kernel32", CharSet=CharSet.Auto, BestFitMapping=false, SetLastError=true)]


    private static extern bool DeleteVolumeMountPoint(String mountPoint);
    private static void Usage()


    {        Console.WriteLine();


        Console.WriteLine("mount <volume name> <mount point>");


        Console.WriteLine("mount -u <mount point>");


    }


    private static void Mount(string volumeName, string mountPoint)


    {


        Console.WriteLine("Mounting volume {0} at {1}", volumeName, mountPoint);


        bool r;
       


        StringBuilder sb = new StringBuilder(1024);


        r = GetVolumeNameForVolumeMountPoint(volumeName, sb, sb.Capacity);


        if (!r)


            throw new Win32Exception(Marshal.GetLastWin32Error());


 


        String uniqueName = sb.ToString();


        r = SetVolumeMountPoint(mountPoint, uniqueName);


        if (!r)


            throw new Win32Exception(Marshal.GetLastWin32Error());


    }


 


    private static void Unmount(string mountPoint)


    {


        Console.WriteLine("Unmounting the volume at {0}", mountPoint);


 


        bool r = DeleteVolumeMountPoint(mountPoint);


        if (!r)


            throw new Win32Exception(Marshal.GetLastWin32Error());


    }


 


    private static void Main(string[] args)


    {
        Console.WriteLine("Managed Unix-style mount program");
        if (args.Length != 2) {
            Usage();
            return;
        }
        bool unmount = false;        String volumeName null;        String mountPoint args[1];    


        if (args[0].Equals("-u") || args[0].Equals("/u"))


            unmount = true;


        else {
            volumeName = args[0];
            if (volumeName[volumeName.Length - 1] != Path.DirectorySeparatorChar)                volumeName += Path.DirectorySeparatorChar;


        }


        if (mountPoint[mountPoint.Length - 1] != Path.DirectorySeparatorChar)


            mountPoint += Path.DirectorySeparatorChar; 


        if (unmount)
            Unmount(mountPoint);
        else
            Mount(volumeName, mountPoint);
   } 
 }
}
0
Rejoignez-nous