Jump to content

RunAsAdmin Script


tlman12
 Share

Recommended Posts

This is a simple script that I wrote for work but I figure that someone else might find it useful so I'm gonna post it here.

The reason I wrote this was to perform simple admin functions quickly and without having to log off of the user.

the first thing you'll probably notice is the extra buttons, I'm looking for extra functions to add so if you have any suggestions please let me know.

Also if you see anything wrong or anything that could be done better please let me know.

#Region;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=Burner.ico
#AutoIt3Wrapper_outfile=RunAsAdmin.exe
#AutoIt3Wrapper_Res_Fileversion=1.0.0.2
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=p
#EndRegion;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Global $adminuser, $adminpass, $admindomain


;===========================================
;If you would like to hard code the user and password put it here.
;===========================================
$adminuser = ""
$adminpass = ""
;- if the user is a domain user you must use the domain name ex. "abc.com" else leave as "".
$admindomain = ""


;===========================================
;No need to edit below unless your adding a function. If you do let 
;me know, I'd like to see what functions people can come up with
;===========================================




If $adminuser = "" And $adminpass = "" Then
    _RunAsLogonGui()
Else
    _MainGui()
EndIf
If $admindomain = "" Then
    $admindomain = @ComputerName
EndIf


Func _RunAsLogonGui()
    #Region ### START Koda GUI section ### Form=C:\Documents and Settings\Travis\Desktop\RunAsAdmin\RunAsMe.kxf
    $RunAsLogon = GUICreate("RunAsAdmin", 353, 151, -1, -1)
    $Label1 = GUICtrlCreateLabel("Type the credentials that you would like to use.", 24, 8, 226, 17)
    $adminuser = GUICtrlCreateInput("", 88, 32, 241, 21)
    $password = GUICtrlCreateInput("", 88, 56, 241, 21, BitOR($ES_PASSWORD, $ES_AUTOHSCROLL))
    $domain = GUICtrlCreateInput("", 88, 80, 241, 21)
    $Label2 = GUICtrlCreateLabel("Username:", 32, 32, 55, 17)
    $Label3 = GUICtrlCreateLabel("Password:", 32, 56, 53, 17)
    $Label4 = GUICtrlCreateLabel("Domain: (Leave " & @CRLF & "Blank for local" & @CRLF & "computer)", 8, 80, 79, 57)
    $Ok = GUICtrlCreateButton("Ok", 88, 112, 81, 17, $BS_DEFPUSHBUTTON)
    $Cancel = GUICtrlCreateButton("Cancel", 248, 112, 81, 17, 0)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit


            Case $Ok
                $adminuser = GUICtrlRead($adminuser)
                $adminpass = GUICtrlRead($password)
                $admindomain = GUICtrlRead($domain)
                If $domain = "" Then
                    $domain = @ComputerName
                EndIf
                
                GUIDelete($RunAsLogon)
                RunAs($adminuser, $admindomain, $adminpass, 0, "cmd.exe", "", @SW_HIDE)
                If @error Then
                    MsgBox(48, "Sorry", "Your username or password is incorrect.")
                    _RunAsLogonGui()
                Else
                    _MainGui()
                EndIf
                
            Case $Cancel
                MsgBox(48, "Error!", "Script can not continue without credintials.")
                Exit
        EndSwitch
    WEnd
EndFunc;==>_RunAsLogonGui




Func _RunAsAdminWait($cmd)
    RunAsWait($adminuser, $admindomain, $adminpass, 1, $cmd)
EndFunc;==>_RunAsAdminWait
Func _RunAsAdmin($cmd)
    RunAs($adminuser, $admindomain, $adminpass, 1, $cmd)
EndFunc;==>_RunAsAdmin

