Jump to content
ajr73333

Run some programs WITH elevated permissions and some WITHOUT.

Recommended Posts

ajr73333

Hey guys, 

I'm relatively new to AutoIT, however I am not new to programming.

My goal it to have a startup script that runs 5-10 different exe/bat files and some need to be ran WITH Admin rights and some need to be ran WITHOUT, in the same script. Is there any way to do this?

Thanks in advance!

Share this post


Link to post
Share on other sites
JLogan3o13

@ajr73333 welcome to the forum. You can use RunAs and RunAsWait to specify credentials for a specific program. The help file has examples.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Skeletor

#RequireAdmin is a good place to start, however, no matter where you place this into your script, it will always start your script prompting for Admin authentication.

Another one is IsAdmin ( )


Kind Regards
Skeletor

"I need coffee to turn me back to a human"

Microsoft Office Splash Screen | Basic Notepad Program (Beginner) | Wondering who uses AutoIt and what it can be used for ?

 

Share this post


Link to post
Share on other sites
ajr73333

Thank you guys so much for the quick responses!

And Jos, thank you for being a part of one of the most powerful scripting languages I've ever had the pleasure of learning.

I've actually done quite a bit of research. I understand the #RequireAdmin function and what it's purpose is, I've used it in a few different scripts, however that's my problem, is that it run EVERYTHING as Admin. The RunAs is what keeps coming up when I research the answer to my question, but I guess I don't understand fully if it will do what I need. A thought is, I need my script to run as Admin, so I can use #RequireAdmin, but my problem is, I have an application (Outlook) that behaves differently if it is ran as Admin. For example the Instant search function doesn't work, and users are unable to drag and drop attachments, they have to click the attachments button and find the files in that fashion which is cumbersome and honestly obnoxious. So....is there some sort of way to make the script run in an EVERYTHING EXCEPT fashion? For example, Run A, B, and C, as Admin, but specifically not D?

Share this post


Link to post
Share on other sites
JLogan3o13
6 hours ago, ajr73333 said:

The RunAs is what keeps coming up when I research the answer to my question, but I guess I don't understand fully if it will do what I need.

Can you please expand on this? You state you want to run some parts under one credential set, and some under another. That is exactly what RunAs is designed to do. Can you explain why you don't think it will do what you need so we can (try to) assist? To clarify, are you running these different items under different credentials, or the same credentials - just some with administrative access and some without?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Juvigy

RUNAS is what you need. The applications that you want to runas admin - you specify an ADMIN account to run with. The other apps can runas with non admin account.

Share this post


Link to post
Share on other sites
Skeletor
Posted (edited)

Okay, then @ajr73333 I think you over complicating things...

First off, go to all your programs that you want to run as Admin and right click, select Properties.

Next, click on Advanced.
Then the Advanced Properties panel will display.
Check the "Run as administrator" box.

Click OK.

Done.... 

Now in Autoit, just create a link to your executable. Simple!!!

Edited by Skeletor

Kind Regards
Skeletor

"I need coffee to turn me back to a human"

Microsoft Office Splash Screen | Basic Notepad Program (Beginner) | Wondering who uses AutoIt and what it can be used for ?

 

Share this post


Link to post
Share on other sites
JLogan3o13

@Skeletor I can't tell if you're being sarcastic of actually think that post is a good idea. Either way, it isn't of help to the OP


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Skeletor

@JLogan3o13 
I'm trying to help as well, and if you think about it, the OP will still need to get the paths of all the programs he needs AutoIt to execute.
That's my point I am making. Why reinvent the wheel?


Kind Regards
Skeletor

"I need coffee to turn me back to a human"

Microsoft Office Splash Screen | Basic Notepad Program (Beginner) | Wondering who uses AutoIt and what it can be used for ?

 

Share this post


Link to post
Share on other sites
JLogan3o13

You're suggesting he go and do something manually, rather than trying to find the way to automate it through AutoIt. Pretty much directly against what we try to accomplish here. 


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Skeletor

@JLogan3o13

Autoit cannot allow single programs to execute as Admin, #RequireAdmin is not a single function but a master function as also mentioned by @Jos. Therefore, to make it easier on the OP hense my suggestion.

Therefore, as i mentioned, my example below shows you will still need to obtain the path for the executables.

$Path = "C:\Program Files\Inkscape\inkview.exe"


Let me know if I am still wrong in your opinion, then I will correct my statement. 


Kind Regards
Skeletor

"I need coffee to turn me back to a human"

Microsoft Office Splash Screen | Basic Notepad Program (Beginner) | Wondering who uses AutoIt and what it can be used for ?

 

Share this post


