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获取计算机名