Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Система";
Текущий архив: 2003.02.06;
Скачать: [xml.tar.bz2];

Вниз

Как получить параметры , с поторыми был запущен процесс?   Найти похожие ветки 

 
Vlad-sh   (2002-11-29 12:31) [0]

Подскажите, как получить параметры, с поторыми был запущен процесс, т.е. я запустил "notepad.exe primer.txt", и в списке процессов висит notepad.exe и показывает мне primer.txt. Далее зная дискриптор этого процесса я могу получить его полный путь, имя модуля и т.д. (при помощи psapi.dll), но как мне получить параметр с которым процесс был запущен (в данном примере primer.txt)?

Все облазил, не могу это найти. Помогите плиз.

Заранее спасибо.


 
Victor_Cr   (2002-11-29 14:25) [1]

Для чужего приложения - скорее всего никак, т.к. то что Блокнот висит в памяти с запущеным primer.txt это не означает что этот файл был запущен из командной строки или с помощью передачи параметра.

Для своего приложения:

function ParamStr(Index: Integer): string;

Description

ParamStr returns the parameter from the command line that corresponds to Index, or an empty string if Index is greater than ParamCount. For example, an Index value of 2 returns the second command-line parameter.

ParamStr(0) returns the path and file name of the executing program (for example, C:\TEST\MYPROG.EXE).

Note: Use double quotes to wrap multiple words as one parameter (such as long file names containing spaces)


 
Yegor Derevenets   (2002-11-29 14:26) [2]

Почитать память у блокнота... :-)


 
Dm9   (2002-11-29 20:36) [3]

ParamStr (x : Integer) : String; - возвращает параметр с номером x. Параметры разделяются пробелами.
ParamCount : Integer; - количество переданных параметров.
ParamStr (0) - возвращает путь к твоей программе + имя файла:
если запущена программа E:\Langs\BP\Progs\1.exe, то
ParamStr (0) = "E:\Langs\BP\Progs\1.exe";


 
Ученик   (2002-11-29 21:27) [4]

Вариант от paul_shmakov ©, портированный в Delphi

function AdjustDebugPriviliges : Bool;
var
hTok : THandle;
tp : TTokenPrivileges;
begin
Result := False;
if OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES, hTok) then try
if LookupPrivilegeValue(nil, "SeDebugPrivilege", tp.Privileges[0].Luid) then begin
tp.PrivilegeCount := 1;
tp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
Result := AdjustTokenPrivileges(hTok, False, tp, 0, PTokenPrivileges(nil)^, PDWord(nil)^)
end
finally
CloseHandle(hTok)
end
end;

function GetProcessCommandLine(dwProcessID : DWord; szBuffer : PChar; cbBuffer : DWORD) : Bool;
var
hProcess, hThread : THandle;
pGetCommandLine : Pointer;
pCommandLine : PChar;
dwRead, dwTID : DWord;
begin
Result := FALSE;
hProcess := OpenProcess(PROCESS_CREATE_THREAD or PROCESS_VM_READ or PROCESS_VM_OPERATION,
FALSE, dwProcessID);
if (hProcess <> 0) then try
pGetCommandLine := GetProcAddress(GetModuleHandle("kernel32.dll"), "GetCommandLineA");
if (pGetCommandLine <> nil) then begin
hThread := CreateRemoteThread(hProcess, NIL, 0, pGetCommandLine, nil, 0, dwTID);
if (hThread <> 0) then try
if WAIT_OBJECT_0 = WaitForSingleObject(hThread, 10000) then begin
if GetExitCodeThread(hThread, PDWord(@pCommandLine)^) then begin
if ReadProcessMemory(hProcess, pCommandLine, szBuffer, cbBuffer, dwRead) then begin
szBuffer[dwRead] := #0;
Result := TRUE
end
end
end
finally
CloseHandle(hThread)
end
end
finally
CloseHandle(hProcess)
end
end;

procedure TForm1.Button1Click(Sender: TObject);
var
szBuffer : array[0..255] of Char;
begin
AdjustDebugPriviliges;
if GetProcessCommandLine(StrToInt(Edit1.Text), szBuffer, 255) then
ShowMessage(szBuffer)
end;


 
Vlad-sh   (2002-12-02 06:59) [5]

Victor_Cr
Dm9


Для своего приложения это элементарно (в хелпе написано, как вы заметили :))

Ученик

То, что нужно, спасибо.

Вот только когда запускаетя что-то под ДОС (ntvdm.exe), то не видно, какая досовская программа и откуда запустилась, т.е. в строке параметров стоит что-то типа "-f -i2" а не путь с ехе. Как бы определить этот путь с ехе-ком для досовских прог?



 
Ученик   (2002-12-02 21:51) [6]

>Vlad-sh © (02.12.02 06:59)
Как вариант, из заголовка окна



Страницы: 1 вся ветка

Форум: "Система";
Текущий архив: 2003.02.06;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.46 MB
Время: 0.01 c
1-15607
Ihtiandr
2003-01-29 11:18
2003.02.06
Combobox


14-15931
Mr.X
2003-01-18 19:16
2003.02.06
SMS -> ICQ


8-15763
malkolinge
2002-09-28 18:34
2003.02.06
Распознавание речи


7-15943
Walker
2002-11-27 07:00
2003.02.06
Отключить экранную заставку


1-15592
swinole
2003-01-29 04:44
2003.02.06
Dll





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский