Python pythoncom.IID_IPersistFile() Examples

The following are 25 code examples of pythoncom.IID_IPersistFile(). 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 pythoncom , or try the search function .
Example #1
Source File: Shortcut.py    From EventGhost with GNU General Public License v2.0 6 votes vote down vote up
def Get(cls, filename):
        sh = pythoncom.CoCreateInstance(
            shell.CLSID_ShellLink,
            None,
            pythoncom.CLSCTX_INPROC_SERVER,
            shell.IID_IShellLink
        )
        persist = sh.QueryInterface(pythoncom.IID_IPersistFile).Load(filename)  # NOQA
        self = cls()
        self.path = filename
        self.target = sh.GetPath(shell.SLGP_SHORTPATH)[0]
        self.description = sh.GetDescription()
        self.arguments = sh.GetArguments()
        self.startIn = sh.GetWorkingDirectory()
        self.icons = sh.GetIconLocation()
        return self 
Example #2
Source File: testcomext.py    From ConTroll_Remote_Access_Trojan with Apache License 2.0 6 votes vote down vote up
def CreateShortCut(Path, Target,Arguments = "", StartIn = "", Icon = ("",0), Description = ""):
    # Get the shell interface.
    sh = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, \
        pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)

    # Get an IPersist interface
    persist = sh.QueryInterface(pythoncom.IID_IPersistFile)

    # Set the data
    sh.SetPath(Target)
    sh.SetDescription(Description)
    sh.SetArguments(Arguments)
    sh.SetWorkingDirectory(StartIn)
    sh.SetIconLocation(Icon[0],Icon[1])
#    sh.SetShowCmd( win32con.SW_SHOWMINIMIZED)

    # Save the link itself.
    persist.Save(Path, 1)
    print "Saved to", Path 
Example #3
Source File: shortcut.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def save( self, filename ):
        """Write the shortcut to disk.

        The file should be named something.lnk.
        """
        self._base.QueryInterface(pythoncom.IID_IPersistFile).Save(filename, 0) 
Example #4
Source File: keyboard_recording_trojan.py    From keyboard_recording_trojan with MIT License 5 votes vote down vote up
def set_shortcut(filename,lnkname,iconname):
    shortcut = pythoncom.CoCreateInstance(
    shell.CLSID_ShellLink, None,
    pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
    shortcut.SetPath(filename)
    shortcut.SetIconLocation(iconname,0)
    if os.path.splitext(lnkname)[-1] != '.lnk':
        lnkname += ".lnk"
    shortcut.QueryInterface(pythoncom.IID_IPersistFile).Save(lnkname,0)
    
#如果是远程监听某个电脑,可以将获取到的信息通过邮件发出去 
Example #5
Source File: windows_post_install.py    From GridCal with GNU General Public License v3.0 5 votes vote down vote up
def create_shortcut(path, description, filename,
                        arguments="", workdir="", iconpath="", iconindex=0):
        try:
            import pythoncom
        except ImportError:
            print("pywin32 is required to run this script manually",
                  file=sys.stderr)
            sys.exit(1)
        from win32com.shell import shell, shellcon  # analysis:ignore

        ilink = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None,
                                           pythoncom.CLSCTX_INPROC_SERVER,
                                           shell.IID_IShellLink)
        ilink.SetPath(path)
        ilink.SetDescription(description)
        if arguments:
            ilink.SetArguments(arguments)
        if workdir:
            ilink.SetWorkingDirectory(workdir)
        if iconpath or iconindex:
            ilink.SetIconLocation(iconpath, iconindex)
        # now save it.
        ipf = ilink.QueryInterface(pythoncom.IID_IPersistFile)
        ipf.Save(filename, 0)

    # Support the same list of "path names" as bdist_wininst. 
Example #6
Source File: create_link.py    From Email_My_PC with MIT License 5 votes vote down vote up
def load( self, filename ):
		# Get an IPersist interface
		# which allows save/restore of object to/from files
		self._base.QueryInterface( pythoncom.IID_IPersistFile ).Load( filename ) 
