Method run.it
Overload
Runs/opens a program, document, directory (folder), URL, new email, etc.
public static RResult it(string file, string args = null, RFlags flags = 0, ROptions dirEtc = null)
Parameters
file (string)
Examples:
|
args (string)
Command line arguments.
This function expands environment variables if starts with |
flags (RFlags) |
dirEtc (ROptions)
Allows to specify more parameters: current directory, verb, etc.
If string, it sets initial current directory for the new process. If |
Returns
RResult
Process info (id etc). |
Exceptions
ArgumentException
Used both ROptions.Verb and RFlags.Admin and this process isn't admin. |
AuException
Failed. For example, the file does not exist. |
Remarks
It works like when you double-click a file icon. It may start new process or not. For example it may just activate window if the program is already running. Uses API ShellExecuteEx. Similar to System.Diagnostics.Process.Start.
The file parameter can be:
- Full path of a file or directory. Examples:
@"C:\file.txt"
,folders.Documents
,folders.System + "notepad.exe"
,@"%folders.System%\notepad.exe"
. - Filename of a file or directory, like
"notepad.exe"
. The function calls filesystem.searchPath. - Path relative to folders.ThisApp. Examples:
"x.exe"
,@"subfolder\x.exe"
,@".\subfolder\x.exe"
,@"..\another folder\x.exe"
. - URL. Examples:
"https://www.example.com"
,"file:///path"
. - Email, like
"mailto:[email protected]"
. Subject, body etc also can be specified, and Google knows how. - Shell object's ITEMIDLIST like
":: ITEMIDLIST"
. See Pidl.ToHexString, folders.shell. Can be used to open virtual folders and items like Control Panel. - Shell object's parsing name, like
@"shell:::{CLSID}"
or@"::{CLSID}"
. See Pidl.ToShellString. Can be used to open virtual folders and items like Control Panel. - To run a Windows Store App, use
@"shell:AppsFolder\WinStoreAppId"
format. Example:@"shell:AppsFolder\Microsoft.WindowsCalculator_8wekyb3d8bbwe!App"
. To discover the string use hotkeyCtrl+Shift+Q
or function WndUtil.GetWindowsStoreAppId or Google. - To open a Windows Settings page can be used ms-settings, like
"ms-settings:display"
. To open Settings use"ms-settings:"
.
Supports environment variables, like @"%TMP%\file.txt"
. See pathname.expand.
By default the new process does not inherit administrator privileges of this process. More info: RFlags.
Examples
Run Notepad and wait for an active Notepad window.
run.it("notepad.exe");
1.s();
wnd w = wnd.wait(10, true, "*- Notepad", "Notepad");
Run Notepad or activate a Notepad window.
wnd w = wnd.findOrRun("*- Notepad", run: () => run.it("notepad.exe"));
Run File Explorer and wait for new folder window. Ignores matching windows that already existed.
var w = wnd.runAndFind(
() => run.it(@"explorer.exe"),
10, cn: "CabinetWClass");