Func _MainGui()
    #Region ### START Koda GUI section ### Form=
    $RunAsAdmin = GUICreate("RunAsAdmin", 293, 517, -1, -1)
    $arprog = GUICtrlCreateButton("Add/Rem Programs", 24, 56, 113, 25, 0)
    $compmgmt = GUICtrlCreateButton("Computer Mgmt.", 24, 88, 113, 25, 0)
    $cmdp = GUICtrlCreateButton("Command Prompt", 24, 120, 113, 25, 0)
    $power = GUICtrlCreateButton("Power Options", 24, 152, 113, 25, 0)
    $ioptions = GUICtrlCreateButton("Internet Options", 24, 184, 113, 25, 0)
    $gpedit = GUICtrlCreateButton("GPedit", 152, 56, 113, 25, 0)
    $taskman = GUICtrlCreateButton("Task Manager", 152, 88, 113, 25, 0)
    $iexp = GUICtrlCreateButton("Internet Explorer", 152, 120, 113, 25, 0)
    $datetime = GUICtrlCreateButton("Date/Time", 152, 152, 113, 25, 0)
    $Button10 = GUICtrlCreateButton("", 152, 184, 113, 25, 0)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $apw = GUICtrlCreateButton("Add Printer Wizard", 24, 216, 113, 25, 0)
    $Button12 = GUICtrlCreateButton("", 24, 248, 113, 25, 0)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $Button13 = GUICtrlCreateButton("", 24, 280, 113, 25, 0)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $psp = GUICtrlCreateButton("Print Server Prop.", 152, 216, 113, 25, 0)
    $Button15 = GUICtrlCreateButton("", 152, 248, 113, 25, 0)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $Button16 = GUICtrlCreateButton("", 152, 280, 113, 25, 0)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $cfr = GUICtrlCreateButton("Choose File Run", 24, 312, 113, 25, 0)
    $sta = GUICtrlCreateButton("Switch to Admin", 24, 344, 113, 25, 0)
    $cfd = GUICtrlCreateButton("Choose File Delete", 152, 312, 113, 25, 0)
    $sbtu = GUICtrlCreateButton("Switch Back to User", 152, 344, 113, 25, 0)
    $Label1 = GUICtrlCreateLabel("Run a command as Admin", 80, 384, 128, 17)
    $runcmd = GUICtrlCreateInput("", 24, 408, 241, 21)
    $run = GUICtrlCreateButton("Run", 88, 440, 113, 25, $BS_DEFPUSHBUTTON)
    $Label2 = GUICtrlCreateLabel('All buttons below will be run under "' & $adminuser & "'s" & '" ' & @CRLF & 'Credentials with the exception of "Switch back to' & @CRLF & 'User which will be run as ' & '"' & @UserName & '"', 24, 8, 542, 41)
    $Help = GUICtrlCreateButton("Help?", 88, 472, 115, 25, 0)

    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit

            Case $arprog
                $var = "cmd /c start appwiz.cpl"
                _RunAsAdmin($var)
            Case $compmgmt
                $var = "cmd /c start compmgmt.msc"
                _RunAsAdmin($var)
            Case $cmdp
                $var = "cmd"
                _RunAsAdmin($var)
            Case $power
                $var = "cmd /c start powercfg.cpl"
                _RunAsAdmin($var)
            Case $ioptions
                $var = "cmd /c start inetcpl.cpl"
                _RunAsAdmin($var)
            Case $gpedit
                $var = "cmd /c start gpedit.msc"
                _RunAsAdmin($var)
            Case $taskman
                $var = "taskmgr"
                _RunAsAdmin($var)
            Case $iexp
                $var = "cmd /c start iexplore.exe"
                _RunAsAdmin($var)
            Case $datetime
                $var = "cmd /c start timedate.cpl"
                _RunAsAdmin($var)
            Case $Button10
            Case $apw
                $var = "rundll32 printui.dll,PrintUIEntry /il"
                _RunAsAdmin($var)
            Case $Button12
            Case $Button13
            Case $psp
                $var = "rundll32 printui.dll,PrintUIEntry /s /t1 /n\\" & @ComputerName
                _RunAsAdmin($var)
            Case $Button15
            Case $Button16
            Case $cfr
                $message = "Choose an executable file to run as " & $adminuser

                $var = FileOpenDialog($message, @WindowsDir & "\system32" & "", "Executables (*.exe;*.msc,*.vbs,*.msi,*.bat)", 1)

                If @error Then
                    MsgBox(4096, "", "No File(s) chosen")
                Else
                    $var = StringReplace($var, "|", @CRLF)
                    _RunAsAdmin($var)
                EndIf
            Case $sta
                _RunAsAdminWait("cmd /c taskkill /f /im explorer.exe")
                _RunAsAdmin("explorer.exe")
            Case $cfd
                $message = "Choose an executable file to run as " & $adminuser

                $var = FileOpenDialog($message, @HomeDrive & "", "All Files (*.*)", 1)

                If @error Then
                    MsgBox(4096, "", "No File(s) chosen")
                Else
                    $var = StringReplace($var, "|", @CRLF)
                    $del = 'cmd /c del "' & $var & '"'
                    _RunAsAdmin($del)
                EndIf
                _RunAsAdmin($var)
            Case $sbtu
                _RunAsAdminWait("cmd /c taskkill /f /im explorer.exe")
                Run("explorer.exe")
            Case $run
                $var = GUICtrlRead($runcmd)
                _RunAsAdmin($var)
            Case $Help
                MsgBox(4128, "Help?", "Error loading help file. Exit code: ID 10T")
        EndSwitch
    WEnd
