-----------------------------------------------------------

New Message on BDOTNET

-----------------------------------------------------------
From: Z?�n
Message 1 in Discussion




C:\code 
>mount a: c:\MountPoint<o:p></o:p>

Managed 
Unix-style mount program<o:p></o:p>

Mounting 
volume a:\ at c:\MountPoint\<o:p></o:p>

<o:p> </o:p>

C:\code 
>dir c:\MountPoint<o:p></o:p>

 Volume in drive C is 
Brian<o:p></o:p>

 Volume Serial Number is 
186C-51E7<o:p></o:p>

<o:p> </o:p>

 Directory of 
c:\MountPoint<o:p></o:p>

<o:p> </o:p>

01/27/2003  03:11 AM            15,229 
Queue.cs<o:p></o:p>

01/27/2003  06:10 PM            
44,098 SortedDictionary.cs<o:p></o:p>

01/27/2003  03:26 AM            
11,100 Stack.cs<o:p></o:p>

               
3 File(s)         
70,427 bytes<o:p></o:p>

 

http://blogs.msdn.com/brada/archive/2004/04/01/105946.aspx

 

 

 

//--------------------------------------------------------------------

 

using System;<o:p></o:p>

using 
System.Runtime.InteropServices;<o:p></o:p>

using System.Text;<o:p></o:p>

using System.IO;<o:p></o:p>

using System.ComponentModel;<o:p></o:p>

<o:p> </o:p>

public class 
UnixLikeMountProgram<o:p></o:p>

{<o:p></o:p>

    [DllImport("kernel32", 
CharSet=CharSet.Auto, BestFitMapping=false, 
SetLastError=true)]<o:p></o:p>

    private static extern bool 
GetVolumeNameForVolumeMountPoint(String volumeName, StringBuilder 
uniqueVolumeName, int 
uniqueNameBufferCapacity);<o:p></o:p>

<o:p> </o:p>

    // unique volume name must be 
"\\?\Volume{GUID}\"<o:p></o:p>

    [DllImport("kernel32", 
CharSet=CharSet.Auto, BestFitMapping=false, 
SetLastError=true)]<o:p></o:p>

    private static extern bool 
SetVolumeMountPoint(String mountPoint, String 
uniqueVolumeName);<o:p></o:p>

<o:p> </o:p>

    [DllImport("kernel32", 
CharSet=CharSet.Auto, BestFitMapping=false, 
SetLastError=true)]<o:p></o:p>

    private static extern bool 
DeleteVolumeMountPoint(String mountPoint);<o:p></o:p>

<o:p> </o:p>

<o:p> </o:p>

    private static void Usage()<o:p></o:p>

    {<o:p></o:p>

        
Console.WriteLine();<o:p></o:p>

        
Console.WriteLine("mount <volume name> <mount 
point>");<o:p></o:p>

        
Console.WriteLine("mount -u <mount point>");<o:p></o:p>

    }<o:p></o:p>

<o:p> </o:p>

    private static void Mount(string 
volumeName, string 
mountPoint)<o:p></o:p>

    {<o:p></o:p>

        
Console.WriteLine("Mounting volume {0} at {1}", volumeName, 
mountPoint);<o:p></o:p>

        
bool r;<o:p></o:p>

        
StringBuilder sb = new 
StringBuilder(1024);<o:p></o:p>

        r = 
GetVolumeNameForVolumeMountPoint(volumeName, sb, 
sb.Capacity);<o:p></o:p>

        
if (!r)<o:p></o:p>

            
throw new 
Win32Exception(Marshal.GetLastWin32Error());<o:p></o:p>

<o:p> </o:p>

        
String uniqueName = sb.ToString();<o:p></o:p>

        r = 
SetVolumeMountPoint(mountPoint, uniqueName);<o:p></o:p>

        
if (!r)<o:p></o:p>

            
throw new 
Win32Exception(Marshal.GetLastWin32Error());<o:p></o:p>

    }<o:p></o:p>

<o:p> </o:p>

    private static void Unmount(string 
mountPoint)<o:p></o:p>

    {<o:p></o:p>

        
Console.WriteLine("Unmounting the volume at {0}", 
mountPoint);<o:p></o:p>

<o:p> </o:p>

        
bool r = 
DeleteVolumeMountPoint(mountPoint);<o:p></o:p>

        
if (!r)<o:p></o:p>

            
throw new 
Win32Exception(Marshal.GetLastWin32Error());<o:p></o:p>

    }<o:p></o:p>

<o:p> </o:p>

    private static void <st1:place 
w:st="on">Main</st1:place>(string[] args) 
<o:p></o:p>

    {<o:p></o:p>

        
Console.WriteLine("Managed Unix-style mount 
program");<o:p></o:p>

<o:p> </o:p>

        
if (args.Length != 2) 
{<o:p></o:p>

            
Usage();<o:p></o:p>

            
return;<o:p></o:p>

        
}<o:p></o:p>

<o:p> </o:p>

        
bool unmount = false;<o:p></o:p>

        
String volumeName = null;<o:p></o:p>

        
String mountPoint = args[1];<o:p></o:p>

        
<o:p></o:p>

        
if (args[0].Equals("-u") || 
args[0].Equals("/u"))<o:p></o:p>

            
unmount = true;<o:p></o:p>

        
else {<o:p></o:p>

            
volumeName = args[0];<o:p></o:p>

<o:p> </o:p>

            
if (volumeName[volumeName.Length - 1] != 
Path.DirectorySeparatorChar)<o:p></o:p>

                
volumeName += Path.DirectorySeparatorChar;<o:p></o:p>

        
}<o:p></o:p>

<o:p> </o:p>

        
if (mountPoint[mountPoint.Length - 1] != 
Path.DirectorySeparatorChar)<o:p></o:p>

            
mountPoint += Path.DirectorySeparatorChar;<o:p></o:p>

<o:p> </o:p>

        
if (unmount)<o:p></o:p>

            
Unmount(mountPoint);<o:p></o:p>

        
else<o:p></o:p>

            
Mount(volumeName, mountPoint);<o:p></o:p>

    }<o:p></o:p>

<o:p> </o:p>

}


  
  
    Creator 
    Brad Abrams [MSFT]
 

Regards
Sajay 
Antony 
 

-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/BDotNet/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you received 
this message by mistake, please click the "Remove" link below. On the pre-addressed 
e-mail message that opens, simply click "Send". Your e-mail address will be deleted 
from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to