2016-04-08 14 views
0

Çalıştırdığım zaman, bir disketi sürücümde bir metin belgesine not defterine aktaran bir yürütülebilir dosya oluşturmak istiyorum. Bu önemlidir, çünkü dosyayı anahtar kelimeler için taramak ve bulunursa son kullanıcıyı uyarmak istiyorum. Visual Basic'te Diğer Çalışma İşlemlerini Dumping

Bu kod

Şu anda var:

Private Const ProcessQueryInformation As Integer = &H400 
Private Const ProcessVmRead As Integer = &H10 

<DllImport("dbghelp", CallingConvention:=CallingConvention.Winapi, SetLastError:=True)> 
Private Shared Function MiniDumpWriteDump(
    ByVal hProcess As SafeFileHandle, 
    ByVal processId As Int32, 
    ByVal hFile As SafeFileHandle, 
    ByVal dumpType As MinidumpType, 
    ByVal exceptionParam As IntPtr, 
    ByVal userStreamParam As IntPtr, 
    ByVal callbackParam As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean 
End Function 

<DllImport("kernel32", CallingConvention:=CallingConvention.Winapi, SetLastError:=True)> 
Public Shared Function OpenProcess(
    ByVal dwDesiredAccess As UInteger, 
    ByVal bInheritHandle As Boolean, 
    ByVal dwProcessId As Integer) As SafeFileHandle 
End Function 

<Flags()> 
Private Enum MinidumpType 
    MiniDumpNormal = 0 
    MiniDumpWithDataSegs = 1 
    MiniDumpWithFullMemory = 2 
    MiniDumpWithHandleData = 4 
    MiniDumpFilterMemory = 8 
    MiniDumpScanMemory = &H10 
    MiniDumpWithUnloadedModules = &H20 
    MiniDumpWithIndirectlyReferencedMemory = &H40 
    MiniDumpFilterModulePaths = &H80 
    MiniDumpWithProcessThreadData = &H100 
    MiniDumpWithPrivateReadWriteMemory = &H200 
    MiniDumpWithoutOptionalData = &H400 
    MiniDumpWithFullMemoryInfo = &H800 
    MiniDumpWithThreadInfo = &H1000 
    MiniDumpWithCodeSegs = &H2000 
    MiniDumpWithoutAuxiliaryState = &H4000 
    MiniDumpWithFullAuxiliaryState = &H8000 
End Enum 


Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click 
    ' Get the process id. 
    Dim id As Integer = GetProcessId("notepad") 
    ' Get the process handle from the id. 
    Dim hProcess As SafeFileHandle = Nothing ' We could define a SafeProcessHandle...  
    Try 
     hProcess = OpenProcess(ProcessVmRead Or ProcessQueryInformation, False, id) 
     ' Check result... 
     If hProcess Is Nothing Then 
      If Marshal.GetLastWin32Error = 0 Then 
       Throw New Win32Exception 
      End If 
     End If 
     Dim oneFileName As String = "C:\dump.txt" 
     Using oneFile As FileStream = New FileStream(oneFileName, FileMode.Create) 
      MiniDumpWriteDump(hProcess, id, oneFile.SafeFileHandle, MinidumpType.MiniDumpWithFullMemory, 
           Nothing, Nothing, Nothing) 
      oneFile.Flush() 
     End Using 
    Finally 
     If hProcess IsNot Nothing Then 
      hProcess.Close() 
      hProcess.Dispose() 
     End If 
    End Try 
End Sub 

Private Function GetProcessId(ByVal processName As String) As Integer 
    Dim id As Integer = -1 
    Dim processes() As Process = Process.GetProcessesByName(processName) 
    If processes.Count = 0 Then Throw New ArgumentException("Could not find the process specified", "processName") 
    id = processes(0).Id ' There could be many processes - we just grab the first. 
    For Each p As Process In processes 
     p.Dispose() 
    Next 
    Return id 
End Function 

Sorunum bu kodu çalıştırmak her zaman, ben boş bir metin belgesi almak olmasıdır. MiniDumpWriteDump işlevinin yanlış döndüğünü biliyorum, nedenini anlayamıyorum - bu yüzden buradayım.

Bilgileriniz için, bu her işlemin BUT'un kendisi ile olur.

+6

Bu yazabilmek için çok üzgünüm - Ben MiniDumpWriteDump sözü en kısa sürede bir çözüm açıldı - burada http://stackoverflow.com/questions/33868483/minidumpwritedump-c-produces-zero-length -dump-files-için-spesifik proses? rQ = 1 – erawdaB

cevap

İlgili konular