Example #7
Source File: IUniformResourceLocator.py    From Email_My_PC with MIT License 5 votes vote down vote up
def save( self, filename ):
		self._base.QueryInterface( pythoncom.IID_IPersistFile ).Save( filename, 1 ) 
Example #8
Source File: IUniformResourceLocator.py    From Email_My_PC with MIT License 5 votes vote down vote up
def load( self, filename ):
		# Get an IPersist interface
		# which allows save/restore of object to/from files
		self._base.QueryInterface( pythoncom.IID_IPersistFile ).Load( filename ) 
Example #9
Source File: dump_link.py    From Email_My_PC with MIT License 5 votes vote down vote up
def DumpLink(fname):
	shellLink = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
	persistFile = shellLink.QueryInterface(pythoncom.IID_IPersistFile)
	persistFile.Load(fname,STGM_READ)
	shellLink.Resolve(0, shell.SLR_ANY_MATCH | shell.SLR_NO_UI)
	fname, findData = shellLink.GetPath(0)
	print "Filename:", fname, ", UNC=", shellLink.GetPath(shell.SLGP_UNCPRIORITY)[0]
	print "Description:", shellLink.GetDescription()
	print "Working Directory:", shellLink.GetWorkingDirectory()
	print "Icon:", shellLink.GetIconLocation() 
Example #10
Source File: Email My PC.py    From Email_My_PC with MIT License 5 votes vote down vote up
def set_shortcut():
	startup_path = shell.SHGetPathFromIDList(shell.SHGetSpecialFolderLocation(0,shellcon.CSIDL_STARTUP))
	shortcut = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, \
		shell.IID_IShellLink)
	shortcut.SetPath(os.getcwd()+'\\Email My PC Launcher.exe')
	shortcut.SetWorkingDirectory(os.getcwd())
	shortcut.SetIconLocation(os.getcwd()+'\\ui\\images\\Icon.ico',0)
	shortcut.QueryInterface(pythoncom.IID_IPersistFile).Save(startup_path+'\\Emai My PC.lnk',0)

#删除开机启动快捷方式 
Example #11
Source File: Shortcut.py    From EventGhost with GNU General Public License v2.0 5 votes vote down vote up
def Create(
        cls,
        path,
        target,
        arguments="",
        startIn="",
        icon=("", 0),
        description=""
    ):
        """Create a Windows shortcut:

        path - As what file should the shortcut be created?
        target - What command should the desktop use?
        arguments - What arguments should be supplied to the command?
        startIn - What folder should the command start in?
        icon - (filename, index) What icon should be used for the shortcut?
        description - What description should the shortcut be given?

        eg
        Shortcut.Create(
            path=os.path.join (desktop (), "PythonI.lnk"),
            target=r"c:\python\python.exe",
            icon=(r"c:\python\python.exe", 0),
            description="Python Interpreter"
        )
        """
        sh = pythoncom.CoCreateInstance(
            shell.CLSID_ShellLink,
            None,
            pythoncom.CLSCTX_INPROC_SERVER,
            shell.IID_IShellLink
        )
        sh.SetPath(target)
        sh.SetDescription(description)
        sh.SetArguments(arguments)
        sh.SetWorkingDirectory(startIn)
        sh.SetIconLocation(icon[0], icon[1])
        persist = sh.QueryInterface(pythoncom.IID_IPersistFile)
        persist.Save(path, 1) 
Example #12
Source File: shortcut.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def save( self, filename ):
        """Write the shortcut to disk.

        The file should be named something.lnk.
        """
        self._base.QueryInterface(pythoncom.IID_IPersistFile).Save(filename, 0) 
Example #13
Source File: shortcut.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def load( self, filename ):
        """Read a shortcut file from disk."""
        self._base.QueryInterface(pythoncom.IID_IPersistFile).Load(filename) 
