Sign in to follow this  
Followers 0
supersonic

Running WMI under different user

5 posts in this topic

#1 ·  Posted (edited)

Hi!

Is it possible to run a specific (WMI) part of a script with different user rights?

Here's my demo script:

Global $strComputer     = "."
Global $objWMIService   = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\default")

MsgBox(0, "", _lReset("2f32cb5e-9d45-4ce9-9c85-7bee3cbcd771"), 0)

Func _lReset($iStr = "")
    Local $objItem  = $objWMIService.Get("VirtualSoftwarePackage.Id=""" & $iStr & """")
    Local $RetVal   = 0
    If @error <> 0 Then
        $RetVal = 1
    Else
        $objItem.Reset()
        If @error <> 0 Then
            $RetVal = 2
        Else
            ConsoleWrite("$objItem.Reset() --- " & $iStr & " --- " & $objItem.Name & @CRLF)
        EndIf
    EndIf
    Return $RetVal
EndFunc

With the help of WMI commands I am trying to control Symantec's SWV (fak SVS).

This works pretty well so far (as an admin user),

but when executing $objItem.Reset() the script has to switch from normal user rights to admin user rights.

Is it possible to switch the user context for the WMI part?

Any ideas?

Greets,

-supersonic.

Edited by supersonic

Share this post


Link to post
Share on other sites



You will probably be okay with #RequireAdmin at the top of your script.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

You will probably be okay with #RequireAdmin at the top of your script.

I am afraid, no... >_<

Is it possible to initiate WMI services via DllCall()???

Share this post


Link to post
Share on other sites

http://www.autoitscript.com/forum/index.php?showtopic=81880&view=findpost&p=587207


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

In my experience with using it, the only way to get to WMI as another user was usually to run an entire other program as that user, and let it do the WMI related tasks. Remotely, yes you can run WMI queries as a different user, but locally, it won't work. At least, not with the same method, IIRC.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0