本文整理汇总了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
示例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)
示例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
示例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
示例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()
示例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"
示例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")
示例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"]],
)
示例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")