Access remotely by WMI

  • Thread starter Thread starter Dan Pavel
  • Start date Start date
D

Dan Pavel

Hi,

I am trying to list in a web page the processes an the services of a
computer in my workgroup. For my computer I use the windows user and it
works fine. For the remote computer I use admin user and password
entered by text boxes and saved as cookie. The bad part is that I get
"Access denied". The ASPNET user is in Administrators group on my
computer.

ConnectionOptions con = new ConnectionOptions();
if (Request.Cookies["wmiuser"].Value.ToString() != "")
{
con.Username = Request.Cookies["wuser"].Value.ToString();
con.Password = Request.Cookies["wpass"].Value.ToString();
}

ManagementScope ms = new ManagementScope("\\\\" + computer +
"\\root\\cimv2", con);

ObjectQuery oq = new ObjectQuery("SELECT * FROM Win32_Service");
ManagementObjectSearcher query = new ManagementObjectSearcher(ms,oq);
ManagementObjectCollection queryColl = query.Get(); //Crash

Please tell me what can be wrong.

Thank you
 
I would isolate your code as a class. Run the code in an application
and make sure that it works with the results that you expect. Then run
the code in your web application double checking all input values to
make sure these input values are what you expect them to be.

If that still fails then I would look into Impersonation.
 
The ASPNET account does not have any priviledges on the remote
machine. I'm not sure what you are doing with the cookie, but cookies
won't help gain authorizations on a remote machine, but you could use
the credentials with WindowsIdentity.Impersonate.
 
Hi,

for (e-mail address removed):
I already put the code in a win application and it worked fine. I can
access the remote computers and see the running processes and services.

for Scott Allen:
I am using the cookies so the user can enter the admin username and
password in the web app. When I use this username in the win app (see
above) it works ok. When I use it in the web app I get the Access denied
exception when I try to connect to the remote computer.

I would like to use WindowsIdentity.Impersonate but I am not sure I am
understanding it very good. If you have time, please explain me a
little.

Thank you
 
Back
Top