首页 > 解决方案 > 开发了使用 gecko 的简单 winform 应用程序,不会在另一台计算机上运行

问题描述

我开发了一个简单的 Windows 窗体应用程序,它在 Gecko 网络浏览器中显示网页。它在我的计算机上运行良好(win10,visual st.2017),我也在另一台运行win10的计算机上尝试过它也运行良好,但是当我尝试在客户端的计算机上运行它时它就无法启动,好像什么都没有发生时,光标变为一个圆圈(思考),然后什么也没有。

我安装了.net 4.6 没有变化,禁用杀毒软件没有变化,安装了firefox 没有变化。尝试了另一个简单地打开一个空窗口并且工作正常的winforms应用程序,另一个控制台应用程序工作正常,只是这个使用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)
    {

    }
}

}

帮助将不胜感激,谢谢。

标签: c#gecko

解决方案


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

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


推荐阅读