Sign in to follow this  
Followers 0
3mustgetbeers

GUI appears then disappears!

4 posts in this topic

#1 ·  Posted (edited)

Hi Guys and Girls!

I'm creating a GUI for the Service Desk at work. The idea is that this will be loaded onto client PCs to be loaded remotely and automate various tasks. Pretty simple...

However, there are certain things locked down by policy - such as control pannel CPLs - that can only be ran as admin. Rather than log the user off and log on as admin, Service Desk staff generally create a desktop shortcut to, for example, appwiz.cpl; then right click and "Run As". After playing about I decided it would be easier ( :) ) to just create a a second GUI requesting admin credentials which are simply passed into the runas cmd line. Here's what I have so far...

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <ComboConstants.au3>
#include <GuiToolBar.au3>
#include <IE.au3>
#include <Array.au3>
#include <GuiMenu.au3>
#include "constants.au3"
#include <WindowsConstants.au3>
#include <ProgressConstants.au3>
#include <INet.au3>
#include <ScreenCapture.au3>
#include <outlookex.au3>

Global $F_Drive_Path = "\\Server\Share$"
Global $J_Drive_Path = "\\Server\Share$"
Global $H_Drive_Path = "\\Server\Share$"
Global $M_Drive_Path = "\\Server\Share$"
Global $P_Drive_Path = "\\Server\Share$"
Global $Q_Drive_Path = "\\Server\Share$"
Global $T_Drive_Path = "\\Server\Share$"

Global $Outlook_Path = "C:\Program Files\Microsoft Office\Office12\"

;File locations
$PrintDriverLocation = "\\Server\Share$"
$GoToCodecFile = "\\Server\Share$\g2m_codec.exe" 
$CutePDFLocation = "\\Server\Share$\CutePDF"

;Email Location
$SD_EmailAddress = "abc@def.xyz" ;account where emails will be sent


;Null values for GUI's to prevent cases firing

Global $RunAs_GUI = 0, $OK = 0, $INPUT_usrnm = 0, $INPUT_psswd = 0

NEW()


