Jump to content
Sign in to follow this  
step887

runas win admin win7

Recommended Posts

step887

is there a way to do runas and have it execute with admin privileges with having use #requireadmin in the program executed by runas..

If I run this, it returns test 0

here is simple example

test.exe:

msgbox(0,@username,isadmin())

[/size]
[size=4]#RequireAdmin
; Fill in the username and password appropriate for your system.
Local $sUserName = "test"
Local $sPassword = "test"[/size]
[size=4]Local $pid = RunAsWait($sUserName, @ComputerName, $sPassword, 0, 'test.exe', @SystemDir)[/size]
[size=4]

So I am running, the script with admin permissions, I do run as and it shows it is not admin.

If I put #requireadmin in test.exe, it will prompt me again, but i only want the one prompt

Share this post


Link to post
Share on other sites
JohnOne

In windows 7 at least and I suspect vista, when a program is ran requiring specifically that admin privileges are required. UAC will prompt user to allow it.

If you do not want this behaviour then turn UAC off (not recommended) else let the user decide whether or not to allow it.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
jazzyjeff

Here is what I do. I create script 1 that runs script 2 as an admin account on my domain. Script 2 has the #RequireAdmin at the top of the script and uses the Run function to execute the program you need to run as admin.

The other part of this is that you will need to have all of your machines registry to this:

HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionPoliciesSystem EnableInstallerDetection=0

HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionPoliciesSystem ConsentPromptBehaviorAdmin=0

This will suppress UAC prompts when programs are executed by an administrator. UAC still works for standard users though.

Script 1 would look some like this:

#include <Crypt.au3>
Global $sPW
_DecryptPW1()
RunAs("admin","Domain",$sPW,0,"C:\Script2.exe")

Func _Decrypt($sKey, $sData)
Local $hKey = _Crypt_DeriveKey($sKey, $CALG_AES_256)
Local $sDecrypted = BinaryToString(_Crypt_DecryptData(Binary($sData), $hKey, $CALG_USERKEY))
_Crypt_DestroyKey($hKey)
Return $sDecrypted
EndFunc ;==>_Decrypt
Func _DecryptPW1()
_Crypt_Startup()
Global $sPasswordCT = '0x000000000001111111110000000000'
Global $sPW = ''
$sPW = _Decrypt("password", $sPasswordCT)
_Crypt_Shutdown()
EndFunc ;==>_DecryptPW1

Script 2 would look like this:

#RequireAdmin
Run("C:\MyProgram.exe")

To create the encrypted password, I use this:

#include <Crypt.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
_Crypt_Startup()
$password = InputBox("Password", "Please enter the password you would like to encrypt to a key", "", "*")
$encrypted = _Encrypt("password", $password) ; DO NOT FORGET TO REMOVE THIS LINE
_Crypt_Shutdown()
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Encrypted Password", 507, 61, 192, 124)
$Input1 = GUICtrlCreateInput($encrypted, 8, 32, 489, 21)
$label = GUICtrlCreateLabel("Encrypted Password:", 8, 8, 104, 17)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func _Encrypt($sKey, $sData)
Local $hKey = _Crypt_DeriveKey($sKey, $CALG_AES_256)
Local $bEncrypted = _Crypt_EncryptData($sData, $hKey, $CALG_USERKEY)
_Crypt_DestroyKey($hKey)
Return $bEncrypted
EndFunc ;==>_Encrypt
Edited by jazzyjeff

Share this post


Link to post
Share on other sites
step887

Thanks JazzyJeff,

I am going to assume

HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionPoliciesSystem EnableInstallerDetection=0

HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionPoliciesSystem ConsentPromptBehaviorAdmin=0

will require a reboot, which I will have to do in the future.

Share this post


Link to post
Share on other sites
jazzyjeff

I don't believe they do... at least I don't think the ConsentPromptBehaviorAdmin value does.

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  

×