satanttin Posted April 4, 2013 Posted April 4, 2013 (edited) 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 April 4, 2013 by satanttin
OliverA Posted April 4, 2013 Posted April 4, 2013 (edited) 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 April 4, 2013 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
satanttin Posted April 4, 2013 Author Posted April 4, 2013 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
satanttin Posted April 4, 2013 Author Posted April 4, 2013 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
FireFox Posted April 4, 2013 Posted April 4, 2013 No, but you can make a second script/exe with #requireadmin and when you click on the button call it the "version" with admin rightsThis 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.
satanttin Posted April 4, 2013 Author Posted April 4, 2013 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
FireFox Posted April 4, 2013 Posted April 4, 2013 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. satanttin 1
satanttin Posted April 4, 2013 Author Posted April 4, 2013 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:)
satanttin Posted April 4, 2013 Author Posted April 4, 2013 @FireFox you solved it^^ thanks to your coding:) code was that i used: Func Admin() If @Compiled Then ShellExecute (@scriptfullpath, "", @WorkingDir, "RunAs") Else ShellExecute(@AutoItExe, '/AutoIt3ExecuteScript "' & @ScriptFullPath & '"', @WorkingDir, "runas") EndIf Exit EndFunc
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now