WMI query call from custom installer not working

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
 
W

Wilson, Phil

I suspect the issue is that mapped drives don't belong to the computer -
they belong to each user. If you are running your code during the install as
a custom action in a VS 2008 setup project then you're running with the
SYSTEM account, and it doesn't have those mapped drives that belog to some
other user. The other issue is the the SYSTEM account doesn't have network
privileges, so it's unlikely that you can access whatever is at that share
anyway. What are you trying to do?
 
B

Bandu

I suspect the issue is that mapped drives don't belong to the computer -
they belong to each user. If you are running your code during the installas
a custom action in a VS 2008 setup project then you're running with the
SYSTEM account, and it doesn't have those mapped drives that belog to some
other user. The other issue is the the SYSTEM account doesn't have network
privileges, so it's unlikely that you can access whatever is at that share
anyway. What are you trying to do?

--
Phil Wilson
The Definitive Guide to Windows Installerhttp://www.apress.com/book/view/1590592972




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;
       }

Bandu- Hide quoted text -

- Show quoted text -

Hi Phil,

I'm trying to install our application together with driver install
package.
Application -> inside Msi
Driver package -> Driver files (with folder)

After installation, i need to copy those driver file to my installed
folder. I can't put those driver files into MSI because Driver files
may get Microsoft signing later or User may need to installed driver
from the Cd directly. And also don't want to keep 2 different copy
(inside msi and outside msi).
So, I put a custom installer to copy the file to installed folder.

when I start doing this, I try to use, loose package for those driver
file in setup package. But Visual Studio put all those file into a
flat folder. So, it didn't fit the scanario.

Thank you very much for your advise.
Is there anyway that I can make setup to run in logged in user
context?

I think you are right about that setup didn't have NETWORK priviledge.
I try to excute "cmd /k xcopy " from custom installer for mapped
drive, it gave me "invalid" drive.

I'm really stuck. Can someone help?

thanks...

Bandu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top