在 python 中启动 Mrt.exe

Mrt.exe launch in python

提问人:anonymous 6598 提问时间:11/3/2023 最后编辑:anonymous 6598 更新时间:11/3/2023 访问量:25

问:

如何在python中启动MRT .exe?

我尝试编写方法在我的 python 程序中启动此程序。 代码如下:

@typing.override
@functools.cache
def __interactive_mode__(self) -> None:
    subprocess.run(["C:\Windows\System32\mrt.exe"])

完整代码:

import customtkinter, tkinter, tkinter.messagebox, subprocess, pickle, functools, typing, sys, My_First_Aid_Kit_interface

type App = customtkinter.CTk()

executable_app: App = App

class Program[executable_app](customtkinter.CTk, My_First_Aid_Kit_interface.My_First_Aid_Kit_interface):
    
    WIDTH: typing.Final[int] = 650
    HEIGHT: typing.Final[int] = 500
    TITLE: typing.Final[str] = "My First Aid Kit"
    ICON: typing.Final[str] = ...
    COLOR_THEME: typing.Final[str] = "dark-blue"
    APPEARENCE_MODE: typing.Final[str] = "system"
    FONT_FOR_WIDGETS: typing.Final[str] = "Roboto Bold"
    WIDGET_SCALING: typing.Final[float] = 1.251 

    def __init__(self, *args, **kwargs) -> None:
        customtkinter.CTk.__init__(self, *args, **kwargs)
        
        customtkinter.set_appearance_mode(self.APPEARENCE_MODE)
        customtkinter.set_default_color_theme(self.COLOR_THEME)
        customtkinter.set_widget_scaling(self.WIDGET_SCALING)
        customtkinter.deactivate_automatic_dpi_awareness()
        
        self.title(self.TITLE)
        self.minsize(height=self.HEIGHT, width=self.WIDTH)
        self.resizable(False, False)
        self.protocol("WM_DELETE_WINDOW", lambda: sys.exit())

        self.font_for_widgets: customtkinter.CTkFont = customtkinter.CTkFont(family=self.FONT_FOR_WIDGETS, size=25)
        self.font_for_title: customtkinter.CTkFont = customtkinter.CTkFont(family=self.FONT_FOR_WIDGETS, size=72)
        self.font_for_small_title: customtkinter.CTkFont = customtkinter.CTkFont(family=self.FONT_FOR_WIDGETS, size=36)

        self.main_screen_title: customtkinter.CTkLabel = customtkinter.CTkLabel(master=self, text="My First Aid Kit", height=75, width=90, font=self.font_for_title)
        self.main_screen_title.place(x=15, y=3)
        
        self.main_screen_interactive_mode_button: customtkinter.CTkButton = customtkinter.CTkButton(master=self, text="интерактивни режим", height=25, width=75, font=self.font_for_widgets, fg_color="green", command=self.__interactive_mode__)
        self.main_screen_interactive_mode_button.place(x=1, y=85)
        
        self.main_screen_full_scan_button: customtkinter.CTkButton = customtkinter.CTkButton(master=self, text="пуно скенирање", height=25, width=75, font=self.font_for_widgets, fg_color="green", command=self.__full_scan__)
        self.main_screen_full_scan_button.place(x=1, y=120)
        
        self.main_screen_full_scan_with_virus_removal_button: customtkinter.CTkButton = customtkinter.CTkButton(master=self, text="пуно скенирање са брисањем вируса", height=25, width=75, font=self.font_for_widgets, fg_color="green", command=self.__full_scan_with_virus_removal__)
        self.main_screen_full_scan_with_virus_removal_button.place(x=1, y=155)
        
        self.main_screen_full_scan_with_virus_removal_button: customtkinter.CTkButton = customtkinter.CTkButton(master=self, text="подешавања", height=25, width=75, font=self.font_for_widgets, fg_color="green")
        self.main_screen_full_scan_with_virus_removal_button.place(x=1, y=190)
        
    @typing.override
    @functools.cache
    def __interactive_mode__(self) -> None:
        subprocess.run(["C:\Windows\System32\mrt.exe"])
        
    @typing.override
    @functools.cache
    def __full_scan__(self) -> None:
        subprocess.call(["MRT.exe /F"])
        
    @typing.override
    @functools.cache
    def __full_scan_with_virus_removal__(self) -> None:
        subprocess.call(["MRT.exe /F:Y"])    

    @functools.cache
    def __run__(self) -> None:
        self.mainloop()
        
if __name__ == "__main__":
   program: Program = Program()
   program.__run__()
        

结果,我的程序崩溃了,Visual Studio 显示“对于 int32 来说,值要么太大,要么太小”。当我关闭程序时,会出现mrt.exe。我不知道这怎么可能。

Python 子进程 调用 防病毒 反恶意软件

评论

0赞 Charles Duffy 11/4/2023
这在 Windows 上不像其他任何地方那样严格执行,但一般来说,您不希望这样做["MRT.exe", "/F"]["MRT.exe /F"]
0赞 anonymous 6598 11/4/2023
subprocess.run([“C:\Windows\System32\mrt.exe”])呢?
0赞 anonymous 6598 11/4/2023
一切都没有改变。我替换为 [“mrt.exe”, “/f”] 并给出了一个错误,即 bufsize 必须是整数。
0赞 Charles Duffy 11/4/2023
在问题文本中包括完整、准确的例外情况。(顺便说一句,评论不应该是答案;如果我认为我有一个答案,我会把它添加为答案——评论“X通常是更好的做法”只是意味着“X通常是更好的做法”,而不是“我认为X会解决你的问题”)

答: 暂无答案