Python win32api 模块,GetModuleFileName() 实例源码

我们从Python开源项目中,提取了以下12个代码示例,用于说明如何使用win32api.GetModuleFileName()

项目:purelove    作者:hucmosin    | 项目源码 | 文件源码
def RegisterCoreDLL(coredllName = None):
    """Registers the core DLL in the registry.

        If no params are passed, the name of the Python DLL used in 
        the current process is used and registered.
    """
    if coredllName is None:
        coredllName = win32api.GetModuleFileName(sys.dllhandle)
        # must exist!
    else:
        try:
            os.stat(coredllName)
        except os.error:
            print "Warning: Registering non-existant core DLL %s" % coredllName

    hKey = win32api.RegCreateKey(GetRootKey() , BuildDefaultPythonKey())
    try:
        win32api.RegSetValue(hKey, "Dll", win32con.REG_SZ, coredllName)
    finally:
        win32api.RegCloseKey(hKey)
    # Lastly, setup the current version to point to me.
    win32api.RegSetValue(GetRootKey(), "Software\\Python\\PythonCore\\CurrentVersion", win32con.REG_SZ, sys.winver)
项目:code    作者:ActiveState    | 项目源码 | 文件源码
def which_file(fname):
    """prints paths for fname where fname can be found,
    in case of .dll loads it"""
    files = []
    path = win32api.GetEnvironmentVariable('PATH')
    # try paths as described in MSDN
    dirs = [os.getcwd(), win32api.GetSystemDirectory(), win32api.GetWindowsDirectory()] + path.split(';')
    dirs_norm = []
    dirs_l = []
    for d in dirs:
        dn = d.lower()
        if dn not in dirs_l:
            dirs_l.append(dn)
            dirs_norm.append(d)
    for d in dirs_norm:
        fname2 = os.path.join(d, fname)
        if os.path.exists(fname2):
            if fname2 not in files:
                files.append(fname2)
    if files:
        print('\n'.join([get_file_info(f) for f in files]))
    h = 0
    if fname.lower().endswith('.dll'):
        print('\ttrying to load "%s" ...' % (fname))
        try:
            h = win32api.LoadLibrary(fname)
            if h:
                dll_name = win32api.GetModuleFileName(h)
                print('\t%s loaded' % (dll_name))
        except:
            print('\tCannot load "%s" !!!' % (fname))
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def RegisterCoreDLL(coredllName = None):
    """Registers the core DLL in the registry.

        If no params are passed, the name of the Python DLL used in 
        the current process is used and registered.
    """
    if coredllName is None:
        coredllName = win32api.GetModuleFileName(sys.dllhandle)
        # must exist!
    else:
        try:
            os.stat(coredllName)
        except os.error:
            print "Warning: Registering non-existant core DLL %s" % coredllName

    hKey = win32api.RegCreateKey(GetRootKey() , BuildDefaultPythonKey())
    try:
        win32api.RegSetValue(hKey, "Dll", win32con.REG_SZ, coredllName)
    finally:
        win32api.RegCloseKey(hKey)
    # Lastly, setup the current version to point to me.
    win32api.RegSetValue(GetRootKey(), "Software\\Python\\PythonCore\\CurrentVersion", win32con.REG_SZ, sys.winver)
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def RegisterCoreDLL(coredllName = None):
    """Registers the core DLL in the registry.

        If no params are passed, the name of the Python DLL used in 
        the current process is used and registered.
    """
    if coredllName is None:
        coredllName = win32api.GetModuleFileName(sys.dllhandle)
        # must exist!
    else:
        try:
            os.stat(coredllName)
        except os.error:
            print("Warning: Registering non-existant core DLL %s" % coredllName)

    hKey = win32api.RegCreateKey(GetRootKey() , BuildDefaultPythonKey())
    try:
        win32api.RegSetValue(hKey, "Dll", win32con.REG_SZ, coredllName)
    finally:
        win32api.RegCloseKey(hKey)
    # Lastly, setup the current version to point to me.
    win32api.RegSetValue(GetRootKey(), "Software\\Python\\PythonCore\\CurrentVersion", win32con.REG_SZ, sys.winver)
项目:OSPTF    作者:xSploited    | 项目源码 | 文件源码
def testHost(self):
        file = win32api.GetFullPathName(os.path.join(win32com.axscript.__path__[0], "test\\testHost.py"))
        cmd = '%s "%s"' % (win32api.GetModuleFileName(0), file)
        if verbose:
            print "Testing Python Scripting host"
        win32com.test.util.ExecuteShellCommand(cmd, self)
