Jump to content

Recommended Posts

Posted (edited)

Hello,

I have to execute below block of code in elevated previllage, as that particular wmic class will work only with admin previlage.

i am getting out put when i launch autoit as administrator,  but i will not be able to launch autoit as admin in this particular case but my user have admin rights.

is there any better way i can run those command as administrator.?

tried below steps:

  • i have tried #RequireAdmin but that creates a user prompt 
  • Tried using Runas command but gives error as wrong username or password , stuck with that step.

 

  Quote

 

#include <MsgBoxConstants.au3>
#include <Constants.au3>
#include <MsgBoxConstants.au3>

$WmiCommand = ( _GetDOSOutput("wmic /namespace:\\root\dcim\sysman path dcim_biosenumeration where(attributename like '%%Microphone%%') get currentvalue") & @CRLF)
ConsoleWrite($WmiCommand)

Func _GetDOSOutput($sCommand)
    Local $iPID, $sOutput = ""
    $iPID = Run('"' & @ComSpec & '" /c ' & $sCommand, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    While 1
        $sOutput &= StdoutRead($iPID, False, False)
        If @error Then
            ExitLoop
        EndIf
        Sleep(10)
    WEnd
    Return $sOutput
 EndFunc   ;==>_GetDOSOutput

 

 

 

Expand  

 

Edited by PramodR
removing word geek
Posted

you are using WMI to query the system, not to operate on it, therefore you actually do not need admin rights. although WMI as a method may require admin rights in effect (regardless of the specific function), only querying in general does not. so consider other methods to retrieve the piece of information you need.

Signature - my forum contributions:

  Reveal hidden contents

 

Posted

@Subs I have tried adding #RequireAdmin to the top of script but its keep giving me UAC pop up which i dont want to select manually.

@orbs Usually WMI get operation does not required any admin previllage but this particular class require admin previllage hence i need to launch auto it in administrator mode, this is a unique name space this functionality not available in other classes.

Posted

Sorry just reread your post and see you had already tried #RequireAdmin, if you are going to launch Cmd as elevated you will always see the UAC prompt, for example, I'm an administrator on my machine, however if I run cmd.exe it will always start in user mode, I still require Run As Administrator which then show UAC.  The only way around this would be switch UAC off.

Posted

are you sure the dell omci class is the only place you can get this information from?

  Reveal hidden contents

Posted (edited)

@PramodR

Depending on how much administrative control you have over your users' environment, you can suppress the UAC prompt for users that are local admins of their workstation by either using group policy or by modifying the registry.  The following link should give you all of the information that you need to make the modifications.  In your case, if the users are truly local admins, you want to direct your attention to the "ConsentPromptBehaviorAdmin" registry key or "User Account Control: Behavior of the elevation prompt for administrators in Admin Approval Mode" group policy.  If this is configured correctly, then local admins will not be prompted when you add the #RequireAdmin directive to your scripts.

User Account Control Group Policy and registry key settings

 

A very helpful UDF lib for getting and setting UAC-related registry settings is UAC.au3 submitted by @AdamUL

 

Edited by TheXman
Posted

Can you query sysdriver without tripping UAC?

wmic sysdriver get /format:list | find "mic"

 

  Reveal hidden contents

Posted (edited)

@iamtheky  i get below out put for Mic.

 Caption=Dynamic Volume Manager
Description=Dynamic Volume Manager
DisplayName=Dynamic Volume Manager

Actually i there is other than microphone many other configuration which i will be able to access only from omci. 

 

Edited by PramodR
Posted

so if you take off the find command, and scroll through the list, do you see the object you are after?

And are you running this as you would want to run it in the future...just so we are sure we are chasing plausible solutions.

  Reveal hidden contents

Posted

hmmmm...

what about 

driverquery /v

or

sc query type=all

im installing that class now as my curiosity is piqued

 

  Reveal hidden contents

Posted
  On 5/27/2018 at 4:57 PM, PramodR said:

I will definitely look for the possibilities to disable UAC in my environment. but i dont think that is the long time solution

Expand  

To be clear, I did not suggest disabling UAC.  I suggested, for local admins only, configuring UAC to automatically elevate without prompting.

Posted

i didnt even look at the enumeration command, i just say wmi and microphone and played videogames, eh ask questions on a holiday weekend you get spotty service :)

  Reveal hidden contents