Link to post
Share on other sites
ajr73333
8 hours ago, JLogan3o13 said:

To clarify, are you running these different items under different credentials, or the same credentials - just some with administrative access and some without?

They should all be running under the same user account that IS an admin user. Which is why I've found that RunAs might not be what I need unless I'm missing something. Program A, B, C, and D, are all being ran by the same user who is an admin and doesn't require creds to run, however, only A, B, and C require Admin rights to run properly, and program D needs to be specifically run as normal, not with the specified elevated privileges that come along with running it as an Admin. 

 

7 hours ago, Juvigy said:

RUNAS is what you need. The applications that you want to runas admin - you specify an ADMIN account to run with. The other apps can runas with non admin account.

There is only ever one account running these programs and it is an Admin account, that's my problem. I've considered creating a different normal user account for the other programs, however that will cause different issues with the programs that pull from the logged in user name. 

 

48 minutes ago, Skeletor said:

Okay, then @ajr73333 I think you over complicating things...

First off, go to all your programs that you want to run as Admin and right click, select Properties.

Next, click on Advanced.
Then the Advanced Properties panel will display.
Check the "Run as administrator" box.

Click OK.

Done.... 

Now in Autoit, just create a link to your executable. Simple!!!

That seems like it would work, unfortunately it's not an option, I already though about that and some of the programs I'm trying to run are on network shares and are run by other people who do NOT have admin rights, therefore if the exe(not exe's but I'll call it that for simplicity) is set to "Always run as Admin" then the other users won't be able to run them. It is a good suggestion though, but as JLogan3o13 said, even if that was an option, I would have to change that on every one of my startup programs which will eventually be over 30 and all in different locations. 

And I apologize for not getting back sooner, but that's where we're at, thanks again for all your suggestions guys! 

Share this post


Link to post
Share on other sites
Skeletor

@ajr73333, maybe not all hope is lost. 

I'm just typing out aloud here but maybe if you create two seperate AutoIT scripts that execute as one, you might have this task automated yet....


Kind Regards
Skeletor

"I need coffee to turn me back to a human"

Microsoft Office Splash Screen | Basic Notepad Program (Beginner) | Wondering who uses AutoIt and what it can be used for ?

 

Share this post


Link to post
Share on other sites
ajr73333
14 minutes ago, Skeletor said:

@ajr73333, maybe not all hope is lost. 

I'm just typing out aloud here but maybe if you create two seperate AutoIT scripts that execute as one, you might have this task automated yet....

Hmmmmmmmmmmmmmmmmm, can you run another AutoIT script with the Run function? I don't see it in the help files. Because if you can, that will definitely solve my problem......

Share this post


Link to post
Share on other sites
ajr73333

If not, I can always write another .bat to run the AutoIT script, but that might work.

Share this post


Link to post
Share on other sites
Skeletor

Okay so here's what you need to do...

 

1. Create three scripts.

- Master
- Admin
- LowLevel

NB: Naming is up to you.

2. Code for Master:
 

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 210, 220, 192, 124)
$Checkbox1 = GUICtrlCreateCheckbox("Run Admin Programs", 40, 112, 97, 17)
$Checkbox2 = GUICtrlCreateCheckbox("Run LowLevel Programs", 40, 142, 97, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Checkbox1
            $Read = GUICtrlRead($Checkbox1)
            Marker()
        Case $Checkbox2
            $Read = GUICtrlRead($Checkbox2)
            Marker2()
    EndSwitch
WEnd


Func Marker()
    If $Read = $GUI_CHECKED Then
        GUICtrlSetData($Checkbox1, "Running")
        Run("Admin.exe")
    Else
        GUICtrlSetData($Checkbox1, "Run Admin Programs")
    EndIf
EndFunc   ;==>Marker

Func Marker2()
    If $Read = $GUI_CHECKED Then
        GUICtrlSetData($Checkbox2, "Running")
        Run("LowLevel.exe")
    Else
        GUICtrlSetData($Checkbox2, "Run LowLevel Programs")
    EndIf
EndFunc   ;==>Marker2


3. Code for Admin
 

#RequireAdmin
$Path = "C:\Program Files\Inkscape\inkview.exe"

4. Code for LowLevel
 

$Path = "C:\Program Files\Inkscape\inkview.exe"


5. Compile the Admin and LowLevel scripts to an exe. 

6. Compile the Master to an exe (optional)

7. Run the Master program...

  • Thanks 1

Kind Regards
Skeletor

"I need coffee to turn me back to a human"

Microsoft Office Splash Screen | Basic Notepad Program (Beginner) | Wondering who uses AutoIt and what it can be used for ?

 

Share this post


Link to post
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

×