Jump to content
Sign in to follow this  
satanttin

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

Recommended Posts

satanttin

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

Share this post


Link to post
Share on other sites
OliverA

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

Share this post


Link to post
Share on other sites
satanttin

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

Share this post


Link to post
Share on other sites
satanttin

uhmms when i run it with #include "admin.au3" it just runs the windows where i need to login:( so doesn't work for me:O

too bad would be great

Share this post


Link to post
Share on other sites
FireFox

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.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
satanttin

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

Share this post


Link to post
Share on other sites
FireFox

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.

  • Like 1

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
satanttin

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:)

Share this post


Link to post
Share on other sites
FireFox

You're welcome ;)


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

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
Sign in to follow this  

×