如何使我的 .exe 文件受到其他计算机的信任

如何使我的 .exe 文件受到其他计算机的信任

我编写了一个简单的 Python 程序,用于将文件上传到服务器供公司人员使用(目前这只是一个短期解决方案)。用户运行该文件,它会要求他们选择文件,然后将文件上传到服务器。我的代码如下:

import os
from tkinter import filedialog, Tk, Label, Button
import paramiko
import urllib.parse
import os
from pathlib import Path

class MyGUI:
    def __init__(self, master):
        self.master = master
        master.title("Server Uploader")
        master.resizable(height=False, width=False)
        master.configure(bg="white")

        self.label = Label(master, text="There was a problem connecting to the server. Please try again later or contact me.", fg="black", bg="white")
        self.label.config(font=("Courier", 12))
        self.label.pack()

class SuccessfulUpload:
    def __init__(self, master):
        self.master = master
        master.title("Successful Upload")
        master.resizable(height=False,width=False)

        self.label = Label(master, text="Upload successful. You can now close this window.")
        self.label.config(font=("Courier, 12"))
        self.label.pack()

#Connect to server using SFTP
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
    ssh_client.connect(hostname='hostname',port=portno,username='username',password='password')
except paramiko.ssh_exception.AuthenticationException as e:
    root = Tk()
    my_gui = MyGUI(root)
    root.mainloop()
    raise SystemExit

#Ask for user to choose files to upload
root = Tk()
root.withdraw()
files = filedialog.askopenfilenames(title="Choose Files to Upload to the Server", filetypes=(("All Files","*.*"),("PDF Files","*.pdf"), ("Word Files","*.doc*")))
print (root.tk.splitlist(files))

s = ssh_client.open_sftp()
if files == "":
    raise SystemExit

#Define local and remote path for file
for file in files:
    localpath = file
    parts = Path(file).parts
    endpath = parts[-1]
    print(endpath)
    remotepath="/Path/" + endpath
    print(remotepath)
    s.put(localpath,remotepath)

root = Tk()
fin = SuccessfulUpload(root)
root.mainloop()

s.close()
root.destroy()

complete = input("Upload Successful. Press any key to exit.")

我使用 pyinstaller 将 .py 文件转换为 .exe 文件。然后我将其发送到另一台计算机。首先,Windows 试图阻止程序下载(可以理解),然后一旦允许下载,Windows 就会尝试阻止程序运行 - 有点烦人,但可以接受。尽管如此,在允许程序通过 Windows 两次后,防病毒软件 (AVG) 仍然阻止程序运行。为了让它运行,我不得不直接进入防病毒软件并为我的程序设置例外。

我无法发送该程序,而您必须在防病毒软件中手动为其设置例外。 有没有什么方法可以让您的文件更值得信赖,以便其他计算机下载和运行(而无需防病毒软件完全阻止程序运行)。

答案1

对于数字签名,你可以尝试一下。(参考自https://steward-fu.github.io/website/driver/wdm/self_sign.htm) signtool 从 MS SDK 或 Visual C++ for Python 获取 (http://aka.ms/vcpython27

第一次

Makecert -r -pe -ss YourName YourName.cer

certmgr.exe -add YourName.cer -s -r localMachine root

signtool sign /s YourName YourApp.exe

相关内容