EndFunc;==>_MainGui

RunAsAdmin.exe

Edited by tlman12
Link to comment
Share on other sites

Hello, i tried to compile your script from the provided code but it does not work, the exe provided does work but i can't decompile it. So can you correct the code above?

I am very interested in a tool like this and also would like to extend it perhaps!

Thx in advance.

Link to comment
Share on other sites

Hello, i tried to compile your script from the provided code but it does not work, the exe provided does work but i can't decompile it. So can you correct the code above?

I am very interested in a tool like this and also would like to extend it perhaps!

Thx in advance.

Your issue with compiling may be with the version of autoit you are using.

because the older versions used RunAsSet() and the newer version use RunAs()

i currently use version 3.2.12.1 and i'm not sure exactly what version this changed in but i just copied the code directly from above into a new au3 file and compiled it with no problem.

Hope this helps

Link to comment
Share on other sites

Your issue with compiling may be with the version of autoit you are using.

because the older versions used RunAsSet() and the newer version use RunAs()

i currently use version 3.2.12.1 and i'm not sure exactly what version this changed in but i just copied the code directly from above into a new au3 file and compiled it with no problem.

Hope this helps

hm it seems i'am running behind, still have autoit 3.2.4.x

I'll have a look to upgrade :mellow:

My bad!

Link to comment
Share on other sites

Found a slight error

what i had

Case $Ok
                $adminuser = GUICtrlRead($adminuser)
                $adminpass = GUICtrlRead($password)
                $admindomain = GUICtrlRead($domain)
                If $domain = "" Then
                    $domain = @ComputerName
                EndIf

should have been

Case $Ok
                $adminuser = GUICtrlRead($adminuser)
                $adminpass = GUICtrlRead($password)
                $admindomain = GUICtrlRead($domain)
                If $admindomain = "" Then
                    $admindomain = @ComputerName
                EndIf

i've fixed it above but if you copied it previously you may need to change it

Link to comment
Share on other sites

This is awesome. I run on a limited account for most things and hate switching over to admin all the time. This makes things so much easier. Thanks

HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Link to comment
Share on other sites

  • 2 weeks later...

I made a few changes, made gui wider and added more empty buttons for later use as well as added buttons of my own, This was more for use for me, but I thought I would submit it and see what ya thought, I also changed the names of buttons, to help organize which buttons are where, since there are now 40 buttons altogether

#cs ----------------------------------------------------------------------------

AutoIt Version: 3.2.12.1

Author: myName

Script Function:

Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

#Region;**** Directives created by AutoIt3Wrapper_GUI ****

#AutoIt3Wrapper_icon=Burner.ico

#AutoIt3Wrapper_outfile=RunAsAdmin.exe

#AutoIt3Wrapper_Res_Fileversion=1.0.0.2

#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=p

#EndRegion;**** Directives created by AutoIt3Wrapper_GUI ****

#include <ButtonConstants.au3>

#include <EditConstants.au3>

#include <GUIConstantsEx.au3>

#include <StaticConstants.au3>

#include <WindowsConstants.au3>

