Jump to content

Recommended Posts

Posted

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
Posted

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!

Posted (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 by wendell42
Posted

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
Posted

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!

Posted

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.  

#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

Posted
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.

Posted
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.

Posted
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.  

#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
Posted
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!

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...