當前位置: 首頁>>代碼示例>>Python>>正文


Python win32api.GetComputerName方法代碼示例

本文整理匯總了Python中win32api.GetComputerName方法的典型用法代碼示例。如果您正苦於以下問題:Python win32api.GetComputerName方法的具體用法?Python win32api.GetComputerName怎麽用?Python win32api.GetComputerName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在win32api的用法示例。


在下文中一共展示了win32api.GetComputerName方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import GetComputerName [as 別名]
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 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:18,代碼來源:testDCOM.py

示例2: __init__

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import GetComputerName [as 別名]
def __init__(self):
        """Initializes the Windows platform instance.
        """
        # The method to invoke when termination is requested.
        self.__termination_handler = None
        # The method to invoke when status is requested by another process.
        self.__status_handler = None
        # The file path to the configuration.  We need to stash this so it is available when start is invoked.
        self.__config_file_path = None

        # The local domain Administrators name.
        self.__local_administrators = "%s\\Administrators" % win32api.GetComputerName()

        self.__no_change_user = False

        # Controls whether or not we warn the user via stdout that we are about to escalate to Administrator privileges.
        self.__no_escalation_warning = False

        PlatformController.__init__(self) 
開發者ID:scalyr,項目名稱:scalyr-agent-2,代碼行數:21,代碼來源:platform_windows.py

示例3: iterConnectableShares

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import GetComputerName [as 別名]
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 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:17,代碼來源:test_win32wnet.py

示例4: hostname

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import GetComputerName [as 別名]
def hostname(self):
        """Returns the client hosts name."""
        return win32api.GetComputerName()

    # Windows file API interface 
開發者ID:kdart,項目名稱:pycopia,代碼行數:7,代碼來源:WindowsServer.py

示例5: run_server

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import GetComputerName [as 別名]
def run_server():
    os.chdir(r"C:\tmp")
    Pyro.core.initServer(banner=0, storageCheck=0)
    ns=Pyro.naming.NameServerLocator().getNS()

    daemon=Pyro.core.Daemon()
    daemon.useNameServer(ns)

    uri=daemon.connectPersistent(Win32Agent(),
                "Agents.%s" % (win32api.GetComputerName().lower(),))
    daemon.requestLoop(_checkexit)
    daemon.shutdown() 
開發者ID:kdart,項目名稱:pycopia,代碼行數:14,代碼來源:WindowsServer.py

示例6: __init__

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import GetComputerName [as 別名]
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" 
開發者ID:ActiveState,項目名稱:code,代碼行數:13,代碼來源:recipe-265858.py

示例7: getSoftwareList

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import GetComputerName [as 別名]
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") 
開發者ID:ActiveState,項目名稱:code,代碼行數:43,代碼來源:recipe-265858.py

示例8: reListSessions

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import GetComputerName [as 別名]
def reListSessions(outFh):
    protocols = {
        ts.WTS_PROTOCOL_TYPE_CONSOLE: "console",
        ts.WTS_PROTOCOL_TYPE_ICA: "citrix",
        ts.WTS_PROTOCOL_TYPE_RDP: "rdp",
    }

    #hostname = api.GetComputerName()
    hserver = ts.WTS_CURRENT_SERVER_HANDLE

    currentSessId = ts.WTSGetActiveConsoleSessionId()

    format = "%(user)-16s %(active)1s%(session)-7s %(id)-7s %(protocol)-8s"
    print >> outFh, format % dict(
        user = "USER",
        active = "",
        session = "SESSION",
        id = "ID",
        protocol = "PROTOCOL",
    )

    for session in ts.WTSEnumerateSessions(hserver):
        sessionId = session["SessionId"]
        session["User"] = ts.WTSQuerySessionInformation(hserver, sessionId, ts.WTSUserName)
        #session["Address"] = ts.WTSQuerySessionInformation(hserver, sessionId, ts.WTSClientAddress)
        session["Protocol"] = ts.WTSQuerySessionInformation(hserver, sessionId, ts.WTSClientProtocolType)
        print >> outFh, format % dict(
            user = session["User"] or "(none)",
            session = session["WinStationName"],
            id = "(%d)" % session["SessionId"],
            active = "*" if sessionId == currentSessId else "",
            protocol = protocols[session["Protocol"]],
        ) 
開發者ID:grawity,項目名稱:code,代碼行數:35,代碼來源:fingerd.py

示例9: getSysInfo

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import GetComputerName [as 別名]
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") 
開發者ID:ActiveState,項目名稱:code,代碼行數:56,代碼來源:recipe-265858.py


注:本文中的win32api.GetComputerName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。