如何将Windows Forms应用程序附加到.EXE进程



再次需要您的帮助。相信我,我已经搜索了数十次,但找不到太多有用的信息。

所以我正在做的这个项目背后的想法是将我的vb.net Windows表单应用程序附加到称为"反击全球进攻"的游戏,这不是作弊!

我的意图基本上是我在玩游戏时可以看一下的一些有用的工具,例如时间等...

[问题]我看过几个视频,但与此相反,这意味着它们将现有流程附加到窗户表单上。我看了一个视频,一个人将Calc.exe附加到他的Windows表单应用程序上,您可以理解,我想要相反的情况,我想将我的Windows表单附加到现有应用程序中。

[我尝试过的东西]因此,我所做的就是复制他的C#代码,将其翻译成VB.NET并将其混合,我弄乱了:D

当我运行项目时,它将启动每个过程的200个实例(游戏& the应用程序),我必须重新启动我的PC以关闭它们:D

Imports System.Windows.Forms
Imports System.Threading
Imports System.Diagnostics
Imports System.Runtime.InteropServices
Partial Public Class CubicCheat
    Inherits Form
    Public Sub New()
        InitializeComponent()
    End Sub
    <DllImport("USER32.DLL")> _
    Private Shared Function SetParent(hwc As IntPtr, hwp As IntPtr) As IntPtr
    End Function
    Private Sub CubicCheat_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        HookCsgo()
    End Sub
    Function HookCsgo()
        Dim csgo As Process = Process.Start("C:Program Files (x86)SteamsteamappscommonCounter-Strike Global Offensivecsgo.exe")
        Dim cubic As Process = Process.Start("C:Usersredfa_000DocumentsVisual Studio 2012ProjectsC++ ProjekterCrazy TutorialsCubicHookCubicHookbinDebugCubicHook.exe")
        Thread.Sleep(500)
        cubic.WaitForInputIdle()
        SetParent(cubic.MainWindowHandle, csgo.Handle)
        Dispose()
    End Function
End Class

我希望您的代码看起来更像:

    Dim csgo As Process
    Dim csgoFileName As String = "C:Program Files (x86)SteamsteamappscommonCounter-Strike Global Offensivecsgo.exe"
    Dim csgoMatches As Process() = Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(csgoFileName))
    If csgoMatches.Length = 0 Then
        csgo = Process.Start(csgoFileName)
        csgo.WaitForInputIdle()
    Else
        csgo = csgoMatches(0)
    End If
    Dim cubic As Process
    Dim cubicFileName As String = "C:Usersredfa_000DocumentsVisual Studio 2012ProjectsC++ ProjekterCrazy TutorialsCubicHookCubicHookbinDebugCubicHook.exe"
    Dim cubicMatches() As Process = Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(cubicFileName))
    If cubicMatches.Length = 0 Then
        cubic = Process.Start(cubicFileName)
        cubic.WaitForInputIdle()
    Else
        cubic = cubicMatches(0)
    End If
    SetParent(cubic.MainWindowHandle, csgo.MainWindowHandle)

请注意,在setParent()调用中,我们都在>两个 ploce中使用MainWindowHandle。您不能在那里使用句柄,因为这意味着完全不同的东西。

相关内容

  • 没有找到相关文章

最新更新