Posted

@PramodR

Is your primary issue being able to run privileged commands, for local admins,  without being prompted by UAC or is your primary issue being able to query for specific information on users' workstations?  Because you've been given a workable solution to the former, it appears that your issue is the latter.  If so, can you explicitly state what piece or pieces of information you are trying to retrieve?  Is it just a list of the microphones, as your original post would suggest, or are you after more information.  If so, what specifically?  Is it imperative that you use the DCIM WMI provider or is it okay to get the information some other way that may or may not require elevated privileges?  Your answers to these questions would go along way towards others trying to help you accomplish your goal.

Posted (edited)

 

@TheXman

Yes my primary issue is how to run privileged commands for local admins.

i am pretty sure these information is not available in other resource currently. im not only trying to retrieve microphone , microphone is just example there are many configurations. 

Its okay to get information from other source but currently not available as part of my research. 

 

Edited by PramodR
Posted (edited)

You can try the snippet below.  It is a different method of elevation that works if your users are local admins.  Because you haven't implement the suppressing of UAC prompts for local admins, it may trigger the prompt just as if you had added #RequireAdmin.  Try it out and see if it works for you. 

Basically, it checks to see if you are running the script with elevated privileges.  If not, it will re-launch itself using the ShellExecute function with the "runas" verb in order to request elevation. 

By the way, I didn't check it for errors so you may have to tweak it a tad.  :)

 

#include <Constants.au3>
#include <WinAPI.au3>

elevate_to_run_with_admin_token()
$WmiCommand = ( _GetDOSOutput("wmic /namespace:\\root\dcim\sysman path dcim_biosenumeration where(attributename like '%%Microphone%%') get currentvalue") & @CRLF)


;==========================================================================
; This assumes that the user is a local admin.
; Do NOT use #RequireAdmin if using this method of elevation
;==========================================================================
Func elevate_to_run_with_admin_token()

    Local $sErrorMsg = ""
    Local $iPid      = 0


    ;Run with "runas" verb in order request full Admin token (in Windows Vista and Higher - UAC-enabled OSes).
    If (Not IsAdmin()) And (Not StringRegExp(@OSVersion, "_(?:XP|2000|2003))")) Then
        $iPid = ShellExecute(@AutoItExe, $CmdLineRaw, @ScriptDir, "runas")
        If $iPid Then
            Exit
        Else
            $sErrorMsg = "ERROR: Unable to elevate to Admin due to UAC. " & _WinAPI_GetLastErrorMessage()
            MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", $sErrorMsg)
            Exit -1
        EndIf
    EndIf

    MsgBox( _
        $MB_ICONINFORMATION + $MB_TOPMOST, _
        "INFO", _
        StringFormat("Elevated status = %s", (IsAdmin())?("TRUE"):("FALSE")) _
    )

    Return

EndFunc

Func _GetDOSOutput($sCommand)
    Local $iPID, $sOutput = ""
    $iPID = Run('"' & @ComSpec & '" /c ' & $sCommand, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    While 1
        $sOutput &= StdoutRead($iPID, False, False)
        If @error Then
            ExitLoop
        EndIf
        Sleep(10)
    WEnd
    Return $sOutput
EndFunc   ;==>_GetDOSOutput

 

Edited by TheXman
Posted (edited)

I just noticed you are launching your command using RUN.  I would either change it to use ShellExecuteWait or use COM. 

** Updated **

Ignore the statement above out changing to ShellExecuteWait or COM.  Just use whatever you are most comfortable with. :)

Edited by TheXman

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
×
×
  • Create New...