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
|
uses
SysUtils;
function TryGetQuotedFileName(const aCommandLine: string; out aFileName, aParameter: string): boolean;
var
vQuotePos, vOtherQuotePos: integer;
begin
result := FALSE;
vQuotePos := 1;
while (vQuotePos <= Length(aCommandLine)) and (Copy(aCommandLine, vQuotePos, 1) <> '"') do
Inc(vQuotePos);
if vQuotePos > Length(aCommandLine) then
exit;
vOtherQuotePos := Succ(vQuotePos);
while (vOtherQuotePos <= Length(aCommandLine)) and (Copy(aCommandLine, vOtherQuotePos, 1) <> '"') do
Inc(vOtherQuotePos);
if vOtherQuotePos > Length(aCommandLine) then
exit;
result := TRUE;
aFileName := Copy(aCommandLine, vQuotePos, Succ(vOtherQuotePos - vQuotePos));
aParameter := Copy(aCommandLine, vOtherQuotePos + 2);
end;
function TryGetCommandLineFileName(const aCommandLine: string; out aFileName, aParameter: string): boolean;
var
vFileName, vParameter: string;
vSpacePos: integer;
begin
if UpperCase(RightStr(aCommandLine, 4)) = '.EXE' then
begin
result := TRUE;
aFileName := aCommandLine;
aParameter := '';
end else
if (Copy(aCommandLine, 1, 1) = '"') and TryGetQuotedFileName(aCommandLine, vFileName, vParameter) then
begin
result := TRUE;
aFileName := vFileName;
aParameter := vParameter;
end else
result := FALSE;
vSpacePos := 1;
while (vSpacePos <= Length(aCommandLine)) and not result do
begin
if Copy(aCommandLine, vSpacePos, 1) = ' ' then
begin
vFileName := Copy(aCommandLine, 1, Pred(vSpacePos));
if UpperCase(RightStr(vFileName, 4)) = '.EXE' then
begin
result := TRUE;
aFileName := vFileName;
aParameter := Copy(aCommandLine, Succ(vSpacePos));
end else
if Length(ExeSearch(Concat(vFileName, '.exe'), GetEnvironmentVariable('PATH'))) > 0 then
begin
result := TRUE;
aFileName := vFileName;
aParameter := Copy(aCommandLine, Length(vFileName) + 2);
end;
end;
Inc(vSpacePos);
end;
end;
const
EXEMPLES: array[1..10] of string = (
'"C:\Windows\SysWOW64\RunDll32.EXE" "C:\Program Files\NVIDIA Corporation\Installer2\InstallerCore\NVI2.DLL",UninstallPackage Display.Update',
'C:\Program Files (x86)\DYMO\DYMO Label Software\Uninstall DYMO Label.exe',
'MsiExec.exe /X{908DB568-E5FA-40C7-A2AA-AB340190858B}',
'RunDll32 C:\Program Files (x86)\COMMON~1\INSTAL~1\PROFES~1\RunTime\11\50\Intel32\ctor.dll,LaunchSetup "C:\Program Files (x86)\InstallShield Installation Information\{40989F6C-18D8-4EE1-9B79-3D6FD2893EE9}\setup.exe" -l0x40c UNINSTALL -removeonly',
'c:\Program Files (x86)\Common Files\Adobe AIR\Versions\1.0\Resources\Adobe AIR Updater.exe -arp:uninstall',
'Uninstall DYMO Label.exe',
'MsiExec.exe /X{908DB568-E5FA-40C7-A2AA-AB340190858B}',
'msiexec /X{908DB568-E5FA-40C7-A2AA-AB340190858B}',
'Adobe AIR Updater.exe -arp:uninstall',
'RunDll32 C:\Program Files (x86)\COMMON~1\INSTAL~1\PROFES~1\RunTime\11\50\Intel32\ctor.dll,LaunchSetup "C:\Program Files (x86)\InstallShield Installation Information\{40989F6C-18D8-4EE1-9B79-3D6FD2893EE9}\setup.exe" -l0x40c UNINSTALL -removeonly'
);
var
vFileName, vParameter: string;
vIndex: integer;
begin
for vIndex := Low(EXEMPLES) to High(EXEMPLES) do
if TryGetCommandLineFileName(EXEMPLES[vIndex], vFileName, vParameter) then
WriteLn(
'Exemple : ', EXEMPLES[vIndex], #13#10,
'Nom de fichier : ', vFileName, #13#10,
'Paramètre : ', vParameter
);
end. |