Global $adminuser, $adminpass, $admindomain

;===========================================

;If you would like to hard code the user and password put it here.

;===========================================

$adminuser = ""

$adminpass = ""

;- if the user is a domain user you must use the domain name ex. "abc.com" else leave as "".

$admindomain = ""

;===========================================

;No need to edit below unless your adding a function. If you do let

;me know, I'd like to see what functions people can come up with

;===========================================

If $adminuser = "" And $adminpass = "" Then

_RunAsLogonGui()

Else

_MainGui()

EndIf

If $admindomain = "" Then

$admindomain = @ComputerName

EndIf

Func _RunAsLogonGui()

#Region ### START Koda GUI section ### Form=C:\Documents and Settings\Travis\Desktop\RunAsAdmin\RunAsMe.kxf

$RunAsLogon = GUICreate("RunAsAdmin", 353, 151, -1, -1)

$Label1 = GUICtrlCreateLabel("Type the credentials that you would like to use.", 24, 8, 226, 17)

$adminuser = GUICtrlCreateInput("", 88, 32, 241, 21)

$password = GUICtrlCreateInput("", 88, 56, 241, 21, BitOR($ES_PASSWORD, $ES_AUTOHSCROLL))

$domain = GUICtrlCreateInput("", 88, 80, 241, 21)

$Label2 = GUICtrlCreateLabel("Username:", 32, 32, 55, 17)

$Label3 = GUICtrlCreateLabel("Password:", 32, 56, 53, 17)

$Label4 = GUICtrlCreateLabel("Domain: (Leave " & @CRLF & "Blank for local" & @CRLF & "computer)", 8, 80, 79, 57)

$Ok = GUICtrlCreateButton("Ok", 88, 112, 81, 17, $BS_DEFPUSHBUTTON)

$Cancel = GUICtrlCreateButton("Cancel", 248, 112, 81, 17, 0)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $Ok

$adminuser = GUICtrlRead($adminuser)

$adminpass = GUICtrlRead($password)

$admindomain = GUICtrlRead($domain)

If $domain = "" Then

$domain = @ComputerName

EndIf

GUIDelete($RunAsLogon)

RunAs($adminuser, $admindomain, $adminpass, 0, "cmd.exe", "", @SW_HIDE)

If @error Then

MsgBox(48, "Sorry", "Your username or password is incorrect.")

_RunAsLogonGui()

Else

_MainGui()

EndIf

Case $Cancel

MsgBox(48, "Error!", "Script can not continue without credintials.")

Exit

EndSwitch

WEnd

EndFunc;==>_RunAsLogonGui

func _AddDomain()

#Region ### START Koda GUI section ### Form=C:\Documents and Settings\Travis\Desktop\RunAsAdmin\RunAsMe.kxf

$AddDomain = GUICreate("Add To domain", 353, 151, -1, -1)

$Label1 = GUICtrlCreateLabel("Type the credentials that you would like to use to add to domain.", 24, 8, 305, 17, $ES_Center)

$uname = GUICtrlCreateInput("", 88, 32, 241, 21)

$password = GUICtrlCreateInput("", 88, 56, 241, 21, BitOR($ES_PASSWORD, $ES_AUTOHSCROLL))

$Label2 = GUICtrlCreateLabel("Username:", 32, 32, 55, 17)

$Label3 = GUICtrlCreateLabel("Password:", 32, 56, 53, 17)

$Ok = GUICtrlCreateButton("Ok", 88, 112, 81, 17, $BS_DEFPUSHBUTTON)

$Cancel = GUICtrlCreateButton("Cancel", 248, 112, 81, 17, 0)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1

$naMsg = GUIGetMsg()

Switch $naMsg

Case $GUI_EVENT_CLOSE

Exit

Case $Ok

$un = GUICtrlRead($uname)

$pass = GUICtrlRead($password)

GUIDelete($AddDomain)

$var = "cmd /c start control sysdm.cpl,,1 -1"

_RunAsAdmin($var)

WinWaitActive("System Properties")

Send("!c")

WinWaitActive ("Computer Name Changes")

send ('!d')

send ('{tab}')

send ('gccisd.local')

sleep (300)

