Hi!
I have written code to change name of the drive, for example drive 'D' to drive 'E' it runs successfully but to reflect the changes i need to restart my machine. So please provide any solution which will cause to reflect the changes without restarting my machine. I have made necessary changes in the registry by code but these changes are not reflected immediately for that i have to restart my machine plz if any suggestion.
But when I am trying to rename drive letter from the computer management it works fine and we don't have to restart the machine. so i just want to know which are the windows API's are calling while renaming the drive letter. I need a solution which is totally part of C++.
// Set new value into the registry.
result = RegSetValueEx(hkey,newstr.GetBuffer(newstr.GetLength()),NULL,Type,dat,cbData);
if(result!=ERROR_SUCCESS)
{
MessageBox(NULL,L"Failed to set the value in Registry",L"Error", MB_OK | MB_ICONERROR );
return 0;
}
// Now the old drive name is deleted in the registry
result = RegDeleteValue(hkey,oldstr.GetBuffer(oldstr.GetLength()));
if(result!=ERROR_SUCCESS)
{
MessageBox(NULL,L"Failed in deleting the Value",L"Error", MB_OK | MB_ICONERROR );
return 0;
}
RegCloseKey(hkey);
return 0;
}
After execution of this code i will get corresponding changes in registry but those changes are not reflected in the explorer. For that i have to restart the system which i won't.
ya the program is changing only registry entries, but i want those changes reflected on the explorer means drive letter are getting changed but not shown in the explorer for that i have to restart the system. So plz tell me the further solution as i am beginner.
As we can change drive letter from control panel --> computer management --> Disk management by right click on volume header. same thing I want to do using c++. I am succeed for making changes in the registry but those are not reflecting in the explorer for that I have restart my system which I won't. I think as we can successfully change the drive letter using computer management we can have those changes using programming also. As I am new to this area please provide any solution regarding this. What is happening while making changes through computer management or what are API's are called or If I am doing completely wrong then also you can suggest me for the correct way.
#define _WIN32_WINNT 0x500
#include <iostream>
#include <windows.h>
usingnamespace std;
int main()
{
char *old_mountpoint="H:\\",
*new_mountpoint="G:\\";
char unc_path[512]; // UNC path is needed to mount a device
GetVolumeNameForVolumeMountPoint(old_mountpoint,unc_path,512); // Get the UNC path of the volume
clog <<"UNC path of the disk: "<<unc_path<<endl;
DeleteVolumeMountPoint(old_mountpoint);
SetVolumeMountPoint(new_mountpoint,unc_path);
}
The function in the above code return error 123 I think the path specified in old_mountpoint parameter is wrong i have also tried path as \\.\\H:\\ but it is not working.