tags:

views:

859

answers:

2

Hi I am trying to mount as a drive in vista I am using the following code from msdn example,

     BOOL bFlag;
   TCHAR Buf[BUFSIZE];     // temporary buffer for volume name

   if( argc != 3 ) 
   {
      _tprintf( TEXT("Usage: %s <mount_point> <volume>\n"), argv[0] );
      _tprintf( TEXT("For example, \"%s c:\\mnt\\fdrive\\ f:\\\"\n"), argv[0]);
      return( -1 );
   }

  // We should do some error checking on the inputs. Make sure
  // there are colons and backslashes in the right places, etc. 

   bFlag = GetVolumeNameForVolumeMountPoint(
              argv[2], // input volume mount point or directory
                  Buf, // output volume name buffer
              BUFSIZE  // size of volume name buffer
           );

   if (bFlag != TRUE) 
   {
      _tprintf( TEXT("Retrieving volume name for %s failed.\n"), argv[2] );
      return (-2);
   }

   _tprintf( TEXT("Volume name of %s is %s\n"), argv[2], Buf );
   bFlag = SetVolumeMountPoint(
              argv[1], // mount point
                  Buf  // volume to be mounted
           );

   if (!bFlag)
     _tprintf (TEXT("Attempt to mount %s at %s failed.\n"), argv[2], argv[1]);

   return (bFlag);

It always gives an error of parameter is incorrect , I also tried definedosdevice at first then get the name, It also didn't work. Any idea how to make it work?

+1  A: 

You need to be more specific! Where exactly in the code do you get that error?

You could try and execute the following command via system() and see if it works this way:

subst K: “c:\blabla"
Chris
Yes it works with subst, "subst Y: c:\somefolder\"bFlag = GetVolumeNameForVolumeMountPoint( L"Y:\\", // input volume mount point or directory Buf, BUFSIZE ); gives the system can not find the specified file
Dincer Uyav
A: 

SetVolumeMountPoint is for mounting a volume on a drive letter or in a folder. It does not allow you to mount a folder on a drive letter. This is the opposite of what you want.

To make a folder available as a drive letter, you want to do the equivalent of the SUBST utility. This uses DefineDosDevice, something like this:

if (!DefineDosDevice(0, _T("Q:"), _T("C:\\Temp")))
    _ftprintf(stderr, _T("DefineDosDevice failed: %d\n"), GetLastError());

If you want to make this persistent, I think that you'll need to write a Windows service that does it at boot time. I wrote one about 10 years ago.

Roger Lipscombe
OK thanks, but I want it to persistent after reboots. I tried DefineDosDevice It works, how do I make it persistent?
Dincer Uyav
In the remarks section of DefineDosDevice in MSDN says:To define a drive letter assignment that is persistent across boots and not a network share, use the SetVolumeMountPoint function.
Dincer Uyav
Yeah, but SetVolumeMountPoint is for mounting volumes, not for aliasing folders. If you want it to persist, you'll probably have to write a service that does it, and configure it for Automatic.
Roger Lipscombe