1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
| program execute;
const
MAX_PATH = 260;
SW_SHOWNORMAL = 1;
Caption = 'Execute';
Msg = 'The command-line tool Execute starts a program or opens a file with its associated program.'#13#13 +
'Usage:'#13 +
' execute <filename> [<parameters>]'#13#13 +
'If <filename> doesn''t include a path, Execute first searches for it in the current folder and then in the Windows search path.'#13 +
'Filenames and parameters that contain spaces should be enclosed in double quotes (").'#13#13#13 +
'Example:'#9#9#9#9#9'Meaning:'#13 +
' execute C:\WINDOWS\NOTEPAD.EXE'#9#9' Start Notepad in the folder C:\WINDOWS.'#13 +
' execute notepad'#9#9#9#9' Start Notepad (find it in the current folder or the search path).'#13 +
' execute SomeText.txt'#9#9#9' Open the file SomeText.txt with its associated program.'#13 +
' execute "C:\some name with spaces.txt"'#9' Open the file C:\some name with spaces.txt with its associated program.'#13 +
' execute notepad SomeText.txt'#9#9' Open the file SomeText.txt (in the current folder) with Notepad.'#13 +
' execute notepad /p SomeText.txt'#9#9' Print the file SomeText.txt with Notepad.';
function ShellExecute(hWnd: Integer; Operation, FileName, Parameters,
Directory: PChar; ShowCmd: Integer): Integer; stdcall;
external 'shell32.dll' name 'ShellExecuteA';
function MessageBoxA(hWnd: Integer; lpText, lpCaption: PAnsiChar;
uType: LongWord): Integer; stdcall; external 'user32.dll' name 'MessageBoxA';
function GetFullPathName(lpFileName: PChar; nBufferLength: LongWord;
lpBuffer: PChar; var lpFilePart: PChar): LongWord; stdcall;
external 'kernel32.dll' name 'GetFullPathNameA';
function StrLCopy(Dest: PChar; const Source: PChar; MaxLen: Cardinal): PChar;
assembler;
asm
PUSH EDI
PUSH ESI
PUSH EBX
MOV ESI,EAX
MOV EDI,EDX
MOV EBX,ECX
XOR AL,AL
TEST ECX,ECX
JZ @@1
REPNE SCASB
JNE @@1
INC ECX
@@1: SUB EBX,ECX
MOV EDI,ESI
MOV ESI,EDX
MOV EDX,EDI
MOV ECX,EBX
SHR ECX,2
REP MOVSD
MOV ECX,EBX
AND ECX,3
REP MOVSB
STOSB
MOV EAX,EDX
POP EBX
POP ESI
POP EDI
end;
function StrPCopy(Dest: PChar; const Source: string): PChar;
begin
Result := StrLCopy(Dest, PChar(Source), Length(Source));
end;
function ExpandFileName(const FileName: string): string;
var
FName: PChar;
Buffer: array[0..MAX_PATH - 1] of Char;
begin
SetString(Result, Buffer, GetFullPathName(PChar(FileName), SizeOf(Buffer),
Buffer, FName));
end;
function ExecuteFile(FileName, Params, DefaultDir: string;
ShowCmd: Integer): Integer;
var
zFileName, zParams, zDir: array[0..MAX_PATH -1] of Char;
begin
Result := ShellExecute(0, nil, StrPCopy(zFileName, FileName),
StrPCopy(zParams, Params), StrPCopy(zDir, DefaultDir), ShowCmd);
end;
function MessageBox(const Text, Caption: string; const Flags: Longint): Integer;
begin
Result := MessageBoxA(0, PChar(Text), PChar(Caption), Flags);
end;
var
CommandLine: string;
begin
try
if (ParamCount = 0) or (ParamStr(1) = '/?') then
MessageBox(Msg, Caption, 0)
else
begin
CommandLine := CmdLine;
Delete(CommandLine, 1, Length(ParamStr(0)) +1);
if (Length(CommandLine) > 1) and (CommandLine[1] = '"') then
Delete(CommandLine, 1, 2);
Delete(CommandLine, 1, Length(ParamStr(1)) +1);
if (Length(CommandLine) > 1) and (CommandLine[1] = '"') then
Delete(CommandLine, 1, 2);
ExecuteFile(ParamStr(1), CommandLine, '', SW_SHOWNORMAL);
end;
except
end;
end. |