Example #14
Source File: dump_link.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def DumpLink(fname):
	shellLink = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
	persistFile = shellLink.QueryInterface(pythoncom.IID_IPersistFile)
	persistFile.Load(fname,STGM_READ)
	shellLink.Resolve(0, shell.SLR_ANY_MATCH | shell.SLR_NO_UI)
	fname, findData = shellLink.GetPath(0)
	print "Filename:", fname, ", UNC=", shellLink.GetPath(shell.SLGP_UNCPRIORITY)[0]
	print "Description:", shellLink.GetDescription()
	print "Working Directory:", shellLink.GetWorkingDirectory()
	print "Icon:", shellLink.GetIconLocation() 
Example #15
Source File: shortcut.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def load( self, filename ):
        """Read a shortcut file from disk."""
        self._base.QueryInterface(pythoncom.IID_IPersistFile).Load(filename) 
Example #16
Source File: recipe-576437.py    From code with MIT License 5 votes vote down vote up
def __init__(self, lnkname):
        self.shortcut = pythoncom.CoCreateInstance(
            shell.CLSID_ShellLink, None,
            pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
        self.shortcut.QueryInterface(pythoncom.IID_IPersistFile).Load(lnkname) 
Example #17
Source File: utils.py    From winpython with MIT License 5 votes vote down vote up
def create_shortcut(
    path,
    description,
    filename,
    arguments="",
    workdir="",
    iconpath="",
    iconindex=0,
):
    """Create Windows shortcut (.lnk file)"""
    import pythoncom
    from win32com.shell import shell

    ilink = pythoncom.CoCreateInstance(
        shell.CLSID_ShellLink,
        None,
        pythoncom.CLSCTX_INPROC_SERVER,
        shell.IID_IShellLink,
    )
    ilink.SetPath(path)
    ilink.SetDescription(description)
    if arguments:
        ilink.SetArguments(arguments)
    if workdir:
        ilink.SetWorkingDirectory(workdir)
    if iconpath or iconindex:
        ilink.SetIconLocation(iconpath, iconindex)
    # now save it.
    ipf = ilink.QueryInterface(pythoncom.IID_IPersistFile)
    if not filename.endswith('.lnk'):
        filename += '.lnk'
    ipf.Save(filename, 0)


# =============================================================================
# Misc.
# ============================================================================= 
Example #18
Source File: shortcut.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def save(self, filename):
        """
        Write the shortcut to disk.

        The file should be named something.lnk.
        """
        self._base.QueryInterface(pythoncom.IID_IPersistFile).Save(
            os.path.abspath(filename), 0) 
Example #19
Source File: shortcut.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def load(self, filename):
        """
        Read a shortcut file from disk.
        """
        self._base.QueryInterface(pythoncom.IID_IPersistFile).Load(
            os.path.abspath(filename)) 
Example #20
Source File: shortcut.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def save( self, filename ):
        """Write the shortcut to disk.

        The file should be named something.lnk.
        """
        self._base.QueryInterface(pythoncom.IID_IPersistFile).Save(filename, 0) 
Example #21
Source File: shortcut.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def load( self, filename ):
        """Read a shortcut file from disk."""
        self._base.QueryInterface(pythoncom.IID_IPersistFile).Load(filename) 
Example #22
Source File: create_link.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def save( self, filename ):
		self._base.QueryInterface( pythoncom.IID_IPersistFile ).Save( filename, 0 ) 
Example #23
Source File: create_link.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def load( self, filename ):
		# Get an IPersist interface
		# which allows save/restore of object to/from files
		self._base.QueryInterface( pythoncom.IID_IPersistFile ).Load( filename ) 
Example #24
Source File: IUniformResourceLocator.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def save( self, filename ):
		self._base.QueryInterface( pythoncom.IID_IPersistFile ).Save( filename, 1 ) 
Example #25
Source File: IUniformResourceLocator.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def load( self, filename ):
		# Get an IPersist interface
		# which allows save/restore of object to/from files
		self._base.QueryInterface( pythoncom.IID_IPersistFile ).Load( filename )