send ('{enter}')

winwaitactive ("Computer Name Changes", "Enter the name and password of an account")

send ($un)

Sleep(500)

send ("{tab}")

sleep(500)

send ($pass)

sleep(500)

send ('{enter}')

WinWaitActive ("Computer Name Changes", "Welcome to the gccisd.local domain.")

send('{enter 2}')

send ('{tab}')

send('{ENTER}')

WinWaitActive("System Settings Change")

Sleep (500)

send ('{ENTER}')

Case $Cancel

MsgBox(48, "Error!", "Script can not continue without credentials.")

_MainGui()

EndSwitch

WEnd

EndFunc

func _RemDomain()

$RemDomain = GUICreate("Add To domain", 353, 151, -1, -1)

$Label1 = GUICtrlCreateLabel("Type the credentials that you would like to use to Remove from the domain.", 24, 8, 305, 17, $ES_Center)

$uname = GUICtrlCreateInput("", 88, 32, 241, 21)

$password = GUICtrlCreateInput("", 88, 56, 241, 21, BitOR($ES_PASSWORD, $ES_AUTOHSCROLL))

$Label2 = GUICtrlCreateLabel("Username:", 32, 32, 55, 17)

$Label3 = GUICtrlCreateLabel("Password:", 32, 56, 53, 17)

$Ok = GUICtrlCreateButton("Ok", 88, 112, 81, 17, $BS_DEFPUSHBUTTON)

$Cancel = GUICtrlCreateButton("Cancel", 248, 112, 81, 17, 0)

GUISetState(@SW_SHOW)

While 1

$naMsg = GUIGetMsg()

Switch $naMsg

Case $GUI_EVENT_CLOSE

Exit

Case $Ok

$un = GUICtrlRead($uname)

$pass = GUICtrlRead($password)

GUIDelete($RemDomain)

$var = "cmd /c start control sysdm.cpl,,1 -1"

_RunAsAdmin($var)

WinWaitActive("System Properties")

Send("!c")

WinWaitActive ("Computer Name Changes")

send ('!w')

send ('{tab}')

send ('workgroup')

sleep (300)

send ('{enter}')

winwaitactive ("Computer Name Changes", "Enter the name and password of an account")

send ($un)

Sleep(500)

send ("{tab}")

sleep(500)

send ($pass)

sleep(500)

send ('{enter}')

WinWaitActive ("Computer Name Changes", "Welcome to the")

send('{enter 2}')

send ('{tab}')

send ('{enter}')

winwaitactive ("System Settings Change")

sleep (500)

send('{ENTER}')

Case $Cancel

MsgBox(48, "Error!", "Script can not continue without credentials.")

_MainGui()

EndSwitch

WEnd

EndFunc

Func _RunAsAdminWait($cmd)

RunAsWait($adminuser, $admindomain, $adminpass, 1, $cmd)

EndFunc;==>_RunAsAdminWait

Func _RunAsAdmin($cmd)

RunAs($adminuser, $admindomain, $adminpass, 1, $cmd)

EndFunc;==>_RunAsAdmin

Func _MainGui()

#Region ### START Koda GUI section ### Form=

$RunAsAdmin = GUICreate("RunAsAdmin", 545, 517, -1, -1)

$button1 = GUICtrlCreateButton("Add/Rem Programs", 24, 56, 113, 25, 0)

$button2 = GUICtrlCreateButton("Computer Mgmt.", 24, 88, 113, 25, 0)

$button3 = GUICtrlCreateButton("Command Prompt", 24, 120, 113, 25, 0)

$button4 = GUICtrlCreateButton("Power Options", 24, 152, 113, 25, 0)

$button5 = GUICtrlCreateButton("Add To Domain", 24, 184, 113, 25, 0)

$button6 = GUICtrlCreateButton("", 24, 216, 113, 25, 0)

GUICtrlSetState(-1, $GUI_DISABLE)

$button7 = GUICtrlCreateButton("", 24, 248, 113, 25, 0)

GUICtrlSetState(-1, $GUI_DISABLE)

$button8 = GUICtrlCreateButton("", 24, 280, 113, 25, 0)

