PramodR Posted May 26, 2018 Posted May 26, 2018 (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 Edited May 27, 2018 by PramodR removing word geek
Subz Posted May 27, 2018 Posted May 27, 2018 Have you tried adding #RequireAdmin to the top of your script?
orbs Posted May 27, 2018 Posted May 27, 2018 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: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates WinPose - simultaneous fluent move and resize Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Magic Math - a math puzzle Demos: Title Bar Menu - click the window title to pop-up a menu
PramodR Posted May 27, 2018 Author Posted May 27, 2018 @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.
Subz Posted May 27, 2018 Posted May 27, 2018 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. PramodR 1
iamtheky Posted May 27, 2018 Posted May 27, 2018 are you sure the dell omci class is the only place you can get this information from? ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
TheXman Posted May 27, 2018 Posted May 27, 2018 (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 May 27, 2018 by TheXman PramodR 1 CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
iamtheky Posted May 27, 2018 Posted May 27, 2018 Can you query sysdriver without tripping UAC? wmic sysdriver get /format:list | find "mic" ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
PramodR Posted May 27, 2018 Author Posted May 27, 2018 (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 May 27, 2018 by PramodR
iamtheky Posted May 27, 2018 Posted May 27, 2018 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. ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
PramodR Posted May 27, 2018 Author Posted May 27, 2018 @iamtheky no i could not find the object which i was looking , yes i am creating script so the same can be re run over different systems for test,
PramodR Posted May 27, 2018 Author Posted May 27, 2018 @TheXman I will definitely look for the possibilities to disable UAC in my environment. but i dont think that is the long time solution.
iamtheky Posted May 27, 2018 Posted May 27, 2018 hmmmm... what about driverquery /v or sc query type=all im installing that class now as my curiosity is piqued ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
TheXman Posted May 27, 2018 Posted May 27, 2018 2 minutes ago, 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 To be clear, I did not suggest disabling UAC. I suggested, for local admins only, configuring UAC to automatically elevate without prompting. CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
PramodR Posted May 27, 2018 Author Posted May 27, 2018 @iamtheky install Dell Command Monitor only for your dell corporate client systems, This will let you set or get BIOS configuration. @TheXman Sure....
iamtheky Posted May 27, 2018 Posted May 27, 2018 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 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
TheXman Posted May 27, 2018 Posted May 27, 2018 @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. CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
PramodR Posted May 27, 2018 Author Posted May 27, 2018 (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 May 27, 2018 by PramodR
TheXman Posted May 27, 2018 Posted May 27, 2018 (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. expandcollapse popup#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 May 27, 2018 by TheXman PramodR 1 CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
TheXman Posted May 27, 2018 Posted May 27, 2018 (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 May 27, 2018 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now