项目:pupy    作者:ru-faraon    | 项目源码 | 文件源码
def testHost(self):
        file = win32api.GetFullPathName(os.path.join(win32com.axscript.__path__[0], "test\\testHost.py"))
        cmd = '%s "%s"' % (win32api.GetModuleFileName(0), file)
        if verbose:
            print "Testing Python Scripting host"
        win32com.test.util.ExecuteShellCommand(cmd, self)
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def testHost(self):
        file = win32api.GetFullPathName(os.path.join(win32com.axscript.__path__[0], "test\\testHost.py"))
        cmd = '%s "%s"' % (win32api.GetModuleFileName(0), file)
        if verbose:
            print "Testing Python Scripting host"
        win32com.test.util.ExecuteShellCommand(cmd, self)
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def testHost(self):
        file = win32api.GetFullPathName(os.path.join(win32com.axscript.__path__[0], "test\\testHost.py"))
        cmd = '%s "%s"' % (win32api.GetModuleFileName(0), file)
        if verbose:
            print("Testing Python Scripting host")
        win32com.test.util.ExecuteShellCommand(cmd, self)
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def RegisterPythonServer(filename, progids=None, verbose=0):
    if progids:
        if isinstance(progids, str):
            progids = [progids]
        # we know the CLSIDs we need, but we might not be an admin user
        # and otherwise unable to register them.  So as long as the progids
        # exist and the DLL points at our version, assume it already is.
        why_not = None
        for progid in progids:
            try:
                clsid = pythoncom.MakeIID(progid)
            except pythoncom.com_error:
                # no progid - not registered.
                break
            # have a CLSID - open it.
            try:
                HKCR = winreg.HKEY_CLASSES_ROOT
                hk = winreg.OpenKey(HKCR, "CLSID\\%s" % clsid)
                dll = winreg.QueryValue(hk, "InprocServer32")
            except WindowsError:
                # no CLSID or InProcServer32 - not good!
                break
            ok_files = [os.path.basename(pythoncom.__file__),
                        'pythoncomloader%d%d.dll' % (sys.version_info[0], sys.version_info[1])]
            if os.path.basename(dll) not in ok_files:
                why_not = "%r is registered against a different Python version (%s)" % (progid, dll)
                break
        else:
            #print "Skipping registration of '%s' - already registered" % filename
            return
    # needs registration - see if its likely!
    try:
        from win32com.shell.shell import IsUserAnAdmin
    except ImportError:
        print("Can't import win32com.shell - no idea if you are an admin or not?")
        is_admin = False
    else:
        try:
            is_admin = IsUserAnAdmin()
        except pythoncom.com_error:
            # old, less-secure OS - assume *is* admin.
            is_admin = True
    if not is_admin:
        msg = "%r isn't registered, but I'm not an administrator who can register it." % progids[0]
        if why_not:
            msg += "\n(registration check failed as %s)" % why_not
        # throw a normal "class not registered" exception - we don't report
        # them the same way as "real" errors.
        raise pythoncom.com_error(winerror.CO_E_CLASSSTRING, msg, None, -1)
    # so theoretically we are able to register it.
    cmd = '%s "%s" --unattended > nul 2>&1' % (win32api.GetModuleFileName(0), filename)
    if verbose:
        print("Registering engine", filename)
#       print cmd
    rc = os.system(cmd)
    if rc:
        print("Registration command was:")
        print(cmd)
        raise RuntimeError("Registration of engine '%s' failed" % filename)
项目:OSPTF    作者:xSploited    | 项目源码 | 文件源码
def RegisterPythonServer(filename, progids=None, verbose=0):
    if progids:
        if isinstance(progids, basestring):
            progids = [progids]
        # we know the CLSIDs we need, but we might not be an admin user
        # and otherwise unable to register them.  So as long as the progids
        # exist and the DLL points at our version, assume it already is.
        why_not = None
        for progid in progids:
            try:
                clsid = pythoncom.MakeIID(progid)
            except pythoncom.com_error:
                # no progid - not registered.
                break
            # have a CLSID - open it.
            try:
                HKCR = _winreg.HKEY_CLASSES_ROOT
                hk = _winreg.OpenKey(HKCR, "CLSID\\%s" % clsid)
                dll = _winreg.QueryValue(hk, "InprocServer32")
            except WindowsError:
                # no CLSID or InProcServer32 - not good!
                break
            ok_files = [os.path.basename(pythoncom.__file__),
                        'pythoncomloader%d%d.dll' % (sys.version_info[0], sys.version_info[1])]
            if os.path.basename(dll) not in ok_files:
                why_not = "%r is registered against a different Python version (%s)" % (progid, dll)
                break
        else:
            #print "Skipping registration of '%s' - already registered" % filename
            return
    # needs registration - see if its likely!
    try:
        from win32com.shell.shell import IsUserAnAdmin
    except ImportError:
        print "Can't import win32com.shell - no idea if you are an admin or not?"
        is_admin = False
    else:
        try:
            is_admin = IsUserAnAdmin()
        except pythoncom.com_error:
            # old, less-secure OS - assume *is* admin.
            is_admin = True
    if not is_admin:
        msg = "%r isn't registered, but I'm not an administrator who can register it." % progids[0]
        if why_not:
            msg += "\n(registration check failed as %s)" % why_not
        # throw a normal "class not registered" exception - we don't report
        # them the same way as "real" errors.
        raise pythoncom.com_error(winerror.CO_E_CLASSSTRING, msg, None, -1)
    # so theoretically we are able to register it.
    cmd = '%s "%s" --unattended > nul 2>&1' % (win32api.GetModuleFileName(0), filename)
    if verbose:
        print "Registering engine", filename
