Python win32com.client.GetObject() Examples
The following are 16
code examples of win32com.client.GetObject().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
win32com.client
, or try the search function
.
Example #1
Source File: install.py From ironpython2 with Apache License 2.0 | 6 votes |
def LocateWebServerPath(description): """ Find an IIS web server whose name or comment matches the provided description (case-insensitive). >>> LocateWebServerPath('Default Web Site') # doctest: +SKIP or >>> LocateWebServerPath('1') #doctest: +SKIP """ assert len(description) >= 1, "Server name or comment is required" iis = GetObject(_IIS_OBJECT) description = description.lower().strip() for site in iis: # Name is generally a number, but no need to assume that. site_attributes = [getattr(site, attr, "").lower().strip() for attr in ("Name", "ServerComment")] if description in site_attributes: return site.AdsPath msg = "No web sites match the description '%s'" % description raise ItemNotFound(msg)
Example #2
Source File: install.py From ironpython2 with Apache License 2.0 | 6 votes |
def CreateISAPIFilter(filterParams, options): server = FindWebServer(options, filterParams.Server) _CallHook(filterParams, "PreInstall", options) try: filters = GetObject(server+"/Filters") except pythoncom.com_error, exc: # Brand new sites don't have the '/Filters' collection - create it. # Any errors other than 'not found' we shouldn't ignore. if winerror.HRESULT_FACILITY(exc.hresult) != winerror.FACILITY_WIN32 or \ winerror.HRESULT_CODE(exc.hresult) != winerror.ERROR_PATH_NOT_FOUND: raise server_ob = GetObject(server) filters = server_ob.Create(_IIS_FILTERS, "Filters") filters.FilterLoadOrder = "" filters.SetInfo() # As for VirtualDir, delete an existing one.
Example #3
Source File: wmi.py From opsbro with MIT License | 6 votes |
def Registry( computer=None, impersonation_level="Impersonate", authentication_level="Default", authority=None, privileges=None, moniker=None ): warnings.warn("This function can be implemented using wmi.WMI (namespace='DEFAULT').StdRegProv", DeprecationWarning) if not moniker: moniker = construct_moniker( computer=computer, impersonation_level=impersonation_level, authentication_level=authentication_level, authority=authority, privileges=privileges, namespace="default", suffix="StdRegProv" ) try: return _wmi_object(GetObject(moniker)) except pywintypes.com_error: handle_com_error()
Example #4
Source File: install.py From ironpython2 with Apache License 2.0 | 5 votes |
def LoadWebServer(path): try: server = GetObject(path) except pythoncom.com_error, details: msg = details.strerror if exc.excepinfo and exc.excepinfo[2]: msg = exc.excepinfo[2] msg = "WebServer %s: %s" % (path, msg) raise ItemNotFound(msg)
Example #5
Source File: install.py From ironpython2 with Apache License 2.0 | 5 votes |
def CreateDirectory(params, options): _CallHook(params, "PreInstall", options) if not params.Name: raise ConfigurationError("No Name param") parent, name = params.split_path() target_dir = GetObject(FindPath(options, params.Server, parent)) if not params.is_root(): target_dir = _CreateDirectory(target_dir, name, params) AssignScriptMaps(params.ScriptMaps, target_dir, params.ScriptMapUpdate) _CallHook(params, "PostInstall", options, target_dir) log(1, "Configured Virtual Directory: %s" % (params.Name,)) return target_dir
Example #6
Source File: install.py From ironpython2 with Apache License 2.0 | 5 votes |
def DeleteISAPIFilter(filterParams, options): _CallHook(filterParams, "PreRemove", options) server = FindWebServer(options, filterParams.Server) ob_path = server+"/Filters" try: filters = GetObject(ob_path) except pythoncom.com_error, details: # failure to open the filters just means a totally clean IIS install # (IIS5 at least has no 'Filters' key when freshly installed). log(2, "ISAPI filter path '%s' did not exist." % (ob_path,)) return
Example #7
Source File: install.py From ironpython2 with Apache License 2.0 | 5 votes |
def _DeleteExtensionFileRecord(module, options): try: ob = GetObject(_IIS_OBJECT) ob.DeleteExtensionFileRecord(module) log(2, "Deleted extension file record for '%s'" % module) except (pythoncom.com_error, AttributeError), details: log(2, "Failed to remove extension file '%s': %s" % (module, details))
Example #8
Source File: install.py From ironpython2 with Apache License 2.0 | 5 votes |
def RemoveDirectory(params, options): if params.is_root(): return try: directory = GetObject(FindPath(options, params.Server, params.Name)) except pythoncom.com_error, details: rc = _GetWin32ErrorCode(details) if rc != winerror.ERROR_PATH_NOT_FOUND: raise log(2, "VirtualDirectory '%s' did not exist" % params.Name) directory = None
Example #9
Source File: install.py From ironpython2 with Apache License 2.0 | 5 votes |
def RemoveScriptMaps(vd_params, options): "Remove script maps from the already installed virtual directory" parent, name = vd_params.split_path() target_dir = GetObject(FindPath(options, vd_params.Server, parent)) installed_maps = list(target_dir.ScriptMaps) for _map in map(str, vd_params.ScriptMaps): if _map in installed_maps: installed_maps.remove(_map) target_dir.ScriptMaps = installed_maps target_dir.SetInfo()
Example #10
Source File: testWMI.py From ironpython2 with Apache License 2.0 | 5 votes |
def testit(self): cses = GetObject("WinMgMts:").InstancesOf("Win32_Process") vals = [] for cs in cses: val = cs.Properties_("Caption").Value vals.append(val) self.failIf(len(vals)<5, "We only found %d processes!" % len(vals))
Example #11
Source File: recipe-576730.py From code with MIT License | 5 votes |
def isRunning(app): WMI = GetObject('winmgmts:') app = replace(app,"\\","\\\\") return(len(WMI.ExecQuery('select * from Win32_Process where ExecutablePath="%s"'%app))!=0)
Example #12
Source File: recipe-576730.py From code with MIT License | 5 votes |
def killAll(appList): WMI = GetObject('winmgmts:') for app in appList: app = replace(app,"\\","\\\\") processes = WMI.ExecQuery('select * from Win32_Process where ExecutablePath="%s"'%app) for process in processes: try: process.Terminate() except TypeError: raise
Example #13
Source File: wmi.py From opsbro with MIT License | 5 votes |
def __init__(self, namespace, wmi_class): _wmi_object.__init__(self, wmi_class) _set(self, "_class_name", wmi_class.Path_.Class) if namespace: _set(self, "_namespace", namespace) else: class_moniker = wmi_class.Path_.DisplayName winmgmts, namespace_moniker, class_name = class_moniker.split(":") namespace = _wmi_namespace(GetObject(winmgmts + ":" + namespace_moniker), False) _set(self, "_namespace", namespace)
Example #14
Source File: Utils.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def GetPids(processName = None, hwnd = None): if processName: pass elif hwnd: return PyGetWindowThreadProcessId(hwnd)[::-1] else: return False try: pids = [] for proc in GetObject("winmgmts:").ExecQuery("SELECT * FROM Win32_Process WHERE Name = '" + str(processName.replace("'", "\\'")) + "'"): pids.append(proc.ProcessID) return pids except: return False # now implemented as C function in cFunctions.pyd #def GetProcessName(pid): # # See http://msdn2.microsoft.com/en-us/library/ms686701.aspx # hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0) # pe32 = PROCESSENTRY32() # pe32.dwSize = sizeof(PROCESSENTRY32) # try: # if Process32First(hProcessSnap, byref(pe32)) == 0: # print >> sys.stderr, "Failed getting first process." # return "<not found>" # while True: # if pe32.th32ProcessID == pid: # return pe32.szExeFile # if Process32Next(hProcessSnap, byref(pe32)) == 0: # break # return "<not found>" # finally: # CloseHandle(hProcessSnap)
Example #15
Source File: Utils.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def GetProcessNameEx(pid = None, hwnd = None, fullPath = False): if pid: pass elif hwnd: pid = PyGetWindowThreadProcessId(hwnd)[-1] else: return False try: result = GetObject("winmgmts:").ExecQuery("SELECT * FROM Win32_Process WHERE ProcessID = '" + str(int(pid)) + "'")[0] return result.ExecutablePath.strip('"') if fullPath else result.Name except: return False
Example #16
Source File: Utils.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def ProcessExists(pid): try: return bool(GetObject("winmgmts:").ExecQuery("SELECT * FROM Win32_Process WHERE ProcessId = " + str(int(pid))).count) except: return False