Elevating privileges for WMI calls in a sidebar

I'm trying to create a gadget that uses some WMI calls to retrieve "cooked" perf data from the WMI counters. Although the code used to work in RC1 w/o any problem, in RTM the same counter classes seem to need Admin privileges.

Is there a way that a gadget can have admin privs for running



Answer this question

Elevating privileges for WMI calls in a sidebar

  • m_nille

    Here is some code that requires elevated priviliges to run. I basically need to run this code witihn a gadget and can't do so unless it's elevated.

    Set objCimv2 = GetObject("winmgmts:root\cimv2")
    Set objRefresher = CreateObject("WbemScripting.SwbemRefresher")

    Set objNW = objRefresher.AddEnum(objCimv2, "Win32_PerfFormattedData_Tcpip_NetworkInterface").ObjectSet

    ' Initial refresh needed to get baseline values
    objRefresher.Refresh


    For each nw in objNW
    Wscript.Echo nw.Name
    Next

    Wscript.Sleep 10000
    objRefresher.Refresh


  • Nightmare_BE

    Thanks. That link explains it perfectly. The strange part is that the counter that I'm trying to read used to work without requiring elevation in RC1. It's changed in RTM. :(
  • MMCompton

    Post some example code, as I would have thought this would work - so long as the running user has enough rights to open an elevated WMI connection.

  • Sarwanan

    I now see what you mean. The only way you'll get access to NIC information is if you're in the Administrators group - as you said. There's no way around that, and you can't elevate Sidebar or a Gadget within it.

    You might want to read User Account Control and WMI which goes into detail about what you can/can't do with WMI when UAC is concerned.

    There must be another way to get the info you require though, as ipconfig and Task Manager both do it without being elevated. Depending on what you're after, you can probably get it though wsock32.dll or icmp.dll


  • Rups11

    Jonathan Abbott wrote:
    There must be another way to get the info you require though, as ipconfig and Task Manager both do it without being elevated. Depending on what you're after, you can probably get it though wsock32.dll or icmp.dll

    Basically I'm trying to get the number of bytes sent and recieved on a particular network connection on an ongoing basis. Is there another way I can do that


  • Elevating privileges for WMI calls in a sidebar