When developing the Windows Sidebar tool, you want to provide the same features as windows, basically the following two features:
1. You can directly run the system path environment variable to listProgram
2. You can directly run the UNC address, URL, and FTP address to support common network protocol access methods.
In fact, the existing functions in the gadget development API support this function, but I started to choose the wrong one. What I started to use is
VaR winshell = new activexobject ("Shell. Application ");
Winshell. ShellExecute ("\" "+ q + "\"");
Winshell = NULL;
We found that the token can only run the program, but does not support the token transfer. Fortunately, we have found a replacement product, system.shell.exe cute (apppath, null, null, open );
The function prototype is defined:
Execute Method
Launches an application.
Syntax
System. Shell. Execute (Strfile[,Strargs][,Strdir][,Stroperation])
Parameters
Strfile |
Required.StringThat specifies a Universal Naming Convention (UNC) path to an executable file, a filename, or a URL. |
Strargs |
Optional. IfStrfileSpecifies an executable file thenStringSpecifies the parameters to be passed to the application. For example, a UNC path suchSystem. Gadget. Path + "\ myfile. txt" . NoteIfStrfileSpecifies a filename or URL,StrargsIs unneccessary and shoshould be blank, null, or an empty string. |
Strdir |
Optional.StringThat specifies the UNC path for the default (working) Directory of the executable file. |
Stroperation |
optional. string that specifies the action (or Microsoft Windows Shell verb) to be performed med. the set of available verbs depends on the particle file or folder.
-
edit
-
Opens the file specified
strargs for editing.
-
example E
-
Opens the folder specified
strdir for sorting.
-
Find
-
Opens the folder specified
strdir for searching.
-
open
-
Opens the file specified
strargs .
-
Print
-
Prints the file specified
strargs on the default printer.
|
Return Value
No return value.
Remarks
Supplying a path to a filename (with extension) or a URLStrfileWill launch the Default Application associated with that file extension and load the filename specified.
NoteAlternatively, a path to a known application. EXE can by supplied
StrfileWhile
Strargs,
Strdir, And
StroperationAre used to specify the rest of the file information.
Strargs,Strdir, AndStroperationCan be assigned values in combination as required.
UNC paths shocould escape special characters with '\'.
System.shell.exe cute the first parameter is the application path, the second parameter is the parameter list, the third parameter is the application working directory, and the fourth parameter is the open mode.
To use this function to implement the running bar function, you also need to do a command line parsing job. Because the Gadget function works on the page, regular Expressions are required for parsing in JavaScript to identify the Application Path and parameter list,CodeAs follows:
Function retapp (STR, retpart ){
VaR S = STR;
VaR Re = new Regexp ("[\ f \ n \ r \ t \ v] * (\". + \ ") | ([^ \ f \ n \ r \ t \ v] +)", "ig ");
VaR arr = re.exe C (s );
If (retpart = 0 ){
Return (Regexp. lastmatch );
} Else {
Return (Regexp. rightcontext );
}
Return ("");
}
System.shell.exe cute (retapp (Q, 0), retapp (Q, 1), null, open );
Now that the command line Parsing is available and the execution command is available, you can receive input formats like command.exe ARGs, the regular expression uses the first boundary string as the end position of the command or program path, and the subsequent string as the command parameter.