I\'m trying to find out how to programmatically (I\'m using C#) determine the name (or i.p.) of servers to which my workstation has current maps. In other words, at some po
The WMI methods won't tell you whether the drive is set to reconnect on login. When you set a drive to reconnect on login, Windows creates a key under HKCU\Network\. The method below can be used to determine if the drive is set to be remapped at login.
private static bool DriveSetForReconnect(string ComputerName, string DriveLetter)
{
RegistryKey key = RegistryKey.OpenRemoteBaseKey(RegistryHive.CurrentUser, ComputerName);
key = key.OpenSubKey("Network\\" + DriveLetter);
return key != null;
}
HTH!
EDIT: To adapt the WMI solutions to work on any arbitrary machine, you need to change the scope parameter like the code below. You obviously have to have have admin rights on the remote machine.
string scope = string.Format(@"\\{0}\root\CIMV2", ComputerName);
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(scope,
"SELECT * FROM Win32_MappedLogicalDisk");