Python制作Windows憑據(jù)添加工具
1、圖示


2、代碼
import subprocess
import tkinter as tk
from tkinter import messagebox
def add_windows_credential(target_name, username="guest", password=""):
"""
使用 cmdkey 命令添加 Windows 憑據(jù)
"""
try:
# 構(gòu)建 cmdkey 命令
cmd = f'cmdkey /add:{target_name} /user:{username}'
if password:
cmd += f' /pass:{password}'
# 執(zhí)行命令
result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
# 檢查命令執(zhí)行結(jié)果
if result.returncode == 0:
messagebox.showinfo("成功", f"成功添加憑據(jù)!\n目標(biāo)計(jì)算機(jī): {target_name}")
return True
else:
messagebox.showerror("錯(cuò)誤", f"添加憑據(jù)失敗: {result.stderr}")
return False
except Exception as e:
messagebox.showerror("錯(cuò)誤", f"添加憑據(jù)時(shí)發(fā)生錯(cuò)誤: {str(e)}")
return False
class CredentialApp:
def __init__(self, root):
self.root = root
self.root.title("Windows憑據(jù)添加工具")
self.root.geometry("300x150")
# 創(chuàng)建主框架,用于居中顯示內(nèi)容
main_frame = tk.Frame(root)
main_frame.pack(expand=True)
# 創(chuàng)建輸入框和標(biāo)簽
tk.Label(main_frame, text="請輸入目標(biāo)計(jì)算機(jī)名:", 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("警告", "請輸入計(jì)算機(jī)名!")
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()到此這篇關(guān)于Python制作Windows憑據(jù)添加工具的文章就介紹到這了,更多相關(guān)Python Windows憑據(jù)添加內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
python安裝oracle擴(kuò)展及數(shù)據(jù)庫連接方法
這篇文章主要介紹了python安裝oracle擴(kuò)展及數(shù)據(jù)庫連接方法,較為詳細(xì)的分析了Python下載oracle擴(kuò)展及Windows、Linux環(huán)境下的安裝步驟、操作技巧及注意事項(xiàng),需要的朋友可以參考下2017-02-02
python pandas dataframe 去重函數(shù)的具體使用
這篇文章主要介紹了python pandas dataframe 去重函數(shù)的具體使用,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07
python?基本結(jié)構(gòu)語句(函數(shù)和模塊)
這篇文章主要介紹了python?基本結(jié)構(gòu)語句(函數(shù)和模塊),文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-09-09
VScode查看python f.write()的文件亂碼問題及解決方法
這篇文章主要介紹了VScode查看python f.write()的文件亂碼問題及解決方法,本文通過圖文并茂的形式給大家分享解決方法,需要的朋友可以參考下2023-02-02
Python Selenium 之?dāng)?shù)據(jù)驅(qū)動(dòng)測試的實(shí)現(xiàn)
這篇文章主要介紹了Python Selenium 之?dāng)?shù)據(jù)驅(qū)動(dòng)測試的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08
Python itertools.product方法代碼實(shí)例
這篇文章主要介紹了Python itertools.product方法代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-03-03
python如何實(shí)現(xiàn)不用裝飾器實(shí)現(xiàn)登陸器小程序
這篇文章主要介紹了python如何實(shí)現(xiàn)不用裝飾器實(shí)現(xiàn)登陸器小程序,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-12-12

