B
Bandu
Hi,
I got the following code segment called in my Setup custom installer
(c#), which not working. But if I called it from normal Winform, the
function work fine. the code is just a simple WMI query code got it
from forum to get a UNC path of a mapped drive. I'm not sure why
calling from custom installer causing the issue. I'm using VS2008.
searcher.Get(); , always return me 0 count when I called from custom
installer. But from Winform, I got the same amount as my mapped drive.
public static string GetUNC(string sFilePath)
{
MessageBox.Show(sFilePath.Substring(0, 2));
if (sFilePath == string.Empty || sFilePath.IndexOf(":") >
1)
{
MessageBox.Show("1");
return sFilePath;
}
if (sFilePath.StartsWith("\\"))
{
MessageBox.Show("2");
return (new Uri(sFilePath)).ToString();
}
ManagementScope myScope = new ManagementScope("\\root\
\cimv2");
myScope.Connect();
SelectQuery oQuery = new SelectQuery("SELECT * FROM
Win32_NetworkConnection");
ManagementObjectSearcher searcher = new
ManagementObjectSearcher(myScope, oQuery);
ManagementObjectCollection moc = searcher.Get();
MessageBox.Show(moc.Count.ToString());
foreach (ManagementObject managementObject in moc)
{
MessageBox.Show("3");
string sRemoteName = managementObject["RemoteName"] as
string;
string sLocalName = managementObject["LocalName"] as
string;
MessageBox.Show(sLocalName + " " + sRemoteName);
if (sLocalName == sFilePath.Substring(0, 2))
{
sRemoteName += sFilePath.Substring(2);
return (new Uri(sRemoteName)).ToString();
}
}
MessageBox.Show("4");
return sFilePath;
}
Regards,
Bandu
I got the following code segment called in my Setup custom installer
(c#), which not working. But if I called it from normal Winform, the
function work fine. the code is just a simple WMI query code got it
from forum to get a UNC path of a mapped drive. I'm not sure why
calling from custom installer causing the issue. I'm using VS2008.
searcher.Get(); , always return me 0 count when I called from custom
installer. But from Winform, I got the same amount as my mapped drive.
public static string GetUNC(string sFilePath)
{
MessageBox.Show(sFilePath.Substring(0, 2));
if (sFilePath == string.Empty || sFilePath.IndexOf(":") >
1)
{
MessageBox.Show("1");
return sFilePath;
}
if (sFilePath.StartsWith("\\"))
{
MessageBox.Show("2");
return (new Uri(sFilePath)).ToString();
}
ManagementScope myScope = new ManagementScope("\\root\
\cimv2");
myScope.Connect();
SelectQuery oQuery = new SelectQuery("SELECT * FROM
Win32_NetworkConnection");
ManagementObjectSearcher searcher = new
ManagementObjectSearcher(myScope, oQuery);
ManagementObjectCollection moc = searcher.Get();
MessageBox.Show(moc.Count.ToString());
foreach (ManagementObject managementObject in moc)
{
MessageBox.Show("3");
string sRemoteName = managementObject["RemoteName"] as
string;
string sLocalName = managementObject["LocalName"] as
string;
MessageBox.Show(sLocalName + " " + sRemoteName);
if (sLocalName == sFilePath.Substring(0, 2))
{
sRemoteName += sFilePath.Substring(2);
return (new Uri(sRemoteName)).ToString();
}
}
MessageBox.Show("4");
return sFilePath;
}
Regards,
Bandu