GUICtrlSetState(-1, $GUI_DISABLE)

$button9 = GUICtrlCreateButton("", 24, 312, 113, 25, 0)

GUICtrlSetState(-1, $GUI_DISABLE)

$button10 = GUICtrlCreateButton("Lock Computer", 24, 344, 113, 25, 0)

$button11 = GUICtrlCreateButton("GPedit", 152, 56, 113, 25, 0)

$button12 = GUICtrlCreateButton("Task Manager", 152, 88, 113, 25, 0)

$button13 = GUICtrlCreateButton("Internet Explorer", 152, 120, 113, 25, 0)

$button14 = GUICtrlCreateButton("Date/Time", 152, 152, 113, 25, 0)

$button15 = GUICtrlCreateButton("Rem from Domain", 152, 184, 113, 25, 0)

$button16 = GUICtrlCreateButton("", 152, 216, 113, 25, 0)

GUICtrlSetState(-1, $GUI_DISABLE)

$button17 = GUICtrlCreateButton("", 152, 248, 113, 25, 0)

GUICtrlSetState(-1, $GUI_DISABLE)

$button18 = GUICtrlCreateButton("", 152, 280, 113, 25, 0)

GUICtrlSetState(-1, $GUI_DISABLE)

$button19 = GUICtrlCreateButton("", 152, 312, 113, 25, 0)

GUICtrlSetState(-1, $GUI_DISABLE)

$button20 = GUICtrlCreateButton("Log Off", 152, 344, 113, 25, 0)

$button21 = GUICtrlCreateButton("Internet Options", 280, 56, 113, 25, 0)

$button22 = GUICtrlCreateButton("Add Printer Wizard", 280, 88, 113, 25, 0)

$button23 = GUICtrlCreateButton("Device Manager", 280, 120, 113, 25, 0)

$button24 = GUICtrlCreateButton("Choose File Run", 280, 152, 113, 25, 0)

$button25 = GUICtrlCreateButton("Control Panel", 280, 184, 113, 25, 0)

$button26 = GUICtrlCreateButton("", 280, 216, 113, 25, 0)

GUICtrlSetState(-1, $GUI_DISABLE)

$button27 = GUICtrlCreateButton("", 280, 248, 113, 25, 0)

GUICtrlSetState(-1, $GUI_DISABLE)

$button28 = GUICtrlCreateButton("", 280, 280, 113, 25, 0)

GUICtrlSetState(-1, $GUI_DISABLE)

$button29 = GUICtrlCreateButton("", 280, 312, 113, 25, 0)

GUICtrlSetState(-1, $GUI_DISABLE)

$button30 = GUICtrlCreateButton("Shutdown", 280, 344, 113, 25, 0)

$button31 = GUICtrlCreateButton("System Properties", 408, 56, 113, 25, 0)

$button32 = GUICtrlCreateButton("Print Server Prop.", 408, 88, 113, 25, 0)

$button33 = GUICtrlCreateButton("Choose File Delete", 408, 120, 113, 25, 0)

$button34 = GUICtrlCreateButton("GPUpdate", 408, 152, 113, 25, 0)

$button35 = GUICtrlCreateButton("Windows Explorer", 408, 184, 113, 25, 0)

$button36 = GUICtrlCreateButton("", 408, 216, 113, 25, 0)

GUICtrlSetState(-1, $GUI_DISABLE)

$button37 = GUICtrlCreateButton("", 408, 248, 113, 25, 0)

GUICtrlSetState(-1, $GUI_DISABLE)

$button38 = GUICtrlCreateButton("", 408, 280, 113, 25, 0)

GUICtrlSetState(-1, $GUI_DISABLE)

$button39 = GUICtrlCreateButton("", 408, 312, 113, 25, 0)

GUICtrlSetState(-1, $GUI_DISABLE)

$button40 = GUICtrlCreateButton("Restart", 408, 344, 113, 25, 0)

$Label1 = GUICtrlCreateLabel("Run a command as Admin", 216, 384, 128, 17)

$runcmd = GUICtrlCreateInput("", 24, 408, 497, 21)

$run = GUICtrlCreateButton("Run", 216, 440, 113, 25, $BS_DEFPUSHBUTTON)

