Jump to content

Using AutoIT to call a BAT file as an admin - (Moved)


Recommended Posts

Ok my brain is fried now.  I'm headed home for the day. I will pick this up tomorrow

Nine: thank you so much for all of your help.  You have gotten me much further than I was and I appreciate it.  

Dana: Thank you as well for pointing out my issue in the code and helping me get the error portion straight.

Link to comment
Share on other sites

NINE!!!

If you were a girl I would kiss you!!!

 

You are correct I did not copy, I just added to mine and did it wrong

I have now successfully run it on a non admin machine!!!

 

I owe you big!!!

Nine you are the "Person"!!!!!

 

Thanks so much!!!!

Link to comment
Share on other sites

Ok, so I was informed late last night that many of these laptops/tablets have been out there for years and may have not received the Local Admin password update from GPO implemented about a year and a half ago.  Is there any way to have the script try multiple usernames and passwords?  Like have a box that pops up and says

"Username or Password incorrect, there are 3 other entries we can attempt, Press ok to try again", and it goes to the next credential we have listed?  I'm thinking this is really way outside what can be done, but you guys are super smart so I figured I would ask. 

 

Thanks so much for all of your help!!!

Link to comment
Share on other sites

Sooooo, I popped another PC online that wasn't in use and signed in a regular user.  I am unable to run the script as I receive the Windows Security box asking for the username and password.  Here is the script that worked on a laptop that is also on the domain and was logged in as a standard user. It's the same script, I had to change the path as I didn't want it to be 5 folders deep.  

 

#RequireAdmin
#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIError.au3>

    ; Change the username and password to the appropriate values for your system.
    Local $sUserName = "administrator"
    Local $sPassword = "**********"
    Local $sDirectory = "C:\users\" & @Username & "\Downloads\directsetup\directsetup"
    Local $sFiletoRun = "setup.bat"

    $iReturn = RunAsWait ($sUserName, @ComputerName, $sPassword, 0, $sDirectory & $sFiletoRun)
    If @error Then
        Local $sLastError = _WinAPI_GetLastErrorMessage()
        MsgBox($MB_SYSTEMMODAL + $MB_ICONERROR, "Error", "Batch file has not Run :" & @CRLF & @CRLF & $sLastError)
    Else
        MsgBox($MB_SYSTEMMODAL, "", "The return code from runaswait was: " & $iReturn)
    EndIf

So I moved the Zip file to a share then to the downloads folder and extracted.  This created the "\directsetup\directsetup\" path I am now using. 

When I double click on the .EXE I created in AutoIT it now pops up a security window asking for the username and password.  It did not do this yesterday after I changed the code for the path as suggested by Nine.  It opened the batch file, I selected 2 and it started the agent install properly. It went though the entire setup and finished successfully. 

Logged in as a terminal server test user I created some time ago I now receive the prompt in the attachment

Logged in as the same user it worked for on the laptop yesterday and I receive the same prompt now.

So I am confused as to how it worked yesterday but not today.  Both the laptop and the desktop are on the domain, connected hard wired, and are receiving the same GPO's, both the users are standard domain users and neither have an "special" GPO's applied or belong to any groups outside of Domain User that would cause an issue. 

Obviously, the RUNASWAIT is not working properly as it is not putting the info in as needed. 

Am i just running on a pipe dream that this can work and bypass the security prompt? 

 

Please let me know your thoughts as I was so super excited yesterday seeing it work and now I feel quite deflated today.

 

Thanks for all of your help!!

Capture.PNG

Link to comment
Share on other sites

So for giggles I decided to try and disable UAC from a reg key using the same theory as the rest of it.  Providing the UN/PW and calling the REG file.  I receive the same prompt, so the issue is that it's not passing the UN/PW through to the prompt as intended. But from what I am reading, it's not possible to do this.  You can't bypass the UAC in any way shape or form. :( Really annoyed right now. 

Link to comment
Share on other sites

UAC is there to prevent people taking over a computer without the user's knowledge. It can be a pain for programmers but it's there for a reason.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

20 minutes ago, BrewManNH said:

UAC is there to prevent people taking over a computer without the user's knowledge. It can be a pain for programmers but it's there for a reason.

I agree and I know it needs to be there.  It is just getting very frustrating as now I don't believe there will be a way for me to get my job done without having 140 people come back to the home office. 

Link to comment
Share on other sites

"Username or Password incorrect, there are 3 other entries we can attempt, 

You could make a loop over runaswait until it doesnt get an @error.  List the username and password into an array instead of a single variable.

Link to comment
Share on other sites

1 minute ago, Nine said:

"Username or Password incorrect, there are 3 other entries we can attempt, 

You could make a loop over runaswait until it doesnt get an @error.  List the username and password into an array instead of a single variable.

Yea I don't think that is going to matter at this point as UAC is the issue..... ugh , but again, thank you so much for the help.  If I can't get past UAC this was all for naught...

Link to comment
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
 Share

  • Recently Browsing   0 members

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