Jump to content

how to launch programs the run dialog style?

Recommended Posts


Hi all. I am creating an app that runs a program with the admin privileges using the shellexecute's run as verb, but what my problem is, that no matter what I use to launch the program, it doesn't quite work like the run dialog would (certain programs don't get found, etc.). I've tried using the explorer.exe and passing the program to it, that is unreliable and opens documents folder sometimes instead, I've tried using the @comspec /c and that works better, but still some of the programs aren't being found that would be with the run dialog e.g., if I do @comspec /c diskpart it won't find it, I've even tried setting the working dir, but still no luck. I also tried passing commandline params to C:\WINDOWS\system32\rundll32.exe shell32.dll,#61, but no luck. can anyone help me what way to go in order to be able to launch programs in the run dialog style? is there a function in winapi that run dialog uses that I could use as well? Or what would be the best way to go about this? Any help much appreciated.

Share this post

Link to post
Share on other sites

ShellExecute works just fine for things like DiskPart. Have you tried that on the other apps you're having trouble with?

√-1 2^3 ∑ π, and it was delicious!

Share this post

Link to post
Share on other sites

This used to work for me, but now i guess that windows 10 has something to do with it..

#include <Constants.au3>
Local $dif
Func ListLetter()
    ProgressOn('Diskpart', 'Working', '', 300, 300)
    ProgressSet(25, '', 'Working...')
    $DSK = Run('diskpart', '', @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD)
    ;$DSK = ShellExecute('diskpart', $STDIN_CHILD + $STDOUT_CHILD, '', '', @SW_HIDE)
    ConsoleWrite('$DSK - ' & @error & ' - ' & @MSEC & @CRLF)
    $begin = TimerInit()
        If $dif >= 3000 Then
            MsgBox(64, 'Params', 'Timeout')
        $dif = TimerDiff($begin)
        ProgressSet(35, '', 'Working...')
        $Read = StdoutRead($DSK, True, False)
        $Str = StringInStr($Read, 'DISKPART>')
    Until $Str <> 0
    ProgressSet(65, '', 'Working...')
    StdinWrite($DSK, "list volume" & @CRLF)
    $begin = TimerInit()
        If $dif >= 3000 Then
            MsgBox(64, 'Params', 'Timeout')
        $dif = TimerDiff($begin)
        $Read = StdoutRead($DSK, True, False)
        $Str1 = StringInStr($Read, 'DISKPART>', 0, 2)
    Until $Str1 <> 0
    ProgressSet(85, '', 'Working...')
    $Read = StdoutRead($DSK, True, False)
    MsgBox(4096, "Diskpart - List Volume", $Read)
EndFunc   ;==>ListLetter

Looks like diskpart is different from regular console.

Edited by careca


Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples


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

  • Similar Content

    • rkr
      By rkr
      Hi, I have a software which has a 'run file'-ie; when i double click on that file, the input file of the software is run by the software. I wish to double click/execute this run file using autoit. how do i achieve this. i opened the software and it shows the input file and run file in same folder, i will put my autoitscript file too in same location. how do i simulate double clicking the run file (using its file name, say - abc.run ). I entered the following lines to make software window active - it became active, dont know how to go forward
      Winactivate("program title")
      winwaitactivate("program title")
      controlclick("program title","abc.run",1000,"primary",2) ; 1000 is ctrl id
    • tremolux66
      By tremolux66
      Initial Problem
      I've written several scripts with the following sequence:
      Execute a program using Run w/stdout+stderr captured Typically processes all the files in one directory tree to populate a second tree Execute a second program (also with Run) to monitor the products of the first program and Display a progress bar (percentage of output files complete) Also monitor the first program's process and exit when it terminates The script then calls ProcessWaitClose (no timeout) on the first program's process and Checks the first program's results Kills the monitor program if it hasn't already exited on its own. Sometimes, ProcessWaitClose returns 1 with @error = 0 and @extended = 0xCCCCCCCC (actually, 0xFFFFFFFFCCCCCCCC), which seems ambiguous: the documentation says that @error = non-zero and @extended = 0xCC... means an invalid PID (unclear what the return value is), and 1 is returned for non-existent processes (but no mention of @extended). The 1/0/0xCC... result seems to occur when the first program exits very quickly (with or without an error). Since the exit value is not available, the script scans the program's output and tries to determine whether it ran successfully. This has gotten complicated and unreliable.
      Partial Fix
      I've now implemented a much simpler approach that works for most cases:
      Modify the monitor program so that it ignores the other program's process (the monitor always gets killed by the script anyway) Execute the monitor program first using Run, then execute the processing program with RunWait When RunWait returns, the child process exit value is available, so the script can ignore its output (which isn't available anyway) If the monitor program is still running, kill it. Remaining Issue
      However, there are still a couple of cases where it's necessary to get both the exit value from the processing program and its output. Since RunWait doesn't capture stdout and stderr for the parent script, it's looking like I'll have to call RunWait and redirect the 2 streams to a temp file and then scan it. Also, to do the redirect, I think I'll have to use @ComSpec to execute the processing program, which adds an undesired layer.
      Does anybody have a better (cleaner) way to handle these cases?
    • e45678mail
      By e45678mail
      I have some question about how to enable the test mode via "Run" or "shellexecute" of command,
      was to tried :
      Run("bcdedit.exe /-set testsinging on", "C:\Windows\System32")
      shellexecute("bcdedit.exe /-set testsinging on", "C:\Windows\System32")
      since this command must to run through administrator competence,
      have any method can accomplish it?
    • BlazerV60
      By BlazerV60
      Hello all,
      I've written the code below which launches chrome in incognito mode and then proceeds to go to the autoit website.
      From my understanding, the Run() command is also supposed to output the PID number related to the application that got launched from the Run command.
      However when I run the below lines, it outputs a PID number that is different from the newly launched chrome browser's PID number, does anyone know why and possibly explain how I could retrieve the accurate PID number associated with the newly launched browser?
      Global $iPid = Run(@ComSpec & ' /c start chrome.exe https://www.autoitscript.com/forum/ -incognito' ,"", "") msgbox(0,"",$iPid) Thank you,
    • rootx
      By rootx
      I need help to understand why the run function does not work, but if i use it directly inside cmd shell the command works. $where is the name of the jpg file
      ShellExecute(@ComSpec ," /k C:\Users\root\Desktop\test\exiftool.exe -p $FileName "&'"'&$where&'"'&" > "&'"'&@ScriptDir&"\out.txt"&'"',@ScriptDir);<----- work Run("C:\Users\root\Desktop\test\exiftool.exe -p $FileName "&$where&" > "&@ScriptDir&"\out.txt",@ScriptDir);<--- doesn't work I would use the run command!

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.