$Label2 = GUICtrlCreateLabel('All buttons below will be run under "' & $adminuser & "'s" & '" Credentials with the exception of "Switch back to User" ' & @CRLF & 'which will be run as ' & '"' & @UserName & '"', 24, 8, 497, 41, $ES_CENTER)

$sta = GUICtrlCreateButton("Switch to Admin", 24, 472, 113, 25, 0)

$close = GUICtrlCreateButton("close", 216, 472, 115, 25, 0)

$sbtu = GUICtrlCreateButton("Switch Back to User", 408, 472, 113, 25, 0)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $button1

$var = "cmd /c start appwiz.cpl"

_RunAsAdmin($var)

Case $button2

$var = "cmd /c start compmgmt.msc"

_RunAsAdmin($var)

Case $button3

$var = "cmd"

_RunAsAdmin($var)

Case $button4

$var = "cmd /c start powercfg.cpl"

_RunAsAdmin($var)

Case $button5

_AddDomain()

Case $button6

Case $button7

Case $button8

Case $button9

Case $button10

$var = "rundll32.exe user32.dll,LockWorkStation"

_RunAsAdmin($var)

Case $button11

$var = "cmd /c start gpedit.msc"

_RunAsAdmin($var)

Case $button12

$var = "taskmgr"

_RunAsAdmin($var)

Case $button13

$var = "cmd /c start iexplore.exe"

_RunAsAdmin($var)

Case $button14

$var = "cmd /c start timedate.cpl"

_RunAsAdmin($var)

Case $button15

_RemDomain()

Case $button16

Case $button17

Case $button18

Case $button19

Case $button20

run("logoff.exe")

Case $button21

$var = "cmd /c start inetcpl.cpl"

_RunAsAdmin($var)

Case $button22

$var = "rundll32 printui.dll,PrintUIEntry /il"

_RunAsAdmin($var)

Case $button23

$var = "cmd /c start devmgmt.msc"

_RunAsAdmin($var)

case $button24

$message = "Choose an executable file to run as " & $adminuser

$var = FileOpenDialog($message, @WindowsDir & "\system32" & "", "Executables (*.exe;*.msc;*.vbs;*.msi;*.bat)", 1)

If @error Then

MsgBox(4096, "", "No File(s) chosen")

Else

$var = StringReplace($var, "|", @CRLF)

_RunAsAdmin($var)

EndIf

Case $button25

$var = "control.exe"

_RunAsAdmin ($var)

Case $button26

Case $button27

Case $button28

Case $button29

Case $button30

$var = "shutdown.exe -s -f -t 00"

_RunAsAdmin($var)

Case $button31

$var = "cmd /c start sysdm.cpl"

_RunAsAdmin($var)

Case $button32

$var = "rundll32 printui.dll,PrintUIEntry /s /t1 /n\\" & @ComputerName

_RunAsAdmin($var)

Case $button33

$message = "Choose an executable file to run as " & $adminuser

$var = FileOpenDialog($message, @HomeDrive & "", "All Files (*.*)", 1)

If @error Then

MsgBox(4096, "", "No File(s) chosen")

Else

$var = StringReplace($var, "|", @CRLF)

$del = 'cmd /c del "' & $var & '"'

_RunAsAdmin($del)

EndIf

_RunAsAdmin($var)

Case $button34

$var = "cmd /k gpupdate /force"

_RunAsAdmin($var)

Case $button35

$var = "explorer.exe"

_RunAsAdmin($var)

Case $button36

Case $button37

Case $button38

Case $button39

Case $button40

$var = "shutdown.exe -r -f -t 00"

_RunAsAdmin($var)

Case $sta

_RunAsAdminWait("cmd /c taskkill /f /im explorer.exe")

_RunAsAdmin("explorer.exe")

Case $sbtu

_RunAsAdminWait("cmd /c taskkill /f /im explorer.exe")

Run("explorer.exe")

Case $run

$var = GUICtrlRead($runcmd)

_RunAsAdmin($var)

Case $close

Exit

EndSwitch

WEnd

EndFunc;==>_MainGui

