最新消息:本站所有跳转向bbs.ykit.cn的附件将全面停止,附件已转移到https://www.qingsj.com

python获取计算机名

Python 有客 310浏览
import ctypes
import os
#获取计算机名
def getname():
    pcName = ctypes.c_char_p(''.encode('utf-8'))
    pcSize = 16
    pcName = ctypes.cast(pcName, ctypes.c_char_p)
    try:
        ctypes.windll.kernel32.GetComputerNameA(pcName, ctypes.byref(ctypes.c_int(pcSize)))
    except Exception:
        print("Sth wrong in getname!")
    print(pcName.value.decode('utf-8'))
 
def main():
    getname()
 
if __name__ == "__main__":
    main()

转载请注明:有客帮 » python获取计算机名