Jump to content

[SOLVED]How to do require admin from a button?


Recommended Posts

Alloha,

I was wondering if it's possible to get admin login screen (#requireadmin) when i press a button?

cause i am busy with a simple tray program and when i am at work i need admin rights from time to time and not when i am at home so was wondering if this was possible and so how to do it?

if u need any code just ask:)

Thanks in advance ^^

Edited by satanttin
Link to comment
Share on other sites

No, but you can make a second script/exe with #requireadmin and when you click on the button call it the "version" with admin rights

Like

Main CODE:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include "admin.au3" ; <<<<<<<<<<<<<<<< Second script

$Form = GUICreate("Form1", 221, 149, 208, 129)
$Button = GUICtrlCreateButton("Admin", 8, 24, 73, 33)
GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $Button
   _Admin()
EndSwitch
WEnd

Second script ( admin.au3 )

#include-once
#RequireAdmin ; <<<<<<<<<<<< this have admin

Func _Admin()
MsgBox(0,0,"Put Func Here")
EndFunc
Edited by OliverA

I'M QUIT FROM THIS FORUM!

It was fun until it lasted, hope on my future way i can't find people that offend without any reason ( i was called lazy and parasitic, and everyone agreed...United we stand, divided we fall ) just for fun because don't have anything to do in the life, without knowing anything about the person who write, noone forced to post, noone forced to help.

From the top of the from their very great superiority they not go down to my level, that people can not spread the knowledge but you have to learn by yourself.

In what way? It's easy...just search on google

For that people, wish you the best way,

Oliver Astone

Link to comment
Share on other sites

No, but you can make a second script/exe with #requireadmin and when you click on the button call it the "version" with admin rights

Like

Main CODE:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include "admin.au3" ; <<<<<<<<<<<<<<<< Second script

$Form = GUICreate("Form1", 221, 149, 208, 129)
$Button = GUICtrlCreateButton("Admin", 8, 24, 73, 33)
GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button
_Admin()
EndSwitch
WEnd

Second script ( admin.au3 )

#include-once
#RequireAdmin ; <<<<<<<<<<<< this have admin

Func _Admin()
MsgBox(0,0,"Put Func Here")
EndFunc

sounds like a good plan^^

going to test this now:D

Link to comment
Share on other sites

No, but you can make a second script/exe with #requireadmin and when you click on the button call it the "version" with admin rights

This could work, but what you provided is wrong. As soon as you include the admin script, the #RequireAdmin function will be called regardless if you use the functions or not in the include.

Br, FireFox.

Link to comment
Share on other sites

This could work, but what you provided is wrong. As soon as you include the admin script, the #RequireAdmin function will be called regardless if you use the functions or not in the include.

Br, FireFox.

how can i make it so it would work? if i may ask:P
Link to comment
Share on other sites

Sure, here you go :

#include <GuiButton.au3>
#include <GuiConstantsEx.au3>

#region GUI
Local Const $hGUI = GUICreate("MyGUI")

Local Const $iBtnElevate = GUICtrlCreateButton("Elevate", 10, 10, 70, 25)
_GUICtrlButton_SetShield($iBtnElevate)

If IsAdmin() Then GUICtrlSetState($iBtnElevate, $GUI_DISABLE)
GUISetState(@SW_SHOW, $hGUI)
#endregion

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $iBtnElevate
            ; restart elevated
            If @Compiled Then
                ShellExecute(@ScriptFullPath, "", @WorkingDir, "runas")
            Else
                ShellExecute(@AutoItExe, '/AutoIt3ExecuteScript "' & @ScriptFullPath & '"', @WorkingDir, "runas")
            EndIf
            Exit
    EndSwitch
WEnd

This is a simplified script from this UDF :

Br, FireFox.

Link to comment
Share on other sites

Sure, here you go :

#include <GuiButton.au3>
#include <GuiConstantsEx.au3>

#region GUI
Local Const $hGUI = GUICreate("MyGUI")

Local Const $iBtnElevate = GUICtrlCreateButton("Elevate", 10, 10, 70, 25)
_GUICtrlButton_SetShield($iBtnElevate)

If IsAdmin() Then GUICtrlSetState($iBtnElevate, $GUI_DISABLE)
GUISetState(@SW_SHOW, $hGUI)
#endregion

While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
Case $iBtnElevate
; restart elevated
If @Compiled Then
ShellExecute(@ScriptFullPath, "", @WorkingDir, "runas")
Else
ShellExecute(@AutoItExe, '/AutoIt3ExecuteScript "' & @ScriptFullPath & '"', @WorkingDir, "runas")
EndIf
Exit
EndSwitch
WEnd

This is a simplified script from this UDF :

Br, FireFox.

uhmms thanks dunno how to put it in my script but that's up to me to test:P

but thanks again for the script:)

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