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

时间:2019-05-26 15:23:31

标签: c# gecko

我开发了一个简单的Windows窗体应用程序,该应用程序在Gecko Webrowser中显示一个网页。它可以在我的计算机上正常运行(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)
    {

    }
}

}

非常感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

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

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