Quip Posted September 5, 2010 Share Posted September 5, 2010 Hi first of all i'd like to know if windows uses an certain dll for the "Run" window (win+R). If so is it possible to intergrate that dll into my script? Well the whole point of my program is to create an easy to update GUI to make certain tasks quicker for example: open a file, go to a certain url, open a directory etc etc. The issues i have now is. If $data[$x][0] is an exe nothing happends or i get an acces violation popup. if $data[$x][0] contains a folder path for example c:\program files (x86)\ i get an popup saying "C:\program is not accessible" and "acces denied". It seems like the command has an issue with paths with spaces. The run code: ; Loop to see if the user leftclicks or rightclicks a button For $x = 0 To 14 ; either runs the path with auto it or by CMD 'start' If $iMsg[0] = $ahIcons[$x] Then If Not $data[$x][0] = "" Then if StringInStr($data[$x][0], ".exe") > 0 Then Run($data[$x][0]) Else _RunDOS("start " & $data[$x][0]) EndIf EndIf EndIf ; Opens the settingswindow with settings for rightclicked button If $a[3] = 1 And $a[4] = $ahIcons[$x] Then $edit = $x ;$b = WinGetPos("Qcut") ;WinMove("Qcut - Settings","",$b[0],$b[1]) GUISetState(@SW_SHOW, $sGui) GUICtrlSetData($Inp_name, $data[$x][3]) GUICtrlSetData($Inp_Path, $data[$x][0]) GUICtrlSetData($Inp_IconPath, $data[$x][1]) GUICtrlSetData($Inp_IconNr, $data[$x][2]) GUICtrlSetImage($Btn_Pre, $data[$x][1], $data[$x][2]) EndIf Next WEnd EndFunc ;==>_Main Whole code below: expandcollapse popup#include <Constants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <StaticConstants.au3> #include <EditConstants.au3> #include <Array.au3> #include <Process.au3> HotKeySet("+!d", "_hotkey") Opt('MustDeclareVars', 1) Opt("TrayMenuMode", 1) Opt("SendKeyDelay", 0) ; Setting global variables Global $hGui, $sGui, $hToggle = 1 _Main() Func _Main() ; Setting Local variables Local $ahIcons[15], $data[15][4] Local $hFile, $hFileSel, $hNext, $x, $iCntHeight, $exititem, $temparray Local $iMsg, $sCurFilename, $sTmpFile, $settingsitem, $aboutitem, $a, $b Local $edit, $Inp_IconNr, $Inp_IconPath, $Inp_name, $Inp_Path, $Dial_iconpath, $Dial_path Local $Btn_cancel, $Btn_ok, $Btn_Pre, $iCntRow, $iCntCol, $iCurIndex = 1, $menu Local $hFilename = @SystemDir & "\shell32.dll"; Default file Local $Ini = @ScriptDir & "\settings.ini"; Path to settings ini ; Loop to create an 2dimensional array with all buttondata For $x = 0 To 14 $data[$x][0] = IniRead($Ini, "Button" & $x, "path", "") $data[$x][1] = IniRead($Ini, "Button" & $x, "iconpath", "") $data[$x][2] = IniRead($Ini, "Button" & $x, "iconNr", "") $data[$x][3] = IniRead($Ini, "Button" & $x, "Name", "") If $data[$x][1] = "" Then $data[$x][1] = $hFilename If $data[$x][2] = "" Then $data[$x][2] = "240" Next ; Creating Tray menu $exititem = TrayCreateItem("Exit") ; Creating mainGui $hGui = GUICreate("Qcut", 200, $iCntHeight + 120, @DesktopWidth / 2 - 192, _ @DesktopHeight / 2 - 235, -1) ; Buttonloop For $iCntRow = 0 To 2 For $iCntCol = 0 To 4 $iCurIndex = $iCntRow * 5 + $iCntCol $ahIcons[$iCurIndex] = GUICtrlCreateButton("", 40 * $iCntCol, 40 * $iCntRow, 40, 40, $BS_ICON) GUICtrlSetImage(-1, $data[$iCurIndex][1], $data[$iCurIndex][2]) GUICtrlSetTip(-1,$data[$iCurIndex][3]) Next Next ; Settings gui $sGui = GUICreate("Qcut - Settings", 255, 212, 400, 307, -1, -1, $hGui) $Inp_name = GUICtrlCreateInput("", 8, 25, 178, 21) GUICtrlCreateLabel("Name:", 8, 8, 35, 17) $Inp_IconNr = GUICtrlCreateInput("", 8, 65, 178, 21) GUICtrlCreateLabel("Icon Nr:", 8, 48, 42, 17) $Inp_Path = GUICtrlCreateInput("", 8, 105, 178, 21) GUICtrlCreateLabel("Path:", 8, 88, 29, 17) $Inp_IconPath = GUICtrlCreateInput("", 8, 145, 178, 21) GUICtrlCreateLabel("Icon Path;", 8, 128, 53, 17) $Btn_ok = GUICtrlCreateButton("Ok", 8, 176, 89, 25, $WS_GROUP) $Btn_cancel = GUICtrlCreateButton("Cancel", 96, 176, 89, 25, $WS_GROUP) $Dial_path = GUICtrlCreateButton("...", 192, 104, 25, 21, $WS_GROUP) $Dial_iconpath = GUICtrlCreateButton("...", 192, 144, 25, 21, $WS_GROUP) $Btn_Pre = GUICtrlCreateButton("", 208, 25, 40, 40, $BS_ICON) GUICtrlCreateLabel("Preview:", 207, 8, 45, 17) GUISetState(@SW_HIDE, $sGui) GUISwitch($hGui) GUISetState(@SW_SHOW) GUISetState() While 1 ; All different variables for user-message handling $iMsg = GUIGetMsg(1) $a = GUIGetCursorInfo($hGui) _ArrayAdd($iMsg, TrayGetMsg()) ; Main "Select" statement that handles other events Select Case $iMsg[0] = $Dial_path $sTmpFile = FileOpenDialog("Select file:", "c:/", "All (*.*)") If @error Then ContinueLoop GUICtrlSetData($Inp_Path, $sTmpFile) If StringInStr($sTmpFile, ".exe") > 0 Then GUICtrlSetData($Inp_IconNr, "0") GUICtrlSetData($Inp_IconPath, $sTmpFile) GUICtrlSetImage($Btn_Pre, $sTmpFile, "0") $temparray = StringSplit($sTmpFile, "\") GUICtrlSetData($Inp_name, _ArrayPop($temparray)) EndIf Case $iMsg[0] = $Dial_iconpath $sTmpFile = FileOpenDialog("Select file:", "c:/", "Icon files (*.dll;*.exe)") If @error Then ContinueLoop GUICtrlSetData($Inp_IconPath, $sTmpFile) GUICtrlSetData($Inp_IconNr, "0") Case $iMsg[0] = $Btn_ok ; Updates the $data array with changed data and then writes it to the ini, ; and updates to new icon image ;If GUICtrlRead($Inp_Path) <> $data[$edit][0] Or GUICtrlRead($Inp_IconPath) <> $data[$edit][1] Or GUICtrlRead($Inp_IconNr) <> $data[$edit][2] Or GUICtrlRead($Inp_name) <> $data[$edit][3] Then If GUICtrlRead($Inp_IconNr) = "" Then GUICtrlSetData($Inp_IconNr, "240") If GUICtrlRead($Inp_IconPath) = "" Then GUICtrlSetData($Inp_IconPath,$hFilename) $data[$edit][0] = GUICtrlRead($Inp_Path) $data[$edit][1] = GUICtrlRead($Inp_IconPath) $data[$edit][2] = GUICtrlRead($Inp_IconNr) $data[$edit][3] = GUICtrlRead($Inp_name) IniWrite($Ini, "Button" & $edit, "path", $data[$edit][0]) IniWrite($Ini, "Button" & $edit, "iconpath", $data[$edit][1]) IniWrite($Ini, "Button" & $edit, "iconNr", $data[$edit][2]) IniWrite($Ini, "Button" & $edit, "name", $data[$edit][3]) GUISetState(@SW_HIDE, $sGui) GUICtrlSetImage($ahIcons[$edit], $data[$edit][1], $data[$edit][2]) GUICtrlSetTip($ahIcons[$edit], $data[$edit][3]) ;EndIf Case $iMsg[0] = $Btn_cancel GUISetState(@SW_HIDE, $sGui) Case $iMsg[0] = $Btn_Pre ; If user clicks preview button the Icon image changes to the current settings GUICtrlSetImage($Btn_Pre, GUICtrlRead($Inp_IconPath), GUICtrlRead($Inp_IconNr)) Case $iMsg[5] = $exititem Exit Case $iMsg[0] = $GUI_EVENT_CLOSE And $iMsg[1] = $hGui Exit Case $iMsg[0] = $GUI_EVENT_CLOSE And $iMsg[1] = $sGui GUISetState(@SW_HIDE, $sGui) EndSelect ; Loop to see if the user leftclicks or rightclicks a button For $x = 0 To 14 ; either runs the path with auto it or by CMD 'start' If $iMsg[0] = $ahIcons[$x] Then If Not $data[$x][0] = "" Then if StringInStr($data[$x][0], ".exe") > 0 Then Run($data[$x][0]) Else _RunDOS("start " & $data[$x][0]) EndIf EndIf EndIf ; Opens the settingswindow with settings for rightclicked button If $a[3] = 1 And $a[4] = $ahIcons[$x] Then $edit = $x ;$b = WinGetPos("Qcut") ;WinMove("Qcut - Settings","",$b[0],$b[1]) GUISetState(@SW_SHOW, $sGui) GUICtrlSetData($Inp_name, $data[$x][3]) GUICtrlSetData($Inp_Path, $data[$x][0]) GUICtrlSetData($Inp_IconPath, $data[$x][1]) GUICtrlSetData($Inp_IconNr, $data[$x][2]) GUICtrlSetImage($Btn_Pre, $data[$x][1], $data[$x][2]) EndIf Next WEnd EndFunc ;==>_Main ; Simple function for showing/hiding the program Func _hotkey() If $hToggle = 1 Then $hToggle = 0 GUISetState(@SW_HIDE, $hGui) GUISetState(@SW_HIDE, $sGui) Else $hToggle = 1 GUISwitch($hGui) GUISetState(@SW_SHOW, $hGui) EndIf EndFunc ;==>_hotkey Current ini file: expandcollapse popup[Button0] path=C:\Program Files (x86)\Codemasters\DiRT2\dirt2.exe iconpath=C:\Program Files (x86)\Codemasters\DiRT2\dirt2_game.exe iconNr=0 name=dirt2.exe [Button1] path=C:\Windows\notepad.exe iconpath=C:\Windows\notepad.exe iconNr=0 name=notepad.exe [Button2] path=C:\Program Files (x86)\mIRC\mirc.exe iconpath=C:\Program Files (x86)\mIRC\mirc.exe iconNr=0 name=mirc.exe [Button3] path=C:\Users\QuiP\Desktop\Qcut.exe iconpath=C:\Users\QuiP\Desktop\Qcut.exe iconNr=0 name=Qcut.exe [Button4] path= iconpath=C:\Windows\system32\shell32.dll iconNr=240 name=4 [Button5] path= iconpath=C:\Windows\system32\shell32.dll iconNr=240 name=5 [Button6] path= iconpath=C:\Windows\system32\shell32.dll iconNr=240 name=6 [Button7] path= iconpath=C:\Windows\system32\shell32.dll iconNr=240 name=7 [Button8] path= iconpath=C:\Windows\system32\shell32.dll iconNr=240 name=8 [Button9] path= iconpath=C:\Windows\system32\shell32.dll iconNr=240 name=9 [Button10] path= iconpath=C:\Windows\system32\shell32.dll iconNr=240 name=10 [Button11] path= iconpath=C:\Windows\system32\shell32.dll iconNr=240 name=11 [Button12] path=c:\program files (x86)\ iconpath=C:\Windows\system32\shell32.dll iconNr=5 name=Autoit - examples [Button13] path=C:\Users\QuiP\Desktop\test.txt iconpath=C:\Windows\system32\shell32.dll iconNr=152 name=test.txt [Button14] path=D:\shaere iconpath=C:\Windows\system32\shell32.dll iconNr=5 name=Shaere Thanks alot for any help! YES! Link to comment Share on other sites More sharing options...
Tvern Posted September 5, 2010 Share Posted September 5, 2010 It's running perfectly for me and I actually realy like it. I have a few idea's that might help: You can use #Requireadmin to solve permission issues. _RunDos will block your program untill it returns (usually when the application is closed) instead you could use "Run(@ComSpec & " /C start " & $data[$x][0], "", @SW_HIDE)" ShellExecute might be usefull if you want to be able to link files and it gives you an alternative for Run, which might help with your issues. An input for parameters would be a nice addition. (You could also add them after the path, bit I think it would be nice.) Link to comment Share on other sites More sharing options...
Quip Posted September 5, 2010 Author Share Posted September 5, 2010 (edited) Im glad that you liked it, and i will try those tips you gave me. Edited September 5, 2010 by Quip Link to comment Share on other sites More sharing options...
Ascend4nt Posted September 6, 2010 Share Posted September 6, 2010 any DOS command that refers to a file or folder with spaces should be surrounded by double quotations. (like 'dir "C:\Program Files\Common Files"'). In some cases you can get away without doing it, but its good practice to always use double quotes to surround files and folder names. My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
legoman1 Posted September 6, 2010 Share Posted September 6, 2010 the run window in windows is just ShellExecutejust use that and it will solve your problemit will automatically decide what program to use.you can put a link, program, folder, it all works.legoman Link to comment Share on other sites More sharing options...
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