2

I am using the following code to find a list of Devices attached to COM Port.

ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM MSSerial_PortName"); 

With Windows XP, the code works fine, but with Windows-7, I get an Access Denied Exception. I am running under full administrative privilege in both the cases, then why would I face this error with Windows 7 and not XP.

10
  • Are you using this code in a web project? Commented Apr 18, 2011 at 9:05
  • 1
    Are you really running under full administrative privilege (after accepting the UAC prompt), or just with an administrator user account? Commented Apr 18, 2011 at 9:11
  • @Adrian:positively Full administrative. Commented Apr 18, 2011 at 9:18
  • @Gunner in that case putting a manifest on it won't help. I never completely solved my version of this problem: stackoverflow.com/questions/2279646/… Commented Apr 18, 2011 at 9:25
  • 1
    @Gunner: Hmm, In win7 when you are running app under Administrator account its not have full administrative rights by default, to obtain full rights you should right click on exe and choose 'Run as Administaror' after that you should click yes in prompt dialog. The warning about changes in the system is not a garantee that you have all sufficient rights Commented Apr 18, 2011 at 11:18

2 Answers 2

1

You need to elevate privileges of your app: See this Q&A

Sign up to request clarification or add additional context in comments.

1 Comment

Even without elevating the privileges, the issue can be resolved by running the App as an administrator.
1

I just ran your code under admin in my win7 rig and it worked properly while it failed within user context. Your process is running under UAC even though you yourself is logged in as admin. You need to secure elevated privileges for the application.

2 Comments

Thanks for the post. Could you please provide some resource on how I can elevate the privileges for the application. Thanks.
There are several ways, one is to include a manifest file requesting elevated privileges for an exe. See here: blogs.msdn.com/b/heaths/archive/2006/09/26/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.