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 "\\?\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);
}
}
}