我们从Python开源项目中,提取了以下13个代码示例,用于说明如何使用win32api.GetComputerName()。
def GeneralInfo(): global host,fv,srcfile host=win32api.GetComputerName() srcfile="C:\\"+host fv=open(srcfile,'w') fv.write("Machine NAME : ") fv.write(host) fv.write('\n') fv.write("the machine is joined to the domain : ") fv.write(str(win32api.GetDomainName())) fv.write('\n') fv.write("these settings were logged for user : ") fv.write(str(win32api.GetUserName())) fv.write('\n') fv.write("System Time is : ") fv.write(str(win32api.GetSystemTime())) fv.write('\n\n\n')
def test(serverName): if string.lower(serverName)==string.lower(win32api.GetComputerName()): print "You must specify a remote server name, not the local machine!" return # Hack to overcome a DCOM limitation. As the Python.Interpreter object # is probably installed locally as an InProc object, DCOM seems to ignore # all settings, and use the local object. clsctx = pythoncom.CLSCTX_SERVER & ~pythoncom.CLSCTX_INPROC_SERVER ob = win32com.client.DispatchEx("Python.Interpreter", serverName, clsctx=clsctx) ob.Exec("import win32api") actualName = ob.Eval("win32api.GetComputerName()") if string.lower(serverName) != string.lower(actualName): print "Error: The object created on server '%s' reported its name as '%s'" % (serverName, actualName) else: print "Object created and tested OK on server '%s'" % serverName
def test(serverName): if string.lower(serverName)==string.lower(win32api.GetComputerName()): print("You must specify a remote server name, not the local machine!") return # Hack to overcome a DCOM limitation. As the Python.Interpreter object # is probably installed locally as an InProc object, DCOM seems to ignore # all settings, and use the local object. clsctx = pythoncom.CLSCTX_SERVER & ~pythoncom.CLSCTX_INPROC_SERVER ob = win32com.client.DispatchEx("Python.Interpreter", serverName, clsctx=clsctx) ob.Exec("import win32api") actualName = ob.Eval("win32api.GetComputerName()") if string.lower(serverName) != string.lower(actualName): print("Error: The object created on server '%s' reported its name as '%s'" % (serverName, actualName)) else: print("Object created and tested OK on server '%s'" % serverName)
def __init__(self): global KeyPath debug("context", "Started CTX with key path: %s" % KeyPath) self.store = PSSTMessageStore() self.keystore = Keystore(KeyPath) self.unseen = Unseen(KeyPath) self.internal = socket.gethostbyname(socket.gethostname()) # Calculate ID self.clientID = win32api.GetComputerName().lower() + "." + win32api.GetDomainName().lower() self.isAdmin = ctypes.windll.shell32.IsUserAnAdmin() # Get external IP address try: # Get External IP Address opener = urllib2.build_opener() opener.addheaders = [('User-agent', 'Mozilla/5.0')] target = "http://www.icanhazip.com/" response = opener.open(target).read() self.external = response.strip() except Exception as e: print(str(e)) # Calculate corp and DC #TODO
def __init__(self): # variable to write a flat file self.fileHandle = None self.HKEY_CLASSES_ROOT = win32con.HKEY_CLASSES_ROOT self.HKEY_CURRENT_USER = win32con.HKEY_CURRENT_USER self.HKEY_LOCAL_MACHINE = win32con.HKEY_LOCAL_MACHINE self.HKEY_USERS = win32con.HKEY_USERS self.FILE_PATH = "//masblrfs06/karcherarea$/workarea/nishitg/"+ win32api.GetComputerName() self.CONST_OS_SUBKEY = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion" self.CONST_PROC_SUBKEY = "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0" self.CONST_SW_SUBKEY = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
def getSoftwareList(self): try: hCounter=0 hAttCounter=0 # connecting to the base hHandle = win32api.RegConnectRegistry(None,win32con.HKEY_LOCAL_MACHINE) # getting the machine name and domain name hCompName = win32api.GetComputerName() hDomainName = win32api.GetDomainName() # opening the sub key to get the list of Softwares installed hHandle = win32api.RegOpenKeyEx(self.HKEY_LOCAL_MACHINE,self.CONST_SW_SUBKEY,0,win32con.KEY_ALL_ACCESS) # get the total no. of sub keys hNoOfSubNodes = win32api.RegQueryInfoKey(hHandle) # delete the entire data and insert it again #deleteMachineSW(hCompName,hDomainName) # browsing each sub Key which can be Applications installed while hCounter < hNoOfSubNodes[0]: hAppName = win32api.RegEnumKey(hHandle,hCounter) hPath = self.CONST_SW_SUBKEY + "\\" + hAppName # initialising hAttCounter hAttCounter = 0 hOpenApp = win32api.RegOpenKeyEx(self.HKEY_LOCAL_MACHINE,hPath,0,win32con.KEY_ALL_ACCESS) # [1] will give the no. of attributes in this sub key hKeyCount = win32api.RegQueryInfoKey(hOpenApp) hMaxKeyCount = hKeyCount[1] hSWName = "" hSWVersion = "" while hAttCounter < hMaxKeyCount: hData = win32api.RegEnumValue(hOpenApp,hAttCounter) if hData[0]== "DisplayName": hSWName = hData[1] self.preparefile("SW Name",hSWName) elif hData[0]== "DisplayVersion": hSWVersion = hData[1] self.preparefile("SW Version",hSWVersion) hAttCounter = hAttCounter + 1 #if (hSWName !=""): #insertMachineSW(hCompName,hDomainName,hSWName,hSWVersion) hCounter = hCounter + 1 except: self.preparefile("Exception","In exception in getSoftwareList")
def assert_common_fields(self, evt, msg=None, eventID=10, sid=None, level="Information", extra=None): assert evt["computer_name"].lower() == win32api.GetComputerName().lower() assert "record_number" in evt self.assertDictContainsSubset({ "event_id": eventID, "level": level, "log_name": self.providerName, "source_name": self.applicationName, "type": self.api, }, evt) if msg == None: assert "message" not in evt else: self.assertEquals(evt["message"], msg) self.assertDictContainsSubset({"event_data.param1": msg}, evt) if sid == None: self.assertEquals(evt["user.identifier"], self.get_sid_string()) self.assertEquals(evt["user.name"].lower(), win32api.GetUserName().lower()) self.assertEquals(evt["user.type"], "User") assert "user.domain" in evt else: self.assertEquals(evt["user.identifier"], sid) assert "user.name" not in evt assert "user.type" not in evt if extra != None: self.assertDictContainsSubset(extra, evt)
def iterConnectableShares(self): nr = win32wnet.NETRESOURCE() nr.dwScope = RESOURCE_GLOBALNET nr.dwUsage = RESOURCEUSAGE_CONTAINER nr.lpRemoteName = "\\\\" + win32api.GetComputerName() handle = win32wnet.WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, 0, nr) while 1: items = win32wnet.WNetEnumResource(handle, 0) if len(items)==0: break for item in items: if item.dwDisplayType == RESOURCEDISPLAYTYPE_SHARE: yield item
def getSysInfo(self): try: hCounter=0 hProcessorName="" # connecting to the base hHandle = win32api.RegConnectRegistry(None,self.HKEY_LOCAL_MACHINE) # opening the sub key to get the processor name print "debug1" hHandle = win32api.RegOpenKeyEx(self.HKEY_LOCAL_MACHINE,self.CONST_PROC_SUBKEY,0,win32con.KEY_ALL_ACCESS) hNoOfKeys = win32api.RegQueryInfoKey(hHandle)[1] while hCounter < hNoOfKeys: hData = win32api.RegEnumValue(hHandle,hCounter) if hData[0]== "Identifier": hProcessorName = hData[1] hCounter = hCounter + 1 if hProcessorName=="": hProcessorName = "Processor Name Cannot be determined" self.preparefile("Processor Name",hProcessorName) hCompName = win32api.GetComputerName() self.preparefile("Computer Name",hCompName) hDomainName = win32api.GetDomainName() self.preparefile("Domain Name",hDomainName) hUserName = win32api.GetUserName() self.preparefile("User Name",hUserName) # getting OS Details hCounter=0 # opening the sub key to get the processor name hHandle = win32api.RegOpenKeyEx(self.HKEY_LOCAL_MACHINE,self.CONST_OS_SUBKEY,0,win32con.KEY_ALL_ACCESS) hNoOfKeys = win32api.RegQueryInfoKey(hHandle)[1] hOSVersion="" hOSName="" while hCounter < hNoOfKeys: hData = win32api.RegEnumValue(hHandle,hCounter) if hData[0]== "ProductName": hOSName = hData[1] self.preparefile("OS Name",hOSName) break hCounter = hCounter + 1 if hOSName=="": self.preparefile("OS Name","OS Name could not be read from the registry") hCounter = 0 while hCounter < hNoOfKeys: hData = win32api.RegEnumValue(hHandle,hCounter) if hData[0]== "CSDVersion": hOSVersion = hData[1] self.preparefile("OS Version",hOSVersion) break hCounter = hCounter + 1 if hOSVersion=="": self.preparefile("OS Version","OS Version could not be read from the registry") # inserting master data #insertMachineMaster(hCompName,hDomainName,hOSName,hOSVersion,hProcessorName) except: self.preparefile("Exception","in Exception in getSysDetails")