NerdFencer Posted March 11, 2009 Posted March 11, 2009 This is a script that I wrote as a module for another script which is not yet ready for display.It Basically clones the Run Dialog box, but with more advanced features.The code follows no particular standard but the ones I chose during each of the 10 min intervals that I wrote it in, so I know that some things could be done better but they aren't... yet. Also, this module used to involve 2 separate windows, so some leftovers from that may cause slight confusion (mainly for newbies) while trying to edit certain parts of the code.Features-All functionality of the windows Run BoxClose visual replica of windows default one for ease of use"Helpful" tool tips... if you really need themAdvanced options (click the gear for them to show up, and again to hide)Advanced - ParametersAdvanced - Working DirectoryAdvanced - Execution Action - drop-down menuAdvanced - Window State -drop-down menu (EX: Maximized, Minimized)Easily used as a module for other scriptsRequires no external includes or non-standard windows files (shell32.dll used) and defines nothing that conflicts with the standard onesFor Use in Modules-Delete Here For Standalone Purposes Only - Remove to use as a Module region in codeCall RunAsInit() function to open the dialog in your scriptCall RunAsLoop($msg) in your script's main loop (where $msg is the return value from GUIGetMsg(1) Notice: Accepts array, not default output)expandcollapse popup#Region ; Variables Global $RunGUI = -100, $OK, $CANCEL, $BROWSE, $Input, $ADVANCED Global Const $RunReg = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU" Global $RunAdvancedWorkingDirectory = 0 Global $RunAdvancedWorkingDirectoryHelp = 0 Global $RunAdvancedWorkingDirectoryReset = 0 Global $RunAdvancedWorkingDirectoryBrowse = 0 Global $RunAdvancedMaximized = 0 Global $RunAdvancedMaximizedHelp = 0 Global $RunAdvancedMaximizedReset = 0 Global $RunAdvancedBrowse = 0 Global $RunAdvancedParameters = 0 Global $RunAdvancedParametersHelp = 0 Global $RunAdvancedParametersReset = 0 Global $RunAdvancedVerb = 0 Global $RunAdvancedVerbHelp = 0 Global $RunAdvancedVerbReset = 0 Global $RunAsAdvancedClose = 0 Global $RunWorkingDir = @HomeDrive Global $RunMaximized = @SW_RESTORE Global $RunVerb = "open" Global $RunParameters = "" #EndRegion ; Variables #Region ; Here For Standalone Purposes Only - Remove to use as a Module RunAsInit() While 1 $msg = GUIGetMsg(1) If $msg[1] == $RunGUI Then RunAsLoop($msg) If $RunGUI < 0 Then Exit Sleep(20) WEnd #EndRegion ; Here For Standalone Purposes Only - Remove to use as a Module #Region ; RunAs Func RunAsInit() Local $temp, $temp2 $RunGUI = GUICreate("Run...",340,150,0,0,0x00C00000&0x80000000&0x00080000) WinMove("Run...","",0,0,340,182) GUICtrlCreateIcon("shell32.dll", 25, 10, 20, 32, 32) GUICtrlSetResizing(-1,802) GUICtrlCreateLabel("Type the name of a program, folder, document, or"&@CRLF&"Internet resource, and it will open for you.",50,20) GUICtrlSetFont(-1, 8.9) GUICtrlSetResizing(-1,802) GUICtrlCreateLabel("Open:",10,65) GUICtrlSetResizing(-1,802) GUICtrlSetTip(-1,"Type the name of a program, folder,"&@CRLF&"Document, or Internet resource here") GUICtrlSetFont(-1, 8.9) $temp = Read("MRUList") If Not($temp=="") Then $temp = StringSplit($temp,"") $Input = GUICtrlCreateCombo(StringTrimRight(Read($temp[1]),2),50,63,250) If UBound($temp)-1 > 1 Then $temp2 = "" For $i = 2 To UBound($temp)-1 $temp2 = $temp2 & "|" & StringTrimRight(Read($temp[$i]),2) Next GUICtrlSetData($Input, StringTrimLeft($temp2,1), StringTrimRight(Read($temp[1]),2)) EndIf Else RegWrite($RunReg,"MRUList","REG_SZ","") $Input = GUICtrlCreateCombo("",50,63,250) EndIf GUICtrlSetResizing(-1,802) GUICtrlSetTip($Input,"Type the name of a program, folder,"&@CRLF&"Document, or Internet resource here") $OK = GUICtrlCreateButton("OK",86,106,70,23,1) GUICtrlSetTip(-1,"Execute the program, folder,"&@CRLF&"Document, or Internet resource") GUICtrlSetResizing(-1,802) $CANCEL = GUICtrlCreateButton("Cancel",166,106,70,23) GUICtrlSetTip(-1,"Close this Window") GUICtrlSetResizing(-1,802) $BROWSE = GUICtrlCreateButton("Browse...",246,106,70,23) GUICtrlSetTip(-1,"Browse your computer for the item") GUICtrlSetResizing(-1,802) $ADVANCED = GUICtrlCreateIcon("shell32.dll", 274, 340-18, 150-18, 16, 16) GUICtrlSetTip(-1,"Show Advanced Options") $RunAdvancedParametersHelp = GUICtrlCreateIcon("shell32.dll", 27, 0, 150, 32,32) GUICtrlSetTip(-1,"Parameters - Help") GUICtrlSetResizing(-1,802) $RunAdvancedParameters = GUICtrlCreateInput($RunParameters,36,8+150,200,21) GUICtrlSetTip(-1,"Parameters") GUICtrlSetResizing(-1,802) $RunAdvancedParametersReset = GUICtrlCreateButton("Default", 250,8+150,80,21) GUICtrlSetTip(-1,"Parameters - Set to Default") GUICtrlSetResizing(-1,802) $RunAdvancedWorkingDirectoryHelp = GUICtrlCreateIcon("shell32.dll", 20, 0, 32+150, 32,32) GUICtrlSetTip(-1,"Working Directory - Help") GUICtrlSetResizing(-1,802) $RunAdvancedWorkingDirectory = GUICtrlCreateInput($RunWorkingDir,36,40+150,179,21) GUICtrlSetTip(-1,"Working Directory") GUICtrlSetResizing(-1,802) $RunAdvancedWorkingDirectoryBrowse = GUICtrlCreateIcon("shell32.dll", 5, 217, 192, 16,16) GUICtrlSetTip(-1,"Working Directory - Browse for Folder") GUICtrlSetResizing(-1,802) $RunAdvancedWorkingDirectoryReset = GUICtrlCreateButton("Default", 250,40+150,80,21) GUICtrlSetTip(-1,"Working Directory - Set to Default") GUICtrlSetResizing(-1,802) $RunAdvancedVerbHelp = GUICtrlCreateIcon("shell32.dll", 54, 0, 64+150, 32,32) GUICtrlSetTip(-1,"Action - Help") GUICtrlSetResizing(-1,802) $RunAdvancedVerb = GUICtrlCreateCombo($RunVerb,36,72+150,200,21) GUICtrlSetData(-1,Exclude("open|edit|print|properties|explore",$RunVerb)) GUICtrlSetTip(-1,"Action") GUICtrlSetResizing(-1,802) $RunAdvancedVerbReset = GUICtrlCreateButton("Default", 250,72+150,80,21) GUICtrlSetTip(-1,"Action - Set to Default") GUICtrlSetResizing(-1,802) $RunAdvancedMaximizedHelp = GUICtrlCreateIcon("shell32.dll", 49, 0, 96+150, 32,32) GUICtrlSetTip(-1,"Window State - Help") GUICtrlSetResizing(-1,802) $RunAdvancedMaximized = GUICtrlCreateCombo(StateString($RunMaximized),36,104+150,200,21) GUICtrlSetData(-1,Exclude("Standard|Minimized|Maximized|Hide",StateString($RunMaximized))) GUICtrlSetTip(-1,"Window State") GUICtrlSetResizing(-1,802) $RunAdvancedMaximizedReset = GUICtrlCreateButton("Default", 250,104+150,80,21) GUICtrlSetTip(-1,"Window State - Set to Default") GUICtrlSetResizing(-1,802) GUISetState(@SW_SHOW) EndFunc Func RunAsLoop($msg) Local $temp Switch $msg[0] Case -3 CloseRunSystem() Case $OK SetError(0) ShellExecute(GUICtrlRead($Input),$RunParameters,$RunWorkingDir,$RunVerb,$RunMaximized) If Not(@error) Then $temp = -1 For $i = Asc("a") To Asc("z") If Read(Chr($i))=="" Then $temp = $i ExitLoop EndIf Next If $temp == -1 Then $temp2=Read("MRUList") If $temp2 == "" Then $temp2 = "a" $temp=Asc(StringRight($temp2,1)) $temp2=StringReplace($temp2,Chr($temp),"") RegWrite($RunReg,"MRUList","REG_SZ",$temp2) EndIf RegWrite($RunReg,String(Chr($temp)),"REG_SZ",GUICtrlRead($Input)&"\1") $temp2=Read("MRUList") RegWrite($RunReg,"MRUList","REG_SZ",String(Chr($temp))&$temp2) CloseRunSystem() EndIf Case $CANCEL CloseRunSystem() Case $BROWSE $temp = FileOpenDialog ( "Browse", @HomeDrive, "Programs (*.exe)|All (*.*)", 3) If Not(@error) Then GUICtrlSetData($Input,$temp) EndIf Case $RunAdvancedWorkingDirectoryBrowse $temp = FileSelectFolder("Browse",@HomeDrive,7,@HomeDrive) If Not(@error) Then GUICtrlSetData($RunAdvancedWorkingDirectory,$temp) EndIf Case $ADVANCED $temp = WinGetPos("Run...") If $temp[3]<200 Then WinMove("Run...","",$temp[0],$temp[1],340,332) GUICtrlSetPos($ADVANCED, 340-24, 300-18) GUICtrlSetTip($ADVANCED,"Hide Advanced Options") Else WinMove("Run...","",$temp[0],$temp[1],340,182) GUICtrlSetPos($ADVANCED, 340-24, 150-18) GUICtrlSetTip($ADVANCED,"Show Advanced Options") EndIf Case $RunAdvancedParametersReset GUICtrlSetData($RunAdvancedParameters,"") Case $RunAdvancedWorkingDirectoryReset GUICtrlSetData($RunAdvancedWorkingDirectory,@HomeDrive) Case $RunAdvancedVerbReset GUICtrlDelete($RunAdvancedVerb) $RunAdvancedVerb = GUICtrlCreateCombo("open",36,72,200,21) GUICtrlSetData(-1,"edit|print|properties|explore") Case $RunAdvancedMaximizedReset GUICtrlDelete($RunAdvancedMaximized) $RunAdvancedMaximized = GUICtrlCreateCombo("Standard",36,72,200,21) GUICtrlSetData(-1,"Minimized|Maximized|Hide") Case $RunAdvancedWorkingDirectoryHelp MsgBox(64,"Help - Working Directory","All commands executed will origenate from this directory") Case $RunAdvancedMaximizedHelp MsgBox(64,"Help - Window State","When the target program opens, it will do so in this state") Case $RunAdvancedParametersHelp MsgBox(64,"Help - Parameters","You can place any command-line parameters here") Case $RunAdvancedVerbHelp MsgBox(64,"Help - Action","This is the action (see right-click menu on file) to do on the target") EndSwitch $RunParameters = GUICtrlRead($RunAdvancedParameters) $RunWorkingDir = GUICtrlRead($RunAdvancedWorkingDirectory) $RunVerb = GUICtrlRead($RunAdvancedVerb) $RunMaximized = StringState(GUICtrlRead($RunAdvancedMaximized)) EndFunc #EndRegion ; RunAs #Region ; Common Func CloseRunSystem() GUIDelete($RunGUI) $RunGUI = -100 EndFunc Func Read($key) Return RegRead($RunReg,$key) EndFunc Func StateString($state) Switch $state Case @SW_MAXIMIZE Return "Maximized" Case @SW_MINIMIZE Return "Minimized" Case @SW_HIDE Return "Hide" EndSwitch Return "Standard" EndFunc Func StringState($state) Switch $state Case "Maximized" Return @SW_MAXIMIZE Case "Minimized" Return @SW_MINIMIZE Case "Hide" Return @SW_HIDE EndSwitch Return @SW_RESTORE EndFunc Func Exclude($list,$item) Local $temp = StringSplit($list,"|") Local $temp2 = "" For $i = 1 To $temp[0] If Not($temp[$i]==$item) Then $temp2 = $temp2 & "|" & $temp[$i] EndIf Next Return StringTrimLeft($temp2,1) EndFunc #EndRegion ; Common _________[u]UDFs[/u]_________-Mouse UDF-Math UDF-Misc Constants-Uninstaller Shell
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