#       print cmd
    rc = os.system(cmd)
    if rc:
        print "Registration command was:"
        print cmd
        raise RuntimeError("Registration of engine '%s' failed" % filename)
项目:pupy    作者:ru-faraon    | 项目源码 | 文件源码
def RegisterPythonServer(filename, progids=None, verbose=0):
    if progids:
        if isinstance(progids, basestring):
            progids = [progids]
        # we know the CLSIDs we need, but we might not be an admin user
        # and otherwise unable to register them.  So as long as the progids
        # exist and the DLL points at our version, assume it already is.
        why_not = None
        for progid in progids:
            try:
                clsid = pythoncom.MakeIID(progid)
            except pythoncom.com_error:
                # no progid - not registered.
                break
            # have a CLSID - open it.
            try:
                HKCR = _winreg.HKEY_CLASSES_ROOT
                hk = _winreg.OpenKey(HKCR, "CLSID\\%s" % clsid)
                dll = _winreg.QueryValue(hk, "InprocServer32")
            except WindowsError:
                # no CLSID or InProcServer32 - not good!
                break
            ok_files = [os.path.basename(pythoncom.__file__),
                        'pythoncomloader%d%d.dll' % (sys.version_info[0], sys.version_info[1])]
            if os.path.basename(dll) not in ok_files:
                why_not = "%r is registered against a different Python version (%s)" % (progid, dll)
                break
        else:
            #print "Skipping registration of '%s' - already registered" % filename
            return
    # needs registration - see if its likely!
    try:
        from win32com.shell.shell import IsUserAnAdmin
    except ImportError:
        print "Can't import win32com.shell - no idea if you are an admin or not?"
        is_admin = False
    else:
        try:
            is_admin = IsUserAnAdmin()
        except pythoncom.com_error:
            # old, less-secure OS - assume *is* admin.
            is_admin = True
    if not is_admin:
        msg = "%r isn't registered, but I'm not an administrator who can register it." % progids[0]
        if why_not:
            msg += "\n(registration check failed as %s)" % why_not
        # throw a normal "class not registered" exception - we don't report
        # them the same way as "real" errors.
        raise pythoncom.com_error(winerror.CO_E_CLASSSTRING, msg, None, -1)
    # so theoretically we are able to register it.
    cmd = '%s "%s" --unattended > nul 2>&1' % (win32api.GetModuleFileName(0), filename)
    if verbose:
        print "Registering engine", filename
#       print cmd
    rc = os.system(cmd)
    if rc:
        print "Registration command was:"
        print cmd
        raise RuntimeError("Registration of engine '%s' failed" % filename)
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def RegisterPythonServer(filename, progids=None, verbose=0):
    if progids:
        if isinstance(progids, basestring):
            progids = [progids]
        # we know the CLSIDs we need, but we might not be an admin user
        # and otherwise unable to register them.  So as long as the progids
        # exist and the DLL points at our version, assume it already is.
        why_not = None
        for progid in progids:
            try:
                clsid = pythoncom.MakeIID(progid)
            except pythoncom.com_error:
                # no progid - not registered.
                break
            # have a CLSID - open it.
            try:
                HKCR = _winreg.HKEY_CLASSES_ROOT
                hk = _winreg.OpenKey(HKCR, "CLSID\\%s" % clsid)
                dll = _winreg.QueryValue(hk, "InprocServer32")
            except WindowsError:
                # no CLSID or InProcServer32 - not good!
                break
            ok_files = [os.path.basename(pythoncom.__file__),
                        'pythoncomloader%d%d.dll' % (sys.version_info[0], sys.version_info[1])]
            if os.path.basename(dll) not in ok_files:
                why_not = "%r is registered against a different Python version (%s)" % (progid, dll)
                break
        else:
            #print "Skipping registration of '%s' - already registered" % filename
            return
    # needs registration - see if its likely!
    try:
        from win32com.shell.shell import IsUserAnAdmin
    except ImportError:
        print "Can't import win32com.shell - no idea if you are an admin or not?"
        is_admin = False
    else:
        try:
            is_admin = IsUserAnAdmin()
        except pythoncom.com_error:
            # old, less-secure OS - assume *is* admin.
            is_admin = True
    if not is_admin:
        msg = "%r isn't registered, but I'm not an administrator who can register it." % progids[0]
        if why_not:
            msg += "\n(registration check failed as %s)" % why_not
        # throw a normal "class not registered" exception - we don't report
        # them the same way as "real" errors.
        raise pythoncom.com_error(winerror.CO_E_CLASSSTRING, msg, None, -1)
    # so theoretically we are able to register it.
    cmd = '%s "%s" --unattended > nul 2>&1' % (win32api.GetModuleFileName(0), filename)
    if verbose:
        print "Registering engine", filename
#       print cmd
    rc = os.system(cmd)
    if rc:
        print "Registration command was:"
        print cmd
        raise RuntimeError("Registration of engine '%s' failed" % filename)