簡體   English   中英

如何使用 python 檢查計算機是在域中還是在工作組中

[英]How to use python to check if a computer is in a domain or is in workgroup

我想使用 python 檢查計算機是在域中還是在工作組中
例如:

def run_check():
    # code here

result = run_check()
if result == "Domain":
    print("Domain")
elif result == "Workgroup":
    print("Workgroup")
else:
    print("None")

我嘗試使用os.environ['USERDNSDOMAIN']但它給出了WorkGroupNameDomainName並且我無法判斷該名稱是用於工作組還是用於域

你能幫我嗎?

提前致謝

應用Windows Management Instrumentationwmi模塊):

import wmi

wmi_os = wmi.WMI().Win32_ComputerSystem()[0]
print( wmi_os.Name, 'PartOfDomain?', wmi_os.PartOfDomain)
 MY-PC PartOfDomain? False

注意: print(wmi_os)顯示Win32_ComputerSystem class 實例的所有屬性(及其值)。

所有屬性都是print(wmi_os.__dict__['properties'].keys())

dict_keys(['AdminPasswordStatus', 'AutomaticManagedPagefile', 'AutomaticResetBootOption', 'AutomaticResetCapability', 'BootOptionOnLimit', 'BootOptionOnWatchDog', 'BootROMSupported', 'BootStatus', 'BootupState', 'Caption', 'ChassisBootupState', 'ChassisSKUNumber', 'CreationClassName', 'CurrentTimeZone', 'DaylightInEffect', 'Description', 'DNSHostName', 'Domain', 'DomainRole', 'EnableDaylightSavingsTime', 'FrontPanelResetStatus', 'HypervisorPresent', 'InfraredSupported', 'InitialLoadInfo', 'InstallDate', 'KeyboardPasswordStatus', 'LastLoadInfo', 'Manufacturer', 'Model', 'Name', 'NameFormat', 'NetworkServerModeEnabled', 'NumberOfLogicalProcessors', 'NumberOfProcessors', 'OEMLogoBitmap', 'OEMStringArray', 'PartOfDomain', 'PauseAfterReset', 'PCSystemType', 'PCSystemTypeEx', 'PowerManagementCapabilities', 'PowerManagementSupported', 'PowerOnPasswordStatus', 'PowerState', 'PowerSupplyState', 'PrimaryOwnerContact', 'PrimaryOwnerName', 'ResetCapability', 'ResetCount', 'ResetLimit', 'Roles', 'Status', 'SupportContactDescription', 'SystemFamily', 'SystemSKUNumber', 'SystemStartupDelay', 'SystemStartupOptions', 'SystemStartupSetting', 'SystemType', 'ThermalState', 'TotalPhysicalMemory', 'UserName', 'WakeUpType', 'Workgroup'])

您可能主要對以下內容感興趣:

Caption
DNSHostName
Domain
DomainRole
Name
NameFormat
PartOfDomain
Roles
UserName
Workgroup

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM