Access remotely by WMI

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
 
R

recoil

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.
 
S

Scott Allen

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.
 
D

Dan Pavel

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
 

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

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top