开发了使用 gecko 的简单 winform 应用程序,不会 运行 在另一台计算机上

Developed simple winform app that uses gecko, won't run on another computer

我开发了一个简单的 windows 表单应用程序,它在 Gecko 网络浏览器中显示网页。它在我的电脑上运行良好(win10,visual st.2017),我也在另一台电脑 运行ning win10 上尝试过,它也 运行 很好,但是当我尝试 运行ning在客户端电脑上就是打不开,好像什么都没发生一样,光标变成一个圆圈(思考)然后什么都没有。

我安装了 .net 4.6 没有变化,禁用杀毒软件没有变化,安装了 firefox 没有变化。尝试了另一个 winforms 应用程序,它只是打开一个空的 window 并且工作正常,另一个控制台应用程序工作正常,只是这个使用 Gecko webbrowser 的应用程序不起作用。

我尝试简单地复制我的 bin\debug 文件夹和 运行 应用程序,我还尝试在制作发布版本后从 setup.exe 安装应用程序也不会 运行,它给出了找不到 plugin-hang-ui.deploy.exe 的错误,我在 bin\Release.

下的 Firefox 文件夹中有 plugin-hang-ui.exe

我的代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Security.Cryptography;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using System.IO;
using Gecko;

namespace ScreenPlayer1
{
public partial class Form1 : Form
{
    static string serial = "thefirst1";//This is unique per user.
    private const int SW_HIDE = 0;
    private const int SW_SHOW = 1;
    [DllImport("user32.dll")]
    private static extern int FindWindow(string className, string windowText);
    [DllImport("user32.dll")]
    private static extern int ShowWindow(int hwnd, int command);
    int hWnd = FindWindow("Shell_TrayWnd", "");
    string UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0";
    public Form1()
    {
        InitializeComponent();
        Xpcom.Initialize("Firefox");
        GeckoPreferences.User["full-screen-api.enabled"] = true;
        GeckoPreferences.Default["full-screen-api.enabled"] = true;
        GeckoPreferences.User["general.useragent.override"] = UserAgent;
        GeckoPreferences.Default["general.useragent.override"] = UserAgent;
        WindowState = FormWindowState.Maximized;
        TopMost = true;

    }

    /// <summary>
    /// //hash stuff
    /// </summary>
    static string ComputeSha256Hash(string rawData, string salt)
    {
        // Create a SHA256   
        using (SHA256 sha256Hash = SHA256.Create())
        {
            string salted = "6++6" + rawData + salt;
            // ComputeHash - returns byte array  
            byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(salted));

            // Convert byte array to a string   
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < bytes.Length; i++)
            {
                builder.Append(bytes[i].ToString("x2"));
            }
            return builder.ToString();
        }
    }
    /// <summary>
    /// end hash stuff
    /// </summary>
    /// 


    private void Form1_Load(object sender, EventArgs e)
    {
        Random r = new Random(), s = new Random(), t = new Random();
        string salt = "s" + r.Next(1, 100) + s.Next(1, 100) + t.Next(1, 100);
        string get_serial = ComputeSha256Hash(serial, salt);
        string mode = "client";

        if (!File.Exists("mode.txt"))
        {
            string message = "Set as server?", caption = "Mode not set, choose yes for server no for client!";
            MessageBoxButtons buttons = MessageBoxButtons.YesNo;
            DialogResult result;

            // Displays the MessageBox.

            result = MessageBox.Show(message, caption, buttons);
            if (result == DialogResult.Yes)
            {
                mode = "server";
                System.IO.File.WriteAllText(@"mode.txt", mode);
            }
            else
            {
                mode = "client";
                System.IO.File.WriteAllText(@"mode.txt", mode);
            }
        }
        else
        {
            mode = System.IO.File.ReadAllText(@"mode.txt");
        }

        if (mode == "client")
        {
            int hh = ShowWindow(hWnd, SW_SHOW);
            FormBorderStyle = FormBorderStyle.None;
        }
        try
        {
            geckoWebBrowser2.Navigate("http://www.example.com/scr/prl.php?usr="                               
                               + get_serial + "&sts=" + salt + "&mode=" + mode);
            geckoWebBrowser2.Width = geckoWebBrowser2.Parent.Width;
            geckoWebBrowser2.Height = geckoWebBrowser2.Parent.Height;
        }
        catch (Exception sysEx)
        {
            System.Diagnostics.EventLog.WriteEntry("Bad web browsing!", sysEx.ToString());
        }
    }

    private void Form1_Closing(object sender, FormClosingEventArgs e)
    {
        int hwnd = ShowWindow(hWnd, SW_SHOW);
    }

    private void geckoWebBrowser2_Click(object sender, EventArgs e)
    {

    }
}

}

不胜感激,谢谢。

安装 Visual Studio 2019 与 .NET 并从 NuGet 包中添加了 GeckoFX。在那之后,我的应用程序就像魅力一样运行!

这不是我期望的答案,但由于没有其他答案,所以应该这样做。