today2004 发表于 2010-8-12 22:50:34

如何获取几个进程的路径并写入到文件啊[已解决]

本帖最后由 today2004 于 2010-8-13 21:37 编辑

我写的怎么每次写入到文件就最后一个进程的路径写入了 其他的都没有写入
FileChangeDir (@ScriptDir)
Dim $var
$var=IniReadSection("setcfg.ini","进程")
If @error Then
        MsgBox(16,"错误","请检查“setcfg.ini”是否存在或配置是否正确!")
        Exit
        Else
        For $i = 1 To $var
                If $var[$i] = "1" Then
                        ProcessExists($var[$i])
       $iPid=ProcessExists($var[$i])

                EndIf
        Next
        $file = FileOpen("test.txt", 1)
If $file = -1 Then
        MsgBox(0, "错误", "不能打开文件.")
        Exit
EndIf
FileWrite($file, _GetModuleFileNameEx($iPid)& @CRLF)

EndIf

      Func _GetModuleFileNameEx($_Pid)
      $_Hwnd=DllCall("Kernel32.dll","hwnd","OpenProcess","dword",0x0400+0x0010,"int",0,"dword",$_Pid)      
      $_Return=DllCall("Psapi.dll","long","GetModuleFileNameEx","hwnd",$_Hwnd,"long",0,"str",0,"long",255)      
      DllCall("Kernel32.dll","int","CloseHandle","hwnd",$_Hwnd)      
      If StringInStr($_Return,"\") Then Return $_Return
      Return ""
          EndFunc

       
高手指导哈谢谢

afan 发表于 2010-8-12 23:08:13

FileChangeDir(@ScriptDir)
Dim $var = IniReadSection("setcfg.ini", "进程")
If @error Then Exit MsgBox(16, "错误", "请检查“setcfg.ini”是否存在或配置是否正确!")
Dim $out
For $i = 1 To $var
        If $var[$i] = "1" Then
                $iPid = ProcessExists($var[$i])
                If Not $iPid Then ContinueLoop
                $out &= _GetModuleFileNameEx($iPid) & @CRLF
        EndIf
Next
FileWrite("test.txt", $out)

Func _GetModuleFileNameEx($_Pid)
        $_Hwnd = DllCall("Kernel32.dll", "hwnd", "OpenProcess", "dword", 0x0400 + 0x0010, "int", 0, "dword", $_Pid)
        $_Return = DllCall("Psapi.dll", "long", "GetModuleFileNameEx", "hwnd", $_Hwnd, "long", 0, "str", 0, "long", 255)
        DllCall("Kernel32.dll", "int", "CloseHandle", "hwnd", $_Hwnd)
        If StringInStr($_Return, "\") Then Return $_Return
        Return ""
EndFunc   ;==>_GetModuleFileNameEx

today2004 发表于 2010-8-12 23:12:57

感谢 可以了 谢谢
页: [1]
查看完整版本: 如何获取几个进程的路径并写入到文件啊[已解决]