Func NEW()
    $aTaskbar = WinGetPos("[CLASS:Shell_TrayWnd]", "")
    $SD_Client = GUICreate("IS Service Desk Client", 175, 19, @DesktopWidth, @DesktopHeight, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS), $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
    SetWindowPos($SD_Client, $HWND_TOPMOST + $HWND_TOP, 0, 0, 0, 0, BitOR($SWP_NOMOVE, $SWP_NOSIZE))


    #Region Main GUI Contents
    $DLD = GUICtrlCreateMenu("Download")
    $DLDprt = GUICtrlCreateMenuItem("Print Drivers", $DLD)
    $DLDcodec = GUICtrlCreateMenuItem("GoTo Codec", $DLD)
    $DLDpdf = GUICtrlCreateMenuItem("CutePDF", $DLD)
    $Tls = GUICtrlCreateMenu("Tools")
    $TLSdrive = GUICtrlCreateMenu("Map Network Drive", $Tls)
    $TLS_F_Drive = GUICtrlCreateMenuItem("F:\", $TLSdrive)
    $TLS_H_Drive = GUICtrlCreateMenuItem("H:\", $TLSdrive)
    $TLS_J_Drive = GUICtrlCreateMenuItem("J:\", $TLSdrive)
    $TLS_M_Drive = GUICtrlCreateMenuItem("M:\", $TLSdrive)
    $TLS_P_Drive = GUICtrlCreateMenuItem("P:\", $TLSdrive)
    $TLS_Q_Drive = GUICtrlCreateMenuItem("Q:\", $TLSdrive)
    $TLS_T_Drive = GUICtrlCreateMenuItem("T:\", $TLSdrive)
    $TLSgpupdate = GUICtrlCreateMenuItem("GPUpdate", $Tls)
    $TLSprtscr = GUICtrlCreateMenuItem("Email Me Screenshot", $Tls)
    $Opn = GUICtrlCreateMenu("Open...")
    $Outlook = GUICtrlCreateMenu("Outlook", $Opn)
    $OUTsafe = GUICtrlCreateMenuItem("Safe Mode", $Outlook)
    $OUTrules = GUICtrlCreateMenuItem("Clear All Rules", $Outlook)
    $OUTsearch = GUICtrlCreateMenuItem("Reset Search Function", $Outlook)
    $OUTreminder = GUICtrlCreateMenuItem("Refresh Reminders", $Outlook)
    $OUTview = GUICtrlCreateMenuItem("Restore Default View", $Outlook)
    $OUTfolders = GUICtrlCreateMenuItem("Restore Default Mail Folders", $Outlook)
    $OUTcaldar = GUICtrlCreateMenuItem("Add Appointments to Calendar", $Outlook)
    $Control_Panel = GUICtrlCreateMenu("Control Panel", $Opn)
    $AccessCPL = GUICtrlCreateMenuItem("Accessibility Options", $Control_Panel)
    $hdwwizCPL = GUICtrlCreateMenuItem("Add New Hardware", $Control_Panel)
    $appwizCPL = GUICtrlCreateMenuItem("Add/Remove Programs", $Control_Panel)
    $timedateCPL = GUICtrlCreateMenuItem("Date and Time", $Control_Panel)
    $deskCPL = GUICtrlCreateMenuItem("Display", $Control_Panel)
    $inetCPL = GUICtrlCreateMenuItem("Internet Options", $Control_Panel)
    $joyCPL = GUICtrlCreateMenuItem("Game Controllers", $Control_Panel)
    $mailCPL = GUICtrlCreateMenuItem("Mail Options", $Control_Panel)
    $mainCPL = GUICtrlCreateMenuItem("Mouse", $Control_Panel)
    $ncpaCPL = GUICtrlCreateMenuItem("Network", $Control_Panel)
    $powercfgCPL = GUICtrlCreateMenuItem("Power Options", $Control_Panel)
    $intlCPL = GUICtrlCreateMenuItem("Regional and Language", $Control_Panel)
    $wscuiCPL = GUICtrlCreateMenuItem("Security Center", $Control_Panel)
    $SysdmCPL = GUICtrlCreateMenuItem("System", $Control_Panel)

    $aWin = WinGetPos($SD_Client)
    WinMove($SD_Client, "", @DesktopWidth - $aWin[2] - 0, @DesktopHeight - $aWin[3] - $aTaskbar[3] - 0)
    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg(1)
        Switch $nMsg[1]
            Case $SD_Client
                Switch $nMsg[0]
                    Case $GUI_EVENT_CLOSE
                        Exit
                    Case $DLDprt
                        Run("C:\WINDOWS\EXPLORER.EXE /n,/e," & $PrintDriverLocation)
                    Case $DLDcodec
                        FileCopy($GoToCodecFile, "C:\", 9)
                        MsgBox(64, "Copy Complete", "Codec has been copied to C:\")
                    Case $DLDpdf
                        DirCopy($CutePDFLocation, "C:\", 1)
                        MsgBox(64, "Copy Complete", "CutePDF & Convertor have been copied to C:\")

                        ; $TLSdrive
                    Case $TLS_F_Drive
                        DriveMapAdd("F:", $F_Drive_Path)
                    Case $TLS_H_Drive
                        DriveMapAdd("H:", $H_Drive_Path)
                    Case $TLS_J_Drive
                        DriveMapAdd("J:", $J_Drive_Path)
                    Case $TLS_M_Drive
                        DriveMapAdd("M:", $M_Drive_Path)
                    Case $TLS_P_Drive
                        DriveMapAdd("P:", $P_Drive_Path)
                    Case $TLS_Q_Drive
                        DriveMapAdd("Q:", $Q_Drive_Path)
                    Case $TLS_T_Drive
                        DriveMapAdd("T:", $T_Drive_Path)
                    Case $TLSgpupdate
                        RunWait(@ComSpec & " /c " & "gpupdate /force", "", @SW_HIDE)
                    Case $TLSprtscr
                        ; Take screen shot & save
                        Local $TLSprtscr_image ;variable for image name
                        WinActivate("Panel")
                        Local $TLSprtscr_image = _ScreenCapture_Capture("C:\ISSD_PRTSCR.jpg", 0, 0, @DesktopWidth + @DesktopWidth, @DesktopHeight, True)
                        Local $oOutlook = _OL_Open()

                        _OL_Wrapper_SendMail($oOutlook, _ ; mail client
                                $SD_EmailAddress, _ ; TO:
                                "", _ ; CC:
                                "", _ ; BCC:
                                "Screenshot from (USERNAME: " & @UserName & ") working on (HOSTNAME: " & @ComputerName & ")", _ ;Subject
                                "Hi.<br><br>Please find a screen shot of my error attached.<br><br>Thanks,<br><br>" & @UserName, _ ; Body
                                "C:\ISSD_PRTSCR.jpg", _ ; Attachment
                                $olFormatHTML, "") _ ; format
                                
                        If @error <> 0 Then Exit MsgBox(16, "ERROR", "Error sending mail." & @CRLF & "Please try again." & @CRLF & "If problem persists, please complete task manually")
                        MsgBox(64, "Complete", "Screenshot succussfully sent to '" & $SD_EmailAddress & "'." & @CRLF & "NOTE: This will show in your sent items.")

                        FileDelete("C:\ISSD_PRTSCR.jpg")



                        ;Outlook Switches
                    Case $OUTsafe
                        Run($Outlook_Path & "Outlook.exe /safe")
                    Case $OUTrules
                        Run($Outlook_Path & "Outlook.exe /CleanRules")
                    Case $OUTsearch
                        Run($Outlook_Path & "Outlook.exe /CleanFinders")
                    Case $OUTreminder
                        Run($Outlook_Path & "Outlook.exe /CleanReminders")
                    Case $OUTview
                        Run($Outlook_Path & "Outlook.exe /CleanViews")
                    Case $OUTfolders
                        Run($Outlook_Path & "Outlook.exe /ResetFolders")
                    Case $OUTcaldar
                        Run($Outlook_Path & "Outlook.exe /Sniff")

                        ;Control Panel
                    Case $AccessCPL

                    Case $hdwwizCPL

                    Case $appwizCPL

                    Case $timedateCPL

                    Case $deskCPL

                    Case $inetCPL

                    Case $joyCPL

                    Case $mailCPL

                    Case $mainCPL

                    Case $ncpaCPL

                    Case $powercfgCPL

                    Case $intlCPL

                    Case $wscuiCPL

                    Case $SysdmCPL

                EndSwitch
            Case $RunAs_GUI
                Switch $nMsg[0] 
                    Case $GUI_EVENT_CLOSE
                        GUIDelete($RunAs_GUI)

                    Case $OK
                        Global $Username = GUICtrlRead($INPUT_usrnm)
                        GUIDelete($RunAs_GUI)




                EndSwitch
        EndSwitch

    WEnd



EndFunc   ;==>NEW

Func SetWindowPos($hwnd, $InsertHwnd, $X, $Y, $cX, $cY, $uFlags)
    $ret = DllCall("user32.dll", "long", "SetWindowPos", "hwnd", $hwnd, "hwnd", $InsertHwnd, _
            "int", $X, "int", $Y, "int", $cX, "int", $cY, "long", $uFlags)
    Return $ret[0]
EndFunc   ;==>SetWindowPos


Func RunAsAdmin()
    $RunAs_GUI = GUICreate("Run As", 245, 214, 490, 210)
    $Title = GUICtrlCreateLabel("Run As...", 8, 8, 62, 20)
    GUICtrlSetFont(-1, 10, 800, 0, "Tahoma")
    $SubTitle1 = GUICtrlCreateLabel("This option requires elevated permission.", 8, 40, 227, 18)
    GUICtrlSetFont(-1, 9, 400, 0, "Tahoma")
    $SubTitle2 = GUICtrlCreateLabel("Please enter admin credentials below...", 8, 56, 219, 18)
    GUICtrlSetFont(-1, 9, 400, 0, "Tahoma")
    $Usrnm = GUICtrlCreateLabel("Username:", 8, 80, 67, 20)
    GUICtrlSetFont(-1, 10, 400, 0, "Tahoma")
    $Psswd = GUICtrlCreateLabel("Password:", 8, 112, 64, 20)
    GUICtrlSetFont(-1, 10, 400, 0, "Tahoma")
    $INPUT_usrnm = GUICtrlCreateInput("DOMAIN\", 96, 80, 137, 21)
    $INPUT_psswd = GUICtrlCreateInput("", 96, 112, 137, 21, $ES_PASSWORD)
    $OK = GUICtrlCreateButton("OK", 80, 144, 75, 25)
    $Disclaimer = GUICtrlCreateLabel("NOTE: No credentials are stored or cached! ", 16, 184, 212, 17)
    GUICtrlSetFont(-1, 8, 400, 2, "Tahoma")
    GUICtrlSetColor(-1, 0xFF0000)
    GUISetState(@SW_SHOW)
EndFunc   ;==>RunAsAdmin

The problem is, when launched the initial GUI flashes on screen then off straight away. I read through this to get this far. I am inclined to believe it has something to do with a/the case/s "firing" so declared all at the start with this line

Global $RunAs_GUI = 0, $OK = 0, $INPUT_usrnm = 0, $SD_Client = 0, $INPUT_psswd = 0, $DLDprt = 0, _
$DLDcodec = 0, $DLDpdf = 0, $TLS_F_Drive_Stonham = 0, $TLS_F_Drive_HomeHousing = 0, $TLS_H_Drive = 0, _
$TLS_J_Drive = 0, $TLS_M_Drive = 0, $TLS_P_Drive = 0, $TLS_Q_Drive = 0, $TLS_T_Drive = 0, $TLSgpupdate = 0, _
$TLSprtscr = 0, $OUTsafe = 0, $OUTrules = 0, $OUTsearch = 0, $OUTreminder = 0, $OUTview = 0, $OUTfolders = 0, _
$OUTcaldar = 0, $AccessCPL = 0, $hdwwizCPL = 0, $appwizCPL = 0, $timedateCPL = 0, $deskCPL = 0, $inetCPL = 0, _
$joyCPL = 0, $mailCPL = 0, $mainCPL = 0, $ncpaCPL = 0, $powercfgCPL = 0, $intlCPL = 0, $wscuiCPL = 0, _
$SysdmCPL = 0, $RunAs_GUI = 0, $OK = 0

That is every case set to 0. Is this right? I have read through this for the past 2 hours tweaking bits but simply can't see where I'm going wrong.

I now fully understand the meaning of frustration; so guru's, please put me out of my misery :3MGB_Crying_Like_A_Baby:

Thanks for any help - no matter how small ;)

3mgb

Edited by 3mustgetbeers

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You are wrong here: Line 44

When you create the GUI you set the x pos as width and the Y pos as Height. also you set wrong the styles is not

$WS_EX_TOOLWINDOW + $WS_EX_TOPMOST

is

BitOr($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)

The line that you want maybe this

$SD_Client = GUICreate("IS Service Desk Client", @DesktopWidth, @DesktopHeight, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS), BitOr($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))

EDITED: Also declare the buttons index as 9999 not as 0 because that cause problems. do it like the example from the wiki.

Here you got. maybe i was wrong with something and this is what you really want. i only edit the global values for the ControlsID

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <ComboConstants.au3>
#include <GuiToolBar.au3>
#include <IE.au3>
#include <Array.au3>
#include <GuiMenu.au3>
#include "constants.au3"
#include <WindowsConstants.au3>
#include <ProgressConstants.au3>
#include <INet.au3>
#include <ScreenCapture.au3>
;~ #include <outlookex.au3>

Global $F_Drive_Path = "\\Server\Share$"
Global $J_Drive_Path = "\\Server\Share$"
Global $H_Drive_Path = "\\Server\Share$"
Global $M_Drive_Path = "\\Server\Share$"
Global $P_Drive_Path = "\\Server\Share$"
Global $Q_Drive_Path = "\\Server\Share$"
Global $T_Drive_Path = "\\Server\Share$"

Global $Outlook_Path = "C:\Program Files\Microsoft Office\Office12\"

;File locations
$PrintDriverLocation = "\\Server\Share$"
$GoToCodecFile = "\\Server\Share$\g2m_codec.exe"
$CutePDFLocation = "\\Server\Share$\CutePDF"

;Email Location
$SD_EmailAddress = "abc@def.xyz" ;account where emails will be sent


;Null values for GUI's to prevent cases firing

Global $RunAs_GUI = 0, $OK = 9999, $INPUT_usrnm = 9999, $INPUT_psswd = 9999

NEW()


Func NEW()
    $aTaskbar = WinGetPos("[CLASS:Shell_TrayWnd]", "")
    $SD_Client = GUICreate("IS Service Desk Client", 175, 19, @DesktopWidth, @DesktopHeight, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS), $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
    SetWindowPos($SD_Client, $HWND_TOPMOST + $HWND_TOP, 0, 0, 0, 0, BitOR($SWP_NOMOVE, $SWP_NOSIZE))


    #Region Main GUI Contents
    $DLD = GUICtrlCreateMenu("Download")
    $DLDprt = GUICtrlCreateMenuItem("Print Drivers", $DLD)
    $DLDcodec = GUICtrlCreateMenuItem("GoTo Codec", $DLD)
    $DLDpdf = GUICtrlCreateMenuItem("CutePDF", $DLD)
    $Tls = GUICtrlCreateMenu("Tools")
    $TLSdrive = GUICtrlCreateMenu("Map Network Drive", $Tls)
    $TLS_F_Drive = GUICtrlCreateMenuItem("F:\", $TLSdrive)
    $TLS_H_Drive = GUICtrlCreateMenuItem("H:\", $TLSdrive)
    $TLS_J_Drive = GUICtrlCreateMenuItem("J:\", $TLSdrive)
    $TLS_M_Drive = GUICtrlCreateMenuItem("M:\", $TLSdrive)
    $TLS_P_Drive = GUICtrlCreateMenuItem("P:\", $TLSdrive)
    $TLS_Q_Drive = GUICtrlCreateMenuItem("Q:\", $TLSdrive)
    $TLS_T_Drive = GUICtrlCreateMenuItem("T:\", $TLSdrive)
    $TLSgpupdate = GUICtrlCreateMenuItem("GPUpdate", $Tls)
    $TLSprtscr = GUICtrlCreateMenuItem("Email Me Screenshot", $Tls)
    $Opn = GUICtrlCreateMenu("Open...")
    $Outlook = GUICtrlCreateMenu("Outlook", $Opn)
    $OUTsafe = GUICtrlCreateMenuItem("Safe Mode", $Outlook)
    $OUTrules = GUICtrlCreateMenuItem("Clear All Rules", $Outlook)
    $OUTsearch = GUICtrlCreateMenuItem("Reset Search Function", $Outlook)
    $OUTreminder = GUICtrlCreateMenuItem("Refresh Reminders", $Outlook)
    $OUTview = GUICtrlCreateMenuItem("Restore Default View", $Outlook)
    $OUTfolders = GUICtrlCreateMenuItem("Restore Default Mail Folders", $Outlook)
    $OUTcaldar = GUICtrlCreateMenuItem("Add Appointments to Calendar", $Outlook)
    $Control_Panel = GUICtrlCreateMenu("Control Panel", $Opn)
    $AccessCPL = GUICtrlCreateMenuItem("Accessibility Options", $Control_Panel)
    $hdwwizCPL = GUICtrlCreateMenuItem("Add New Hardware", $Control_Panel)
    $appwizCPL = GUICtrlCreateMenuItem("Add/Remove Programs", $Control_Panel)
    $timedateCPL = GUICtrlCreateMenuItem("Date and Time", $Control_Panel)
    $deskCPL = GUICtrlCreateMenuItem("Display", $Control_Panel)
    $inetCPL = GUICtrlCreateMenuItem("Internet Options", $Control_Panel)
    $joyCPL = GUICtrlCreateMenuItem("Game Controllers", $Control_Panel)
    $mailCPL = GUICtrlCreateMenuItem("Mail Options", $Control_Panel)
    $mainCPL = GUICtrlCreateMenuItem("Mouse", $Control_Panel)
    $ncpaCPL = GUICtrlCreateMenuItem("Network", $Control_Panel)
    $powercfgCPL = GUICtrlCreateMenuItem("Power Options", $Control_Panel)
    $intlCPL = GUICtrlCreateMenuItem("Regional and Language", $Control_Panel)
    $wscuiCPL = GUICtrlCreateMenuItem("Security Center", $Control_Panel)
    $SysdmCPL = GUICtrlCreateMenuItem("System", $Control_Panel)

    $aWin = WinGetPos($SD_Client)
    WinMove($SD_Client, "", @DesktopWidth - $aWin[2] - 0, @DesktopHeight - $aWin[3] - $aTaskbar[3] - 0)
    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg(1)
        Switch $nMsg[1]
            Case $SD_Client
                Switch $nMsg[0]
                    Case $GUI_EVENT_CLOSE
                        Exit
                    Case $DLDprt
                        Run("C:\WINDOWS\EXPLORER.EXE /n,/e," & $PrintDriverLocation)
                    Case $DLDcodec
                        FileCopy($GoToCodecFile, "C:\", 9)
                        MsgBox(64, "Copy Complete", "Codec has been copied to C:\")
                    Case $DLDpdf
                        DirCopy($CutePDFLocation, "C:\", 1)
                        MsgBox(64, "Copy Complete", "CutePDF & Convertor have been copied to C:\")

                        ; $TLSdrive
                    Case $TLS_F_Drive
                        DriveMapAdd("F:", $F_Drive_Path)
                    Case $TLS_H_Drive
                        DriveMapAdd("H:", $H_Drive_Path)
                    Case $TLS_J_Drive
                        DriveMapAdd("J:", $J_Drive_Path)
                    Case $TLS_M_Drive
                        DriveMapAdd("M:", $M_Drive_Path)
                    Case $TLS_P_Drive
                        DriveMapAdd("P:", $P_Drive_Path)
                    Case $TLS_Q_Drive
                        DriveMapAdd("Q:", $Q_Drive_Path)
                    Case $TLS_T_Drive
                        DriveMapAdd("T:", $T_Drive_Path)
                    Case $TLSgpupdate
                        RunWait(@ComSpec & " /c " & "gpupdate /force", "", @SW_HIDE)
                    Case $TLSprtscr
                        ; Take screen shot & save
                        Local $TLSprtscr_image ;variable for image name
                        WinActivate("Panel")
;~                         Local $TLSprtscr_image = _ScreenCapture_Capture("C:\ISSD_PRTSCR.jpg", 0, 0, @DesktopWidth + @DesktopWidth, @DesktopHeight, True)
;~                         Local $oOutlook = _OL_Open()

;~                         _OL_Wrapper_SendMail($oOutlook, _ ; mail client
;~                                 $SD_EmailAddress, _ ; TO:
;~                                 "", _ ; CC:
;~                                 "", _ ; BCC:
;~                                 "Screenshot from (USERNAME: " & @UserName & ") working on (HOSTNAME: " & @ComputerName & ")", _ ;Subject
;~                                 "Hi.<br><br>Please find a screen shot of my error attached.<br><br>Thanks,<br><br>" & @UserName, _ ; Body
;~                                 "C:\ISSD_PRTSCR.jpg", _ ; Attachment
;~                                 $olFormatHTML, "") _ ; format
;~
;~                         If @error <> 0 Then Exit MsgBox(16, "ERROR", "Error sending mail." & @CRLF & "Please try again." & @CRLF & "If problem persists, please complete task manually")
                        MsgBox(64, "Complete", "Screenshot succussfully sent to '" & $SD_EmailAddress & "'." & @CRLF & "NOTE: This will show in your sent items.")

                        FileDelete("C:\ISSD_PRTSCR.jpg")



                        ;Outlook Switches
                    Case $OUTsafe
                        Run($Outlook_Path & "Outlook.exe /safe")
                    Case $OUTrules
                        Run($Outlook_Path & "Outlook.exe /CleanRules")
                    Case $OUTsearch
                        Run($Outlook_Path & "Outlook.exe /CleanFinders")
                    Case $OUTreminder
                        Run($Outlook_Path & "Outlook.exe /CleanReminders")
                    Case $OUTview
                        Run($Outlook_Path & "Outlook.exe /CleanViews")
                    Case $OUTfolders
                        Run($Outlook_Path & "Outlook.exe /ResetFolders")
                    Case $OUTcaldar
                        Run($Outlook_Path & "Outlook.exe /Sniff")

                        ;Control Panel
                    Case $AccessCPL

                    Case $hdwwizCPL

                    Case $appwizCPL

                    Case $timedateCPL

                    Case $deskCPL

                    Case $inetCPL

                    Case $joyCPL

                    Case $mailCPL

                    Case $mainCPL

                    Case $ncpaCPL

                    Case $powercfgCPL

                    Case $intlCPL

                    Case $wscuiCPL

                    Case $SysdmCPL

                EndSwitch
            Case $RunAs_GUI
                Switch $nMsg[0]
                    Case $GUI_EVENT_CLOSE
                        GUIDelete($RunAs_GUI)

                    Case $OK
                        Global $Username = GUICtrlRead($INPUT_usrnm)
                        GUIDelete($RunAs_GUI)




                EndSwitch
        EndSwitch

    WEnd



EndFunc   ;==>NEW

Func SetWindowPos($hwnd, $InsertHwnd, $X, $Y, $cX, $cY, $uFlags)
    $ret = DllCall("user32.dll", "long", "SetWindowPos", "hwnd", $hwnd, "hwnd", $InsertHwnd, _
            "int", $X, "int", $Y, "int", $cX, "int", $cY, "long", $uFlags)
    Return $ret[0]
EndFunc   ;==>SetWindowPos


Func RunAsAdmin()
    $RunAs_GUI = GUICreate("Run As", 245, 214, 490, 210)
    $Title = GUICtrlCreateLabel("Run As...", 8, 8, 62, 20)
    GUICtrlSetFont(-1, 10, 800, 0, "Tahoma")
    $SubTitle1 = GUICtrlCreateLabel("This option requires elevated permission.", 8, 40, 227, 18)
    GUICtrlSetFont(-1, 9, 400, 0, "Tahoma")
    $SubTitle2 = GUICtrlCreateLabel("Please enter admin credentials below...", 8, 56, 219, 18)
    GUICtrlSetFont(-1, 9, 400, 0, "Tahoma")
    $Usrnm = GUICtrlCreateLabel("Username:", 8, 80, 67, 20)
    GUICtrlSetFont(-1, 10, 400, 0, "Tahoma")
    $Psswd = GUICtrlCreateLabel("Password:", 8, 112, 64, 20)
    GUICtrlSetFont(-1, 10, 400, 0, "Tahoma")
    $INPUT_usrnm = GUICtrlCreateInput("DOMAIN\", 96, 80, 137, 21)
    $INPUT_psswd = GUICtrlCreateInput("", 96, 112, 137, 21, $ES_PASSWORD)
    $OK = GUICtrlCreateButton("OK", 80, 144, 75, 25)
    $Disclaimer = GUICtrlCreateLabel("NOTE: No credentials are stored or cached! ", 16, 184, 212, 17)
    GUICtrlSetFont(-1, 8, 400, 2, "Tahoma")
    GUICtrlSetColor(-1, 0xFF0000)
    GUISetState(@SW_SHOW)
EndFunc   ;==>RunAsAdmin
Edited by monoscout999

Share this post


Link to post
Share on other sites

Thats great mate! thanks very much :)

Share this post


Link to post
Share on other sites

OK, so now I have another problem, passing the input into the second gui.

When clicking one of the control pannel .cpl's, I need the "Run As" gui I created to appear, the user enter their credentials and click ok, then run the cmd runas line using the given details and the relevant cpl.

monoscout999; in the script you have provided I have the following:

Case $AccessCPL
    RunAsAdmin()
        $Username = GUICtrlRead($INPUT_usrnm)
    $Password = GUICtrlRead($INPUT_psswd)
    GUIDelete($RunAs_GUI)
    MsgBox(4096,"",$Username & " - " & $Password)

Problem is, it does exactly what I tell it, not what I want haha! It runs the GUI, deletes it and shows nothing in the message box; which is what I have. Head scratcher is, how do I pause the script until the OK button ($OK) is pressed? This way it gives the use chance to enter their details?

Alternatively, a much smoother approach would be to emulate the Windows XP right-click & 'run as'; is this possible?? This would be much better - not a kop out but because it would have the capability of questioning the DC on entered credentials...

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  
Followers 0