2017-06-01 72 views
1

美好的一天!我一直試圖列出所有當前正在運行的應用程序,並使用masm將其寫入文本文件。我是新的程序集,但使用MSDN作爲我的參考。到目前爲止,我知道如何使用CreateFile,WriteFile,ReadFile等,但我沒有得到Process32First的工作方式。列出所有正在運行的應用程序MASM32程序集

我試圖將此鏈接中的代碼轉換爲MASM,(https://msdn.microsoft.com/en-us/library/windows/desktop/ms686701(v=vs.85).aspx),但沒有運氣,我無法獲得任何輸出。

我會很感激任何幫助!謝謝!祝你今天愉快。

include \masm32\include\masm32rt.inc 

.data 
    pe32 PROCESSENTRY32 <> 
    errorCreateTool db "ERROR: CreateToolhelp32Snapshot", 0 
    errorPF db "ERROR: Process32First", 0 
    errorOP db "ERROR: OpenProcess", 0 

    yesMsg db "proceed", 0 

.data? 
    dwPriorityClass dd ? 
    hProcessSnap HANDLE ? 
    hProcess HANDLE ? 

.code 

_start: 

    push 0 
    push TH32CS_SNAPPROCESS 
    call CreateToolhelp32Snapshot 

    mov hProcessSnap, eax 

    cmp hProcessSnap, INVALID_HANDLE_VALUE 
    je _errorCT 

    mov pe32.dwSize, sizeof PROCESSENTRY32 

    push offset pe32 
    push hProcessSnap 
    call Process32FirstW 

    cmp eax, ERROR_NO_MORE_FILES 
    je _errorPF 

    push offset pe32.szExeFile 
    call StdOut 

    mov dwPriorityClass, 0 

    push offset pe32.th32ProcessID 
    push FALSE 
    push PROCESS_ALL_ACCESS 
    call OpenProcess 

    cmp eax, 00H      ;if I comment this out, the code will proceed 
    je _errorOpen 

    push offset pe32.th32ProcessID  ;but this doesn't have any value and doesn't print out 
    call StdOut 
    push offset yesMsg     ;while this prints out on the console 
    call StdOut 

    jmp _done 

_errorOpen: 
    push offset errorOP 
    call StdOut 
    jmp _done 

_errorPF: 
    push offset errorPF 
    call StdOut 
    jmp _done 

_errorCT: 
    push offset errorCreateTool 
    call StdOut 

_done:  
    push 0 
    call ExitProcess 

end _start 
+0

'StdOut'打印零終止的_strings_。 'pe32.th32ProcessID'不是一個字符串。 (順便說一句,你確定你想要的Process32First的unicode版本?) – Michael

+0

嗨邁克爾!感謝您的評論。我只是意識到我不需要獲取th32ProcessID。我所需要的只是exe文件名,現在正在工作。我所做的只是將Process32FirstW更改爲Process32First,將Process32NextW更改爲kernel32.inc和kernel32p.inc中的Process32Next。謝謝你的線索! :) – fortress

回答

0

我已經體驗過使用該功能。我所要做的就是按照您的建議升級我的kernel32.inc和kernel32p.inc。做完這些事情之後,我在masm32文件夾中運行makelibs.bat,並從那裏開始工作。

+0

是的!我也是這麼做的。不管怎樣,謝謝你。 :) – fortress

+0

不客氣。很高興幫助你:) – Pentagon

+1

不要這樣做!沒有人可以幫助你,如果你遇到了一個拙劣的文件的問題。我找不到'Process32First'(ANSI版本 - 沒有Process32FirstA)和'Process32Next'失敗的MASM32版本。所報告的錯誤適用於Unicode。取而代之的是[最新的MASM32 SDK](http://www.masm32.com/download.htm)並安裝它。 – rkhb

相關問題