Link to comment
Share on other sites

I made a few changes, made gui wider and added more empty buttons for later use as well as added buttons of my own, This was more for use for me, but I thought I would submit it and see what ya thought, I also changed the names of buttons, to help organize which buttons are where, since there are now 40 buttons altogether

That looks cool, the one thing you need to do is for add and remove domain you left _MainGui() if you click cancle. so you end up with 2 MainGui's

other then that i like the idea, I have another script i use to join computers to the domain, it uses the NetDom.exe so that i can even specify an OU to place the computer in.

That might be something to look into instead of a macro.

i use a

FileInstall("netdom.exe",@WindowsDir & "\system32\netdom.exe")

then to call it in the script you can just do a run netdom with the proper switches

Link to comment
Share on other sites

This is a great utility, which I plan on using! THANKS FOR THE GREAT POST!!

I made a few changes, made gui wider and added more empty buttons for later use as well as added buttons of my own, This was more for use for me, but I thought I would submit it and see what ya thought, I also changed the names of buttons, to help organize which buttons are where, since there are now 40 buttons altogether

Roger O."When people show you who they are, believe them.” --Mark Twain

Link to comment
Share on other sites

  • 1 month later...

That looks cool, the one thing you need to do is for add and remove domain you left _MainGui() if you click cancle. so you end up with 2 MainGui's

other then that i like the idea, I have another script i use to join computers to the domain, it uses the NetDom.exe so that i can even specify an OU to place the computer in.

That might be something to look into instead of a macro.

i use a

FileInstall("netdom.exe",@WindowsDir & "\system32\netdom.exe")

then to call it in the script you can just do a run netdom with the proper switches

What is Netdom?, and how does it work, and doesnt the computer need admin pack installed to run it?

Also, Thanks for the help, Im a rather inexperienced coder, but I picked up alot of what I know from this scripts and have created a few more that incorporate all sorts of tactics.

Link to comment
Share on other sites

This is a great utility, which I plan on using! THANKS FOR THE GREAT POST!!

Your welcome, its more built for my Network, but I will add the new one I made that will work for any network, it now foregoes the admin pass and shows a combobox for domain and you can choose between the logon domain name or computer name its pretty nice, I need to put the finishing touches and Ill post it
Link to comment
Share on other sites

@wbfreeman

I haven't tried your program, and mine uses 'RunAs', but you might like to check out - Admin Rights & Admin File Management, both of which can be found here. Admin File Management especially may give you more ideas ... I may upgrade and improve it (them) one day. I'm pretty certain both can be decompiled, but let me know if you have trouble. If you wait a bit (day or three), I'll convert them to my smaller package format for better downloading.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

What is Netdom?, and how does it work, and doesnt the computer need admin pack installed to run it?

Also, Thanks for the help, Im a rather inexperienced coder, but I picked up alot of what I know from this scripts and have created a few more that incorporate all sorts of tactics.

Netdom is a utility to add remove computer accounts and join the domain. and you only need to install the admin pack in your computer and copy the netdom.exe file it can be run stand alone. thats why i use a fileinstall to put it into the sys32 folder that way it can be run from the command line without specifing a path which makes it more reliable.

Link to comment
Share on other sites

  • 2 weeks later...

Very nice script

In the list is Internet Explorer which I used to use admin over file system but with IE7 this no longer works as it opens a new window (with users credentials) when you put in the local path.

I now use "explorer.exe /separate" to start a Windows explorer session with admin credentials.

Link to comment
Share on other sites

This is a simple script that I wrote for work but I figure that someone else might find it useful so I'm gonna post it here.

...

...             
      RunAs($adminuser, $admindomain, $adminpass, 0, "cmd.exe", "", @SW_HIDE)
...
I don't think using RunAs is good idea.

Everyone could read the commandline with Procexp. Also an autoitscript was postet GetCommandlineFromPID Udf.

You can take a look at Surun on the website the sourcecode is also available for download. This program works secure. It asks for an administrative account and adds a security token to the users process. This utility is written in C++ since it uses WinApi functions to inject the security token I think it could be converted to autoit.

Best wishes

Paul

Edited by PaulBaumann
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...