当前位置: 代码网 > it编程>前端脚本>Python > Python制作Windows凭据添加工具

Python制作Windows凭据添加工具

2024年12月19日 Python 我要评论
1、图示2、代码import subprocessimport tkinter as tkfrom tkinter import messagebox def add_windows_credenti

1、图示

2、代码

import subprocess
import tkinter as tk
from tkinter import messagebox
 
def add_windows_credential(target_name, username="guest", password=""):
    """
    使用 cmdkey 命令添加 windows 凭据
    """
    try:
        # 构建 cmdkey 命令
        cmd = f'cmdkey /add:{target_name} /user:{username}'
        if password:
            cmd += f' /pass:{password}'
        
        # 执行命令
        result = subprocess.run(cmd, shell=true, capture_output=true, text=true)
        
        # 检查命令执行结果
        if result.returncode == 0:
            messagebox.showinfo("成功", f"成功添加凭据!\n目标计算机: {target_name}")
            return true
        else:
            messagebox.showerror("错误", f"添加凭据失败: {result.stderr}")
            return false
            
    except exception as e:
        messagebox.showerror("错误", f"添加凭据时发生错误: {str(e)}")
        return false
 
class credentialapp:
    def __init__(self, root):
        self.root = root
        self.root.title("windows凭据添加工具")
        self.root.geometry("300x150")
        
        # 创建主框架,用于居中显示内容
        main_frame = tk.frame(root)
        main_frame.pack(expand=true)
        
        # 创建输入框和标签
        tk.label(main_frame, text="请输入目标计算机名:", font=('arial', 10)).pack(pady=10)
        self.computer_entry = tk.entry(main_frame, width=25)
        self.computer_entry.pack(pady=5)
        
        # 按钮框架
        button_frame = tk.frame(main_frame)
        button_frame.pack(pady=20)
        
        # 添加确定和取消按钮
        tk.button(button_frame, text="确定", width=10, command=self.add_credential).pack(side=tk.left, padx=10)
        tk.button(button_frame, text="取消", width=10, command=self.root.quit).pack(side=tk.left, padx=10)
    
    def add_credential(self):
        computer_name = self.computer_entry.get().strip()
        
        if not computer_name:
            messagebox.showwarning("警告", "请输入计算机名!")
            return
            
        if add_windows_credential(computer_name):
            self.computer_entry.delete(0, tk.end)  # 清空输入框
 
def main():
    root = tk.tk()
    app = credentialapp(root)
    root.mainloop()
 
if __name__ == "__main__":
    main()

到此这篇关于python制作windows凭据添加工具的文章就介绍到这了,更多相关python windows凭据添加内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com