wendell42 Posted August 5, 2019 Posted August 5, 2019 I am VERY new to AutoIt, but have been unable to find an answer to my problem in the forums. I am trying to create, what I think is a very simple run as script to run a program as administrator with a non administrator account. Here is what I have... RunAs( "<adminuser>", "<domain>", ","<adminuserpass>", 2, "C:\Access\MSACCESS.EXE",) when I run the script I am getting an error saying "unknown function name" All I want it to do is open MSACCESS as administrator. Any assistance would be greatly appreciated.
Moderators JLogan3o13 Posted August 5, 2019 Moderators Posted August 5, 2019 Can you please screenshot or paste the exact verbiage you're seeing for the error? Also, are you using the full SciTE install? https://www.autoitscript.com/site/autoit-script-editor/downloads/ "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Danp2 Posted August 5, 2019 Posted August 5, 2019 Looks like you've got some issues with the command between the domain and password (extra ",) and also an extra comma at the end. Latest Webdriver UDF Release Webdriver Wiki FAQs
wendell42 Posted August 5, 2019 Author Posted August 5, 2019 (edited) Sorry, the extra quotation was a typo on my part. Here is the text from the error... Line 1 (File "C:\Users\wwendell\Desktop\Test.au3"): RunAs("<adminuser.","<domain>", "<adminuserpw>", 2, "C:\Access\MSACCESS.EXE") ^ERROR Error: Unknown function name. And I did the full install of autoit-V3-setup.exe Edited August 5, 2019 by wendell42
Developers Jos Posted August 6, 2019 Developers Posted August 6, 2019 (edited) Please post the actual file (of course with dummy account information) that generates this error so I can check it. Jos Edited August 6, 2019 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Earthshine Posted August 6, 2019 Posted August 6, 2019 it doesn't give any errors here. My resources are limited. You must ask the right questions
Developers Jos Posted August 6, 2019 Developers Posted August 6, 2019 That file indeed doesn't give any error, so how are you running it and do you get any error when you run this attached file? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
wendell42 Posted August 6, 2019 Author Posted August 6, 2019 OK, I got it to work... somewhat... I suppose. it will open MSACCESS, but it appears that it isn't full admin rights. I am trying to make it to open a database running MSACCESS as administrator, as there are macros and functions within the database that require admin rights. (third party software that the vendor has gone out of business). If I right click on MSACCESS.exe and run as administrator, enter the administrator credentials in it, the database opens fine and functions as it should. However, if I run the .au3 file, it APPEARS to open MSACCESS.exe in administrator mode (access to user administrator desktop) but will not open the database file in admin mode. Is there a switch I am missing that will make it open the database as administrator? is there a way to put the database in the RunAs string? I did try to open the database file (instead of MSACCESS) but it didn't work.
Moderators JLogan3o13 Posted August 6, 2019 Moderators Posted August 6, 2019 When you open MSAccess using runAs, look in the Task Manager for the msaccess process. Is it running under your credentials or the administrative credentials? "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
AdamUL Posted August 7, 2019 Posted August 7, 2019 RunAs and RunAsWait does not request the admin token, and does not run with full admin rights, even if the RunAs user is an admin. There are workarounds to get past this limitation. A workaround example is below. expandcollapse popup#include <MsgBoxConstants.au3> Global $sAdminUser = "USERNAME" Global $sAdminPassword = "PASSWORD" Global $sDomain = "AD" Global $iLogOnFlag = 0 Global $sParameters = "" ;Elevate with the Admin account. If @UserName <> $sAdminUser And Not IsAdmin() Then $sParameters = "" If Not @Compiled Then $sParameters = ' "' & @ScriptFullPath & '"' EndIf If RunAs($sAdminUser, $sDomain, $sAdminPassword, $iLogOnFlag, @AutoItExe & $sParameters) Then Exit Else Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR!", "Unable to run under administrator account.") EndIf EndIf ;Request the Admin Token for the Admin account in Windows Vista and Higher. If @UserName = $sAdminUser And Not IsAdmin() And Not StringRegExp(@OSVersion, "_(XP|200(0|3))") Then $sParameters = "" If Not @Compiled Then $sParameters = '"' & @ScriptFullPath & '"' EndIf If ShellExecute(@AutoItExe, $sParameters, "", "runas") Then Exit Else Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR!", "Unable to elevate to Admin due to UAC.") EndIf EndIf ;Put rest of the script here. MsgBox(16, $sAdminUser, IsAdmin()) ;Example Run("C:\Access\MSACCESS.EXE") Adam
abberration Posted August 7, 2019 Posted August 7, 2019 I wrote scripts like this in the past. For me, the problem was using the wrong logon flag. Try playing with that value. Easy MP3 | Software Installer | Password Manager
wendell42 Posted August 12, 2019 Author Posted August 12, 2019 On 8/6/2019 at 5:14 PM, JLogan3o13 said: When you open MSAccess using runAs, look in the Task Manager for the msaccess process. Is it running under your credentials or the administrative credentials? Windows 10 is showing Microsoft Access in the Apps list, but does not list who's credentials it is running under.
wendell42 Posted August 12, 2019 Author Posted August 12, 2019 On 8/7/2019 at 11:40 AM, abberration said: I wrote scripts like this in the past. For me, the problem was using the wrong logon flag. Try playing with that value. I have changed the logon flag several times and finally got it to open the MSACCESS program, it just will not open the database with the admin rights in place.
wendell42 Posted August 12, 2019 Author Posted August 12, 2019 On 8/7/2019 at 11:07 AM, AdamUL said: RunAs and RunAsWait does not request the admin token, and does not run with full admin rights, even if the RunAs user is an admin. There are workarounds to get past this limitation. A workaround example is below. expandcollapse popup#include <MsgBoxConstants.au3> Global $sAdminUser = "USERNAME" Global $sAdminPassword = "PASSWORD" Global $sDomain = "AD" Global $iLogOnFlag = 0 Global $sParameters = "" ;Elevate with the Admin account. If @UserName <> $sAdminUser And Not IsAdmin() Then $sParameters = "" If Not @Compiled Then $sParameters = ' "' & @ScriptFullPath & '"' EndIf If RunAs($sAdminUser, $sDomain, $sAdminPassword, $iLogOnFlag, @AutoItExe & $sParameters) Then Exit Else Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR!", "Unable to run under administrator account.") EndIf EndIf ;Request the Admin Token for the Admin account in Windows Vista and Higher. If @UserName = $sAdminUser And Not IsAdmin() And Not StringRegExp(@OSVersion, "_(XP|200(0|3))") Then $sParameters = "" If Not @Compiled Then $sParameters = '"' & @ScriptFullPath & '"' EndIf If ShellExecute(@AutoItExe, $sParameters, "", "runas") Then Exit Else Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR!", "Unable to elevate to Admin due to UAC.") EndIf EndIf ;Put rest of the script here. MsgBox(16, $sAdminUser, IsAdmin()) ;Example Run("C:\Access\MSACCESS.EXE") Adam I am going to give this a shot Adam. Thanks!
Moderators JLogan3o13 Posted August 12, 2019 Moderators Posted August 12, 2019 3 minutes ago, wendell42 said: Windows 10 is showing Microsoft Access in the Apps list, but does not list who's credentials it is running under. That is because you're looking in the wrong spot. In Win10 you have to look on the Details tab, not Processes. Or, if you're looking under the App List, right click and choose "Go to details" "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
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