Menú

Mostrar Mensajes

Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.

Mostrar Mensajes Menú

Mensajes - Eleкtro

#7711
Shortcut Manager

Resuelve el target de shortcut "corrupto", crea un nuevo shortcut u obtiene información de un shortcut.

Código (vbnet) [Seleccionar]
Imports System.Runtime.InteropServices
Imports System.Text
Imports System.IO

#Region " ShortcutManager "

' [ ShortcutManager ]
'
' // By Elektro H@cker

#Region " Usage Examples "

'Private Sub Test()

'    ' Tries to resolve a shortcut which has changed their Target location.
'    ShortcutManager.Resolve_Ui("C:\Truncated Shortcut.lnk", New IntPtr(1))
'    ShortcutManager.Resolve_NoUi("C:\Truncated Shortcut.lnk")

'    ' Creates a new Shortcut file
'    ShortcutManager.Create("C:\Shortcut.lnk",
'                           "C:\TargetFile.ext",
'                           "C:\",
'                           "Description",
'                           "-Arguments",
'                           "C:\Icon.ico", 0,
'                           ShortcutManager.HotkeyModifiers.ALT Or ShortcutManager.HotkeyModifiers.CONTROL,
'                           Keys.F1,
'                           ShortcutManager.ShortcutWindowState.Normal)

'    ' Gets Shortcut file information
'    Dim ShortcutInfo As ShortcutManager.ShortcutInfo =
'        ShortcutManager.GetInfo("C:\Shortcut.lnk")

'    Dim sb As New System.Text.StringBuilder

'    With ShortcutInfo

'        sb.AppendLine(String.Format(" ""{0}"" ", .ShortcutFile))
'        sb.AppendLine(String.Format("------------------------"))
'        sb.AppendLine(String.Format("Description: {0}", .Description))
'        sb.AppendLine(String.Format("Target: {0}", .Target))
'        sb.AppendLine(String.Format("Arguments: {0}", .Arguments))
'        sb.AppendLine(String.Format("Target Is Directory?: {0}", CStr(.IsDirectory)))
'        sb.AppendLine(String.Format("Target Is File?: {0}", CStr(.IsFile)))
'        sb.AppendLine(String.Format("WorkingDir: {0}", .WorkingDir))
'        sb.AppendLine(String.Format("DirectoryName: {0}", .DirectoryName))
'        sb.AppendLine(String.Format("FileName: {0}", .FileName))
'        sb.AppendLine(String.Format("FileExtension: {0}", .FileExtension))
'        sb.AppendLine(String.Format("DriveLetter: {0}", .DriveLetter))
'        sb.AppendLine(String.Format("Icon: {0}", .Icon))
'        sb.AppendLine(String.Format("Icon Index: {0}", CStr(.IconIndex)))
'        sb.AppendLine(String.Format("Hotkey (Hex): {0}", CStr(.Hotkey)))
'        sb.AppendLine(String.Format("Hotkey (Str): {0} + {1}", .Hotkey_Modifier.ToString, .Hotkey_Key.ToString))
'        sb.AppendLine(String.Format("Window State: {0}", .WindowState.ToString))

'    End With

'    MsgBox(sb.ToString)

'End Sub

#End Region

Public Class ShortcutManager

#Region " Variables "

    Private Shared lnk As New ShellLink()
    Private Shared lnk_data As New WIN32_FIND_DATAW()

    Private Shared lnk_arguments As New StringBuilder(260)
    Private Shared lnk_description As New StringBuilder(260)
    Private Shared lnk_target As New StringBuilder(260)
    Private Shared lnk_workingdir As New StringBuilder(260)
    Private Shared lnk_iconpath As New StringBuilder(260)
    Private Shared lnk_iconindex As Integer = -1
    Private Shared lnk_hotkey As Short = -1
    Private Shared lnk_windowstate As ShortcutWindowState = ShortcutWindowState.Normal

#End Region

#Region " API, Interfaces, Enumerations "

    <DllImport("shfolder.dll",
    CharSet:=CharSet.Auto)>
    Friend Shared Function SHGetFolderPath(ByVal hwndOwner As IntPtr,
                                           ByVal nFolder As Integer,
                                           ByVal hToken As IntPtr,
                                           ByVal dwFlags As Integer,
                                           ByVal lpszPath As StringBuilder
    ) As Integer
    End Function

    <Flags()>
    Private Enum SLGP_FLAGS

        ''' <summary>
        ''' Retrieves the standard short (8.3 format) file name.
        ''' </summary>
        SLGP_SHORTPATH = &H1

        ''' <summary>
        ''' Retrieves the Universal Naming Convention (UNC) path name of the file.
        ''' </summary>
        SLGP_UNCPRIORITY = &H2

        ''' <summary>
        ''' Retrieves the raw path name.
        ''' A raw path is something that might not exist and may include environment variables that need to be expanded.
        ''' </summary>
        SLGP_RAWPATH = &H4

    End Enum

    <Flags()>
    Private Enum SLR_FLAGS

        ''' <summary>
        ''' Do not display a dialog box if the link cannot be resolved. When SLR_NO_UI is set,
        ''' the high-order word of fFlags can be set to a time-out value that specifies the
        ''' maximum amount of time to be spent resolving the link. The function returns if the
        ''' link cannot be resolved within the time-out duration. If the high-order word is set
        ''' to zero, the time-out duration will be set to the default value of 3,000 milliseconds
        ''' (3 seconds). To specify a value, set the high word of fFlags to the desired time-out
        ''' duration, in milliseconds.
        ''' </summary>
        SLR_NO_UI = &H1

        ''' <summary>
        ''' If the link object has changed, update its path and list of identifiers.
        ''' If SLR_UPDATE is set, you do not need to call IPersistFile::IsDirty to determine,
        ''' whether or not the link object has changed.
        ''' </summary>
        SLR_UPDATE = &H4

        ''' <summary>
        ''' Do not update the link information
        ''' </summary>
        SLR_NOUPDATE = &H8

        ''' <summary>
        ''' Do not execute the search heuristics
        ''' </summary>
        SLR_NOSEARCH = &H10

        ''' <summary>
        ''' Do not use distributed link tracking
        ''' </summary>
        SLR_NOTRACK = &H20

        ''' <summary>
        ''' Disable distributed link tracking.
        ''' By default, distributed link tracking tracks removable media,
        ''' across multiple devices based on the volume name.
        ''' It also uses the Universal Naming Convention (UNC) path to track remote file systems,
        ''' whose drive letter has changed.
        ''' Setting SLR_NOLINKINFO disables both types of tracking.
        ''' </summary>
        SLR_NOLINKINFO = &H40

        ''' <summary>
        ''' Call the Microsoft Windows Installer
        ''' </summary>
        SLR_INVOKE_MSI = &H80

    End Enum

    ''' <summary>
    ''' Stores information about a shortcut file.
    ''' </summary>
    Public Class ShortcutInfo

        ''' <summary>
        ''' Shortcut file full path.
        ''' </summary>
        Public Property ShortcutFile As String

        ''' <summary>
        ''' Shortcut Comment/Description.
        ''' </summary>
        Public Property Description As String

        ''' <summary>
        ''' Shortcut Target Arguments.
        ''' </summary>
        Public Property Arguments As String

        ''' <summary>
        ''' Shortcut Target.
        ''' </summary>
        Public Property Target As String

        ''' <summary>
        ''' Shortcut Working Directory.
        ''' </summary>
        Public Property WorkingDir As String

        ''' <summary>
        ''' Shortcut Icon Location.
        ''' </summary>
        Public Property Icon As String

        ''' <summary>
        ''' Shortcut Icon Index.
        ''' </summary>
        Public Property IconIndex As Integer

        ''' <summary>
        ''' Shortcut Hotkey combination.
        ''' Is represented as Hexadecimal.
        ''' </summary>
        Public Property Hotkey As Short

        ''' <summary>
        ''' Shortcut Hotkey modifiers.
        ''' </summary>
        Public Property Hotkey_Modifier As HotkeyModifiers

        ''' <summary>
        ''' Shortcut Hotkey Combination.
        ''' </summary>
        Public Property Hotkey_Key As Keys

        ''' <summary>
        ''' Shortcut Window State.
        ''' </summary>
        Public Property WindowState As ShortcutWindowState

        ''' <summary>
        ''' Indicates if the target is a file.
        ''' </summary>
        Public Property IsFile As Boolean

        ''' <summary>
        ''' Indicates if the target is a directory.
        ''' </summary>
        Public Property IsDirectory As Boolean

        ''' <summary>
        ''' Shortcut target drive letter.
        ''' </summary>
        Public Property DriveLetter As String

        ''' <summary>
        ''' Shortcut target directory name.
        ''' </summary>
        Public Property DirectoryName As String

        ''' <summary>
        ''' Shortcut target filename.
        ''' (File extension is not included in name)
        ''' </summary>
        Public Property FileName As String

        ''' <summary>
        ''' Shortcut target file extension.
        ''' </summary>
        Public Property FileExtension As String

    End Class

    ''' <summary>
    ''' Hotkey modifiers for a shortcut file.
    ''' </summary>
    <FlagsAttribute()>
    Public Enum HotkeyModifiers As Short

        ''' <summary>
        ''' The SHIFT key.
        ''' </summary>
        SHIFT = 1

        ''' <summary>
        ''' The CTRL key.
        ''' </summary>
        CONTROL = 2

        ''' <summary>
        ''' The ALT key.
        ''' </summary>
        ALT = 4

        ''' <summary>
        ''' None.
        ''' Specifies any hotkey modificator.
        ''' </summary>
        NONE = 0

    End Enum

    ''' <summary>
    ''' The Window States for a shortcut file.
    ''' </summary>
    Public Enum ShortcutWindowState As Integer

        ''' <summary>
        ''' Shortcut Window is at normal state.
        ''' </summary>
        Normal = 1

        ''' <summary>
        ''' Shortcut Window is Maximized.
        ''' </summary>
        Maximized = 3

        ''' <summary>
        ''' Shortcut Window is Minimized.
        ''' </summary>
        Minimized = 7

    End Enum

    <StructLayout(LayoutKind.Sequential,
    CharSet:=CharSet.Auto)>
    Private Structure WIN32_FIND_DATAW
        Public dwFileAttributes As UInteger
        Public ftCreationTime As Long
        Public ftLastAccessTime As Long
        Public ftLastWriteTime As Long
        Public nFileSizeHigh As UInteger
        Public nFileSizeLow As UInteger
        Public dwReserved0 As UInteger
        Public dwReserved1 As UInteger
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)>
        Public cFileName As String
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=14)>
        Public cAlternateFileName As String
    End Structure

    ''' <summary>
    ''' The IShellLink interface allows Shell links to be created, modified, and resolved
    ''' </summary>
    <ComImport(),
    InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
    Guid("000214F9-0000-0000-C000-000000000046")>
    Private Interface IShellLinkW

        ''' <summary>
        ''' Retrieves the path and file name of a Shell link object.
        ''' </summary>
        Sub GetPath(<Out(), MarshalAs(UnmanagedType.LPWStr)>
                    ByVal pszFile As StringBuilder,
                    ByVal cchMaxPath As Integer,
                    ByRef pfd As WIN32_FIND_DATAW,
                    ByVal fFlags As SLGP_FLAGS)

        ''' <summary>
        ''' Retrieves the list of item identifiers for a Shell link object.
        ''' </summary>
        Sub GetIDList(ByRef ppidl As IntPtr)

        ''' <summary>
        ''' Sets the pointer to an item identifier list (PIDL) for a Shell link object.
        ''' </summary>
        Sub SetIDList(ByVal pidl As IntPtr)

        ''' <summary>
        ''' Retrieves the description string for a Shell link object.
        ''' </summary>
        Sub GetDescription(<Out(), MarshalAs(UnmanagedType.LPWStr)>
                           ByVal pszName As StringBuilder,
                           ByVal cchMaxName As Integer)

        ''' <summary>
        ''' Sets the description for a Shell link object.
        ''' The description can be any application-defined string.
        ''' </summary>
        Sub SetDescription(<MarshalAs(UnmanagedType.LPWStr)>
                           ByVal pszName As String)

        ''' <summary>
        ''' Retrieves the name of the working directory for a Shell link object.
        ''' </summary>
        Sub GetWorkingDirectory(<Out(), MarshalAs(UnmanagedType.LPWStr)>
                                ByVal pszDir As StringBuilder,
                                ByVal cchMaxPath As Integer)

        ''' <summary>
        ''' Sets the name of the working directory for a Shell link object.
        ''' </summary>
        Sub SetWorkingDirectory(<MarshalAs(UnmanagedType.LPWStr)>
                                ByVal pszDir As String)

        ''' <summary>
        ''' Retrieves the command-line arguments associated with a Shell link object.
        ''' </summary>
        Sub GetArguments(<Out(), MarshalAs(UnmanagedType.LPWStr)>
                         ByVal pszArgs As StringBuilder,
                         ByVal cchMaxPath As Integer)

        ''' <summary>
        ''' Sets the command-line arguments for a Shell link object.
        ''' </summary>
        Sub SetArguments(<MarshalAs(UnmanagedType.LPWStr)>
                         ByVal pszArgs As String)

        ''' <summary>
        ''' Retrieves the hot key for a Shell link object.
        ''' </summary>
        Sub GetHotkey(ByRef pwHotkey As Short)

        ''' <summary>
        ''' Sets a hot key for a Shell link object.
        ''' </summary>
        Sub SetHotkey(ByVal wHotkey As Short)

        ''' <summary>
        ''' Retrieves the show command for a Shell link object.
        ''' </summary>
        Sub GetShowCmd(ByRef piShowCmd As Integer)

        ''' <summary>
        ''' Sets the show command for a Shell link object.
        ''' The show command sets the initial show state of the window.
        ''' </summary>
        Sub SetShowCmd(ByVal iShowCmd As ShortcutWindowState)

        ''' <summary>
        ''' Retrieves the location (path and index) of the icon for a Shell link object.
        ''' </summary>
        Sub GetIconLocation(<Out(), MarshalAs(UnmanagedType.LPWStr)>
                            ByVal pszIconPath As StringBuilder,
                            ByVal cchIconPath As Integer,
                            ByRef piIcon As Integer)

        ''' <summary>
        ''' Sets the location (path and index) of the icon for a Shell link object.
        ''' </summary>
        Sub SetIconLocation(<MarshalAs(UnmanagedType.LPWStr)>
                            ByVal pszIconPath As String,
                            ByVal iIcon As Integer)

        ''' <summary>
        ''' Sets the relative path to the Shell link object.
        ''' </summary>
        Sub SetRelativePath(<MarshalAs(UnmanagedType.LPWStr)>
                            ByVal pszPathRel As String,
                            ByVal dwReserved As Integer)

        ''' <summary>
        ''' Attempts to find the target of a Shell link,
        ''' even if it has been moved or renamed.
        ''' </summary>
        Sub Resolve(ByVal hwnd As IntPtr,
                    ByVal fFlags As SLR_FLAGS)

        ''' <summary>
        ''' Sets the path and file name of a Shell link object
        ''' </summary>
        Sub SetPath(ByVal pszFile As String)

    End Interface

    <ComImport(), Guid("0000010c-0000-0000-c000-000000000046"),
    InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
    Public Interface IPersist

        <PreserveSig()>
        Sub GetClassID(ByRef pClassID As Guid)

    End Interface

    <ComImport(), Guid("0000010b-0000-0000-C000-000000000046"),
    InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
    Public Interface IPersistFile
        Inherits IPersist

        Shadows Sub GetClassID(ByRef pClassID As Guid)

        <PreserveSig()>
        Function IsDirty() As Integer

        <PreserveSig()>
        Sub Load(<[In](), MarshalAs(UnmanagedType.LPWStr)>
                 pszFileName As String,
                 dwMode As UInteger)

        <PreserveSig()>
        Sub Save(<[In](), MarshalAs(UnmanagedType.LPWStr)>
                 pszFileName As String,
                 <[In](), MarshalAs(UnmanagedType.Bool)>
                 fRemember As Boolean)

        <PreserveSig()>
        Sub SaveCompleted(<[In](), MarshalAs(UnmanagedType.LPWStr)>
                          pszFileName As String)

        <PreserveSig()>
        Sub GetCurFile(<[In](), MarshalAs(UnmanagedType.LPWStr)>
                       ppszFileName As String)

    End Interface

    ' "CLSID_ShellLink" from "ShlGuid.h"
    <ComImport(),
    Guid("00021401-0000-0000-C000-000000000046")>
    Public Class ShellLink
    End Class

#End Region

#Region " Public Methods "

    ''' <summary>
    ''' Resolves the target of a shortcut.
    ''' If shortcut can't be resolved, an error message would be displayed.
    ''' This is usefull when the target path of a shortcut file is changed from a driveletter for example,
    ''' then the shortcut file need to be resolved before trying to retrieve the target path.
    ''' </summary>
    ''' <param name="ShortcutFile">
    ''' The shortcut file to resolve.
    ''' </param>
    ''' <param name="hwnd">
    ''' The new handle pointer that would be generated
    ''' for the window which should display the error message (if any).
    ''' </param>
    Public Shared Sub Resolve_Ui(ShortcutFile As String, hwnd As IntPtr)
        LoadShortcut(ShortcutFile)
        DirectCast(lnk, IShellLinkW).Resolve(hwnd, SLR_FLAGS.SLR_UPDATE)
    End Sub

    ''' <summary>
    ''' Resolves the target of a shortcut.
    ''' If shortcut can't be resolved, any error message would be displayed.
    ''' This is usefull when the target path of a shortcut file is changed from a driveletter for example,
    ''' then the shortcut file need to be resolved before trying to retrieve the target path.
    ''' </summary>
    ''' <param name="ShortcutFile">
    ''' The shortcut file to resolve.
    ''' </param>
    Public Shared Sub Resolve_NoUi(ByVal ShortcutFile As String)
        LoadShortcut(ShortcutFile)
        DirectCast(lnk, IShellLinkW).Resolve(IntPtr.Zero, SLR_FLAGS.SLR_UPDATE Or SLR_FLAGS.SLR_NO_UI)
    End Sub

    ''' <summary>
    ''' Returns the description of a shortcut file.
    ''' </summary>
    ''' <param name="ShortcutFile">
    ''' The shortcut file to retrieve the info.
    ''' </param>
    Public Shared Function Get_Description(ByVal ShortcutFile As String) As String
        LoadShortcut(ShortcutFile)
        lnk_description.Clear()
        DirectCast(lnk, IShellLinkW).GetDescription(lnk_description, lnk_description.Capacity)
        Return lnk_description.ToString()
    End Function

    ''' <summary>
    ''' Returns the Arguments of a shortcut file.
    ''' </summary>
    ''' <param name="ShortcutFile">
    ''' The shortcut file to retrieve the info.
    ''' </param>
    Public Shared Function Get_Arguments(ByVal ShortcutFile As String) As String
        LoadShortcut(ShortcutFile)
        lnk_arguments.Clear()
        DirectCast(lnk, IShellLinkW).GetArguments(lnk_arguments, lnk_arguments.Capacity)
        Return lnk_arguments.ToString()
    End Function

    ''' <summary>
    ''' Returns the path and filename of a shortcut file.
    ''' </summary>
    ''' <param name="ShortcutFile">
    ''' The shortcut file to retrieve the info.
    ''' </param>
    Public Shared Function Get_FullPath(ByVal ShortcutFile As String) As String
        LoadShortcut(ShortcutFile)
        lnk_target.Clear()
        DirectCast(lnk, IShellLinkW).GetPath(lnk_target, lnk_target.Capacity, lnk_data, SLGP_FLAGS.SLGP_UNCPRIORITY)
        Return lnk_target.ToString()
    End Function

    ''' <summary>
    ''' Returns the working directory of a shortcut file.
    ''' </summary>
    ''' <param name="ShortcutFile">
    ''' The shortcut file to retrieve the info.
    ''' </param>
    Public Shared Function Get_WorkingDir(ByVal ShortcutFile As String) As String
        LoadShortcut(ShortcutFile)
        lnk_workingdir.Clear()
        DirectCast(lnk, IShellLinkW).GetWorkingDirectory(lnk_workingdir, lnk_workingdir.Capacity)
        Return lnk_workingdir.ToString()
    End Function

    ''' <summary>
    ''' Returns the Hotkey of a shortcut file.
    ''' </summary>
    ''' <param name="ShortcutFile">
    ''' The shortcut file to retrieve the info.
    ''' </param>
    Public Shared Function Get_Hotkey(ByVal ShortcutFile As String) As Short
        LoadShortcut(ShortcutFile)
        lnk_hotkey = -1
        DirectCast(lnk, IShellLinkW).GetHotkey(lnk_hotkey)
        Return lnk_hotkey
    End Function

    ''' <summary>
    ''' Returns the Window State of a shortcut file.
    ''' </summary>
    ''' <param name="ShortcutFile">
    ''' The shortcut file to retrieve the info.
    ''' </param>
    Public Shared Function Get_WindowStyle(ByVal ShortcutFile As String) As ShortcutWindowState
        LoadShortcut(ShortcutFile)
        DirectCast(lnk, IShellLinkW).GetShowCmd(lnk_windowstate)
        Return lnk_windowstate
    End Function

    ''' <summary>
    ''' Returns the Icon location of a shortcut file.
    ''' </summary>
    ''' <param name="ShortcutFile">
    ''' The shortcut file to retrieve the info.
    ''' </param>
    ''' <param name="IconIndex">
    ''' Optional Integer type variable to store the IconIndex.
    ''' </param>
    Public Shared Function Get_IconLocation(ByVal ShortcutFile As String,
                                            Optional ByRef IconIndex As Integer = 0) As String
        LoadShortcut(ShortcutFile)
        lnk_iconpath.Clear()
        DirectCast(lnk, IShellLinkW).GetIconLocation(lnk_iconpath, lnk_iconpath.Capacity, IconIndex)
        Return lnk_iconpath.ToString()
    End Function

    ''' <summary>
    ''' Retrieves all the information about a shortcut file.
    ''' </summary>
    ''' <param name="ShortcutFile">
    ''' The shortcut file to retrieve the info.
    ''' </param>
    Public Shared Function GetInfo(ByVal ShortcutFile As String) As ShortcutInfo

        ' Load Shortcut
        LoadShortcut(ShortcutFile)

        ' Clean objects
        lnk_description.Clear()
        lnk_arguments.Clear()
        lnk_target.Clear()
        lnk_workingdir.Clear()
        lnk_iconpath.Clear()
        lnk_hotkey = -1
        lnk_iconindex = -1

        ' Retrieve Info
        DirectCast(lnk, IShellLinkW).GetDescription(lnk_description, lnk_description.Capacity)
        DirectCast(lnk, IShellLinkW).GetArguments(lnk_arguments, lnk_arguments.Capacity)
        DirectCast(lnk, IShellLinkW).GetPath(lnk_target, lnk_target.Capacity, lnk_data, SLGP_FLAGS.SLGP_UNCPRIORITY)
        DirectCast(lnk, IShellLinkW).GetWorkingDirectory(lnk_workingdir, lnk_workingdir.Capacity)
        DirectCast(lnk, IShellLinkW).GetIconLocation(lnk_iconpath, lnk_iconpath.Capacity, lnk_iconindex)
        DirectCast(lnk, IShellLinkW).GetHotkey(lnk_hotkey)
        DirectCast(lnk, IShellLinkW).GetShowCmd(lnk_windowstate)

        ' Return Info
        Return New ShortcutInfo With {
            .ShortcutFile = ShortcutFile,
            .Description = lnk_description.ToString,
            .Arguments = lnk_arguments.ToString,
            .Target = lnk_target.ToString,
            .Icon = lnk_iconpath.ToString,
            .IconIndex = lnk_iconindex,
            .WorkingDir = lnk_workingdir.ToString,
            .Hotkey = Hex(lnk_hotkey),
            .Hotkey_Modifier = [Enum].Parse(GetType(HotkeyModifiers), GetHiByte(lnk_hotkey)),
            .Hotkey_Key = [Enum].Parse(GetType(Keys), GetLoByte(lnk_hotkey)),
            .WindowState = lnk_windowstate,
            .IsFile = File.Exists(lnk_target.ToString),
            .IsDirectory = Directory.Exists(lnk_target.ToString),
            .DriveLetter = lnk_target.ToString.Substring(0, 1),
            .DirectoryName = lnk_target.ToString.Substring(0, lnk_target.ToString.LastIndexOf("\")),
            .FileName = lnk_target.ToString.Split("\").LastOrDefault.Split(".").FirstOrDefault,
            .FileExtension = lnk_target.ToString.Split(".").LastOrDefault
        }

    End Function

    ''' <summary>
    ''' Creates a shortcut file.
    ''' </summary>
    ''' <param name="FilePath">
    ''' The filepath to create the shortcut.
    ''' </param>
    ''' <param name="Target">
    ''' The target file or directory.
    ''' </param>
    ''' <param name="WorkingDirectory">
    ''' The working directory os the shortcut.
    ''' </param>
    ''' <param name="Description">
    ''' The shortcut description.
    ''' </param>
    ''' <param name="Arguments">
    ''' The target file arguments.
    ''' This value only should be set when target is an executable file.
    ''' </param>
    ''' <param name="Icon">
    ''' The icon location of the shortcut.
    ''' </param>
    ''' <param name="IconIndex">
    ''' The icon index of the icon file.
    ''' </param>
    ''' <param name="HotKey_Modifier">
    ''' The hotkey modifier(s) which should be used for the hotkey combination.
    ''' <paramref name="HotkeyModifiers"/> can be one or more modifiers.
    ''' </param>
    ''' <param name="HotKey_Key">
    ''' The key used in combination with the <paramref name="HotkeyModifiers"/> for hotkey combination.
    ''' </param>
    ''' <param name="WindowState">
    ''' The Window state for the target.
    ''' </param>
    Public Shared Sub Create(ByVal FilePath As String,
                             ByVal Target As String,
                             Optional ByVal WorkingDirectory As String = Nothing,
                             Optional ByVal Description As String = Nothing,
                             Optional ByVal Arguments As String = Nothing,
                             Optional ByVal Icon As String = Nothing,
                             Optional ByVal IconIndex As Integer = Nothing,
                             Optional ByVal HotKey_Modifier As HotkeyModifiers = Nothing,
                             Optional ByVal HotKey_Key As Keys = Nothing,
                             Optional ByVal WindowState As ShortcutWindowState = ShortcutWindowState.Normal)

        LoadShortcut(FilePath)

        DirectCast(lnk, IShellLinkW).SetPath(Target)

        DirectCast(lnk, IShellLinkW).SetWorkingDirectory(If(WorkingDirectory IsNot Nothing,
                                                            WorkingDirectory,
                                                            Path.GetDirectoryName(Target)))

        DirectCast(lnk, IShellLinkW).SetDescription(Description)
        DirectCast(lnk, IShellLinkW).SetArguments(Arguments)
        DirectCast(lnk, IShellLinkW).SetIconLocation(Icon, IconIndex)

        DirectCast(lnk, IShellLinkW).SetHotkey(If(HotKey_Modifier + HotKey_Key <> 0,
                                                  Convert.ToInt32(CInt(HotKey_Modifier & Hex(HotKey_Key)), 16),
                                                  Nothing))

        DirectCast(lnk, IShellLinkW).SetShowCmd(WindowState)

        DirectCast(lnk, IPersistFile).Save(FilePath, True)
        DirectCast(lnk, IPersistFile).SaveCompleted(FilePath)

    End Sub

#End Region

#Region " Private Methods "

    ''' <summary>
    ''' Loads the shortcut object to retrieve information.
    ''' </summary>
    ''' <param name="ShortcutFile">
    ''' The shortcut file to retrieve the info.
    ''' </param>
    Private Shared Sub LoadShortcut(ByVal ShortcutFile As String)
        DirectCast(lnk, IPersistFile).Load(ShortcutFile, 0)
    End Sub

    ''' <summary>
    ''' Gets the low order byte of a number.
    ''' </summary>
    Private Shared Function GetLoByte(ByVal Intg As Integer) As Integer
        Return Intg And &HFF&
    End Function

    ''' <summary>
    ''' Gets the high order byte of a number.
    ''' </summary>
    Private Shared Function GetHiByte(ByVal Intg As Integer) As Integer
        Return (Intg And &HFF00&) / 256
    End Function

#End Region

End Class

#End Region
#7712
Mi implementación de la librería MediaInfo.dll en VBNET: http://pastebin.com/XGUwW8hQ

#7713
Scripting / Re: Problema con un For en batch
18 Noviembre 2013, 16:34 PM
Hola

Cita de: santi810 en 18 Noviembre 2013, 15:28 PMYo pensaba que el bat "prueba1" llevaria como "%1" el valor que el for tiene en "%%a" cada vez que fuese llamado, pero no es asi.

Tal y como comentas, eso es así.

De haber un error, debe estar en el script "prueba", solo puedo decirte que revises de nuevo el valor de dichos parámetros en el script "prueba1", una simple comprobación visual:

Código (dos) [Seleccionar]
@Echo off
Echo "%%1=%~1"
Echo "%%2=%~2"
Echo "%%3=%~3"
Pause


De todas formas encierra los parámetros con comillas dobles, para evitar falsos positivos...
call archivo.bat "%%a" "%%b" "%%c"

PD: Ese tocho de libro en gallego o castellano solo lo he mirado de reojo, te digo que has hecho demasiado trabajo manual, no hagas una base de datos en Batch, por lo que mas quieras! xD, se que aprender un lenguaje nuevo es un poco perezoso al principio, pero mi consejo es que deberías invertir ese esfuerzo en aprender en algo más productivo que te facilite la tarea, por ejemplo XML (y olvidarte de Batch al menos para esa tarea de las series) y usar una estructura simple, es facil, y luego puedes representar el contenido de dicho documento XML con más comodidad.

Saludos
#7714
Cita de: .:Weeds:. en 17 Noviembre 2013, 22:34 PMMi pregunta es si esa referencia la tienen todos los sistemas windows(de xp para arriba).

Claro que si, es la dll Shell32.dll.

Sobre el Component Object Modal -> http://en.wikipedia.org/wiki/Component_Object_Model

Yo tampoco he profundizado mucho en el tema del IPC y COM, pero realicé varios proyectos donde debía manejar accesos directos, y bueno, antes de llevarlo a cabo me puse a investigar cual podría ser la mejor manera de hacerlo, e investigando leí muchos, pero muchos errores sobre códigos parecidos al que has mostrado usando dicha referencia, a algunos le daban problemas porque primero debían registrar dicha dll, a otros por la compatibilidad del tipo de interface en distinto Windows (COM 4, COM 5) obligando a compilar una versión distinta para XP y otra para Win7, y distintos errores más que ahora no recuerdo.

En fín, al final yo lo que hice fue buscar un código de alquien que ya se haya molestado en crear una Class de ayuda para esta tarea con dicha interface (IShellLink), tomé el código original que solo servia para resolver shortcuts dañados, y extendí dicha Class para mis requisitos (obtener información del shortcut),
no se cuan fiable será este método, a mi parecer no debe ser casi nada distinto a la referencia ya que parece que se basa en lo mismo, pero no estoy 100% seguro porque como te digo no se casi nada sobre COM, pero el caso es que esto funciona tanto en XP, Vista, Win7 y Win8 sin ningún tipo de errores (al menos hasta dia de hoy no he experimentado ningún error), y además tiene la ventaja de poder customizarlo como yo hice para tus requisitos, y la ventaja de resolver shortcuts, que esa era su función original.

El funcionamiento lo hice muy sencillo, te muestro un ejemplo:

código eliminado


A pesar de no haber podido "iluminarte", imagino que el código te será de gran ayuda :).

Saludos.




EDITO:
Le he dado otro repaso a la Class, aquí tienes.
he añadido un método para crear shortcuts, he añadido más propiedades y he facilitado el uso de las hotkeys.

Ejemplo de uso:
Código (vbnet) [Seleccionar]
       ' Tries to resolve a shortcut which has changed their Target location.
       ShortcutManager.Resolve_Ui("C:\Truncated Shortcut.lnk", New IntPtr(1))
       ShortcutManager.Resolve_NoUi("C:\Truncated Shortcut.lnk")

       ' Creates a new Shortcut file
       ShortcutManager.Create("C:\Shortcut.lnk",
                              "C:\TargetFile.ext",
                              "C:\",
                              "Description",
                              "-Arguments",
                              "C:\Icon.ico", 0,
                              ShortcutManager.HotkeyModifiers.ALT Or ShortcutManager.HotkeyModifiers.CONTROL,
                              Keys.F1,
                              ShortcutManager.ShortcutWindowState.Normal)

       ' Gets Shortcut file information
       Dim ShortcutInfo As ShortcutManager.ShortcutInfo =
           ShortcutManager.GetInfo("C:\Shortcut.lnk")

       Dim sb As New System.Text.StringBuilder

       With ShortcutInfo

           sb.AppendLine(String.Format(" ""{0}"" ", .ShortcutFile))
           sb.AppendLine(String.Format("------------------------"))
           sb.AppendLine(String.Format("Description: {0}", .Description))
           sb.AppendLine(String.Format("Target: {0}", .Target))
           sb.AppendLine(String.Format("Arguments: {0}", .Arguments))
           sb.AppendLine(String.Format("Target Is Directory?: {0}", CStr(.IsDirectory)))
           sb.AppendLine(String.Format("Target Is File?: {0}", CStr(.IsFile)))
           sb.AppendLine(String.Format("WorkingDir: {0}", .WorkingDir))
           sb.AppendLine(String.Format("DirectoryName: {0}", .DirectoryName))
           sb.AppendLine(String.Format("FileName: {0}", .FileName))
           sb.AppendLine(String.Format("FileExtension: {0}", .FileExtension))
           sb.AppendLine(String.Format("DriveLetter: {0}", .DriveLetter))
           sb.AppendLine(String.Format("Icon: {0}", .Icon))
           sb.AppendLine(String.Format("Icon Index: {0}", CStr(.IconIndex)))
           sb.AppendLine(String.Format("Hotkey (Hex): {0}", CStr(.Hotkey)))
           sb.AppendLine(String.Format("Hotkey (Str): {0} + {1}", .Hotkey_Modifier.ToString, .Hotkey_Key.ToString))
           sb.AppendLine(String.Format("Window State: {0}", .WindowState.ToString))

       End With

       MsgBox(sb.ToString)


la class:
Código (vbnet) [Seleccionar]
Imports System.Runtime.InteropServices
Imports System.Text
Imports System.IO

#Region " ShortcutManager "

' [ ShortcutManager ]
'
' // By Elektro H@cker

#Region " Usage Examples "

'Private Sub Test()

'    ' Tries to resolve a shortcut which has changed their Target location.
'    ShortcutManager.Resolve_Ui("C:\Truncated Shortcut.lnk", New IntPtr(1))
'    ShortcutManager.Resolve_NoUi("C:\Truncated Shortcut.lnk")

'    ' Creates a new Shortcut file
'    ShortcutManager.Create("C:\Shortcut.lnk",
'                           "C:\TargetFile.ext",
'                           "C:\",
'                           "Description",
'                           "-Arguments",
'                           "C:\Icon.ico", 0,
'                           ShortcutManager.HotkeyModifiers.ALT Or ShortcutManager.HotkeyModifiers.CONTROL,
'                           Keys.F1,
'                           ShortcutManager.ShortcutWindowState.Normal)

'    ' Gets Shortcut file information
'    Dim ShortcutInfo As ShortcutManager.ShortcutInfo =
'        ShortcutManager.GetInfo("C:\Shortcut.lnk")

'    Dim sb As New System.Text.StringBuilder

'    With ShortcutInfo

'        sb.AppendLine(String.Format(" ""{0}"" ", .ShortcutFile))
'        sb.AppendLine(String.Format("------------------------"))
'        sb.AppendLine(String.Format("Description: {0}", .Description))
'        sb.AppendLine(String.Format("Target: {0}", .Target))
'        sb.AppendLine(String.Format("Arguments: {0}", .Arguments))
'        sb.AppendLine(String.Format("Target Is Directory?: {0}", CStr(.IsDirectory)))
'        sb.AppendLine(String.Format("Target Is File?: {0}", CStr(.IsFile)))
'        sb.AppendLine(String.Format("WorkingDir: {0}", .WorkingDir))
'        sb.AppendLine(String.Format("DirectoryName: {0}", .DirectoryName))
'        sb.AppendLine(String.Format("FileName: {0}", .FileName))
'        sb.AppendLine(String.Format("FileExtension: {0}", .FileExtension))
'        sb.AppendLine(String.Format("DriveLetter: {0}", .DriveLetter))
'        sb.AppendLine(String.Format("Icon: {0}", .Icon))
'        sb.AppendLine(String.Format("Icon Index: {0}", CStr(.IconIndex)))
'        sb.AppendLine(String.Format("Hotkey (Hex): {0}", CStr(.Hotkey)))
'        sb.AppendLine(String.Format("Hotkey (Str): {0} + {1}", .Hotkey_Modifier.ToString, .Hotkey_Key.ToString))
'        sb.AppendLine(String.Format("Window State: {0}", .WindowState.ToString))

'    End With

'    MsgBox(sb.ToString)

'End Sub

#End Region

Public Class ShortcutManager

#Region " Variables "

   Private Shared lnk As New ShellLink()
   Private Shared lnk_data As New WIN32_FIND_DATAW()

   Private Shared lnk_arguments As New StringBuilder(260)
   Private Shared lnk_description As New StringBuilder(260)
   Private Shared lnk_target As New StringBuilder(260)
   Private Shared lnk_workingdir As New StringBuilder(260)
   Private Shared lnk_iconpath As New StringBuilder(260)
   Private Shared lnk_iconindex As Integer = -1
   Private Shared lnk_hotkey As Short = -1
   Private Shared lnk_windowstate As ShortcutWindowState = ShortcutWindowState.Normal

#End Region

#Region " API, Interfaces, Enumerations "

   <DllImport("shfolder.dll",
   CharSet:=CharSet.Auto)>
   Friend Shared Function SHGetFolderPath(ByVal hwndOwner As IntPtr,
                                          ByVal nFolder As Integer,
                                          ByVal hToken As IntPtr,
                                          ByVal dwFlags As Integer,
                                          ByVal lpszPath As StringBuilder
   ) As Integer
   End Function

   <Flags()>
   Private Enum SLGP_FLAGS

       ''' <summary>
       ''' Retrieves the standard short (8.3 format) file name.
       ''' </summary>
       SLGP_SHORTPATH = &H1

       ''' <summary>
       ''' Retrieves the Universal Naming Convention (UNC) path name of the file.
       ''' </summary>
       SLGP_UNCPRIORITY = &H2

       ''' <summary>
       ''' Retrieves the raw path name.
       ''' A raw path is something that might not exist and may include environment variables that need to be expanded.
       ''' </summary>
       SLGP_RAWPATH = &H4

   End Enum

   <Flags()>
   Private Enum SLR_FLAGS

       ''' <summary>
       ''' Do not display a dialog box if the link cannot be resolved. When SLR_NO_UI is set,
       ''' the high-order word of fFlags can be set to a time-out value that specifies the
       ''' maximum amount of time to be spent resolving the link. The function returns if the
       ''' link cannot be resolved within the time-out duration. If the high-order word is set
       ''' to zero, the time-out duration will be set to the default value of 3,000 milliseconds
       ''' (3 seconds). To specify a value, set the high word of fFlags to the desired time-out
       ''' duration, in milliseconds.
       ''' </summary>
       SLR_NO_UI = &H1

       ''' <summary>
       ''' If the link object has changed, update its path and list of identifiers.
       ''' If SLR_UPDATE is set, you do not need to call IPersistFile::IsDirty to determine,
       ''' whether or not the link object has changed.
       ''' </summary>
       SLR_UPDATE = &H4

       ''' <summary>
       ''' Do not update the link information
       ''' </summary>
       SLR_NOUPDATE = &H8

       ''' <summary>
       ''' Do not execute the search heuristics
       ''' </summary>
       SLR_NOSEARCH = &H10

       ''' <summary>
       ''' Do not use distributed link tracking
       ''' </summary>
       SLR_NOTRACK = &H20

       ''' <summary>
       ''' Disable distributed link tracking.
       ''' By default, distributed link tracking tracks removable media,
       ''' across multiple devices based on the volume name.
       ''' It also uses the Universal Naming Convention (UNC) path to track remote file systems,
       ''' whose drive letter has changed.
       ''' Setting SLR_NOLINKINFO disables both types of tracking.
       ''' </summary>
       SLR_NOLINKINFO = &H40

       ''' <summary>
       ''' Call the Microsoft Windows Installer
       ''' </summary>
       SLR_INVOKE_MSI = &H80

   End Enum

   ''' <summary>
   ''' Stores information about a shortcut file.
   ''' </summary>
   Public Class ShortcutInfo

       ''' <summary>
       ''' Shortcut file full path.
       ''' </summary>
       Public Property ShortcutFile As String

       ''' <summary>
       ''' Shortcut Comment/Description.
       ''' </summary>
       Public Property Description As String

       ''' <summary>
       ''' Shortcut Target Arguments.
       ''' </summary>
       Public Property Arguments As String

       ''' <summary>
       ''' Shortcut Target.
       ''' </summary>
       Public Property Target As String

       ''' <summary>
       ''' Shortcut Working Directory.
       ''' </summary>
       Public Property WorkingDir As String

       ''' <summary>
       ''' Shortcut Icon Location.
       ''' </summary>
       Public Property Icon As String

       ''' <summary>
       ''' Shortcut Icon Index.
       ''' </summary>
       Public Property IconIndex As Integer

       ''' <summary>
       ''' Shortcut Hotkey combination.
       ''' Is represented as Hexadecimal.
       ''' </summary>
       Public Property Hotkey As Short

       ''' <summary>
       ''' Shortcut Hotkey modifiers.
       ''' </summary>
       Public Property Hotkey_Modifier As HotkeyModifiers

       ''' <summary>
       ''' Shortcut Hotkey Combination.
       ''' </summary>
       Public Property Hotkey_Key As Keys

       ''' <summary>
       ''' Shortcut Window State.
       ''' </summary>
       Public Property WindowState As ShortcutWindowState

       ''' <summary>
       ''' Indicates if the target is a file.
       ''' </summary>
       Public Property IsFile As Boolean

       ''' <summary>
       ''' Indicates if the target is a directory.
       ''' </summary>
       Public Property IsDirectory As Boolean

       ''' <summary>
       ''' Shortcut target drive letter.
       ''' </summary>
       Public Property DriveLetter As String

       ''' <summary>
       ''' Shortcut target directory name.
       ''' </summary>
       Public Property DirectoryName As String

       ''' <summary>
       ''' Shortcut target filename.
       ''' (File extension is not included in name)
       ''' </summary>
       Public Property FileName As String

       ''' <summary>
       ''' Shortcut target file extension.
       ''' </summary>
       Public Property FileExtension As String

   End Class

   ''' <summary>
   ''' Hotkey modifiers for a shortcut file.
   ''' </summary>
   <FlagsAttribute()>
   Public Enum HotkeyModifiers As Short

       ''' <summary>
       ''' The SHIFT key.
       ''' </summary>
       SHIFT = 1

       ''' <summary>
       ''' The CTRL key.
       ''' </summary>
       CONTROL = 2

       ''' <summary>
       ''' The ALT key.
       ''' </summary>
       ALT = 4

       ''' <summary>
       ''' None.
       ''' Specifies any hotkey modificator.
       ''' </summary>
       NONE = 0

   End Enum

   ''' <summary>
   ''' The Window States for a shortcut file.
   ''' </summary>
   Public Enum ShortcutWindowState As Integer

       ''' <summary>
       ''' Shortcut Window is at normal state.
       ''' </summary>
       Normal = 1

       ''' <summary>
       ''' Shortcut Window is Maximized.
       ''' </summary>
       Maximized = 3

       ''' <summary>
       ''' Shortcut Window is Minimized.
       ''' </summary>
       Minimized = 7

   End Enum

   <StructLayout(LayoutKind.Sequential,
   CharSet:=CharSet.Auto)>
   Private Structure WIN32_FIND_DATAW
       Public dwFileAttributes As UInteger
       Public ftCreationTime As Long
       Public ftLastAccessTime As Long
       Public ftLastWriteTime As Long
       Public nFileSizeHigh As UInteger
       Public nFileSizeLow As UInteger
       Public dwReserved0 As UInteger
       Public dwReserved1 As UInteger
       <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)>
       Public cFileName As String
       <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=14)>
       Public cAlternateFileName As String
   End Structure

   ''' <summary>
   ''' The IShellLink interface allows Shell links to be created, modified, and resolved
   ''' </summary>
   <ComImport(),
   InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
   Guid("000214F9-0000-0000-C000-000000000046")>
   Private Interface IShellLinkW

       ''' <summary>
       ''' Retrieves the path and file name of a Shell link object.
       ''' </summary>
       Sub GetPath(<Out(), MarshalAs(UnmanagedType.LPWStr)>
                   ByVal pszFile As StringBuilder,
                   ByVal cchMaxPath As Integer,
                   ByRef pfd As WIN32_FIND_DATAW,
                   ByVal fFlags As SLGP_FLAGS)

       ''' <summary>
       ''' Retrieves the list of item identifiers for a Shell link object.
       ''' </summary>
       Sub GetIDList(ByRef ppidl As IntPtr)

       ''' <summary>
       ''' Sets the pointer to an item identifier list (PIDL) for a Shell link object.
       ''' </summary>
       Sub SetIDList(ByVal pidl As IntPtr)

       ''' <summary>
       ''' Retrieves the description string for a Shell link object.
       ''' </summary>
       Sub GetDescription(<Out(), MarshalAs(UnmanagedType.LPWStr)>
                          ByVal pszName As StringBuilder,
                          ByVal cchMaxName As Integer)

       ''' <summary>
       ''' Sets the description for a Shell link object.
       ''' The description can be any application-defined string.
       ''' </summary>
       Sub SetDescription(<MarshalAs(UnmanagedType.LPWStr)>
                          ByVal pszName As String)

       ''' <summary>
       ''' Retrieves the name of the working directory for a Shell link object.
       ''' </summary>
       Sub GetWorkingDirectory(<Out(), MarshalAs(UnmanagedType.LPWStr)>
                               ByVal pszDir As StringBuilder,
                               ByVal cchMaxPath As Integer)

       ''' <summary>
       ''' Sets the name of the working directory for a Shell link object.
       ''' </summary>
       Sub SetWorkingDirectory(<MarshalAs(UnmanagedType.LPWStr)>
                               ByVal pszDir As String)

       ''' <summary>
       ''' Retrieves the command-line arguments associated with a Shell link object.
       ''' </summary>
       Sub GetArguments(<Out(), MarshalAs(UnmanagedType.LPWStr)>
                        ByVal pszArgs As StringBuilder,
                        ByVal cchMaxPath As Integer)

       ''' <summary>
       ''' Sets the command-line arguments for a Shell link object.
       ''' </summary>
       Sub SetArguments(<MarshalAs(UnmanagedType.LPWStr)>
                        ByVal pszArgs As String)

       ''' <summary>
       ''' Retrieves the hot key for a Shell link object.
       ''' </summary>
       Sub GetHotkey(ByRef pwHotkey As Short)

       ''' <summary>
       ''' Sets a hot key for a Shell link object.
       ''' </summary>
       Sub SetHotkey(ByVal wHotkey As Short)

       ''' <summary>
       ''' Retrieves the show command for a Shell link object.
       ''' </summary>
       Sub GetShowCmd(ByRef piShowCmd As Integer)

       ''' <summary>
       ''' Sets the show command for a Shell link object.
       ''' The show command sets the initial show state of the window.
       ''' </summary>
       Sub SetShowCmd(ByVal iShowCmd As ShortcutWindowState)

       ''' <summary>
       ''' Retrieves the location (path and index) of the icon for a Shell link object.
       ''' </summary>
       Sub GetIconLocation(<Out(), MarshalAs(UnmanagedType.LPWStr)>
                           ByVal pszIconPath As StringBuilder,
                           ByVal cchIconPath As Integer,
                           ByRef piIcon As Integer)

       ''' <summary>
       ''' Sets the location (path and index) of the icon for a Shell link object.
       ''' </summary>
       Sub SetIconLocation(<MarshalAs(UnmanagedType.LPWStr)>
                           ByVal pszIconPath As String,
                           ByVal iIcon As Integer)

       ''' <summary>
       ''' Sets the relative path to the Shell link object.
       ''' </summary>
       Sub SetRelativePath(<MarshalAs(UnmanagedType.LPWStr)>
                           ByVal pszPathRel As String,
                           ByVal dwReserved As Integer)

       ''' <summary>
       ''' Attempts to find the target of a Shell link,
       ''' even if it has been moved or renamed.
       ''' </summary>
       Sub Resolve(ByVal hwnd As IntPtr,
                   ByVal fFlags As SLR_FLAGS)

       ''' <summary>
       ''' Sets the path and file name of a Shell link object
       ''' </summary>
       Sub SetPath(ByVal pszFile As String)

   End Interface

   <ComImport(), Guid("0000010c-0000-0000-c000-000000000046"),
   InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
   Public Interface IPersist

       <PreserveSig()>
       Sub GetClassID(ByRef pClassID As Guid)

   End Interface

   <ComImport(), Guid("0000010b-0000-0000-C000-000000000046"),
   InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
   Public Interface IPersistFile
       Inherits IPersist

       Shadows Sub GetClassID(ByRef pClassID As Guid)

       <PreserveSig()>
       Function IsDirty() As Integer

       <PreserveSig()>
       Sub Load(<[In](), MarshalAs(UnmanagedType.LPWStr)>
                pszFileName As String,
                dwMode As UInteger)

       <PreserveSig()>
       Sub Save(<[In](), MarshalAs(UnmanagedType.LPWStr)>
                pszFileName As String,
                <[In](), MarshalAs(UnmanagedType.Bool)>
                fRemember As Boolean)

       <PreserveSig()>
       Sub SaveCompleted(<[In](), MarshalAs(UnmanagedType.LPWStr)>
                         pszFileName As String)

       <PreserveSig()>
       Sub GetCurFile(<[In](), MarshalAs(UnmanagedType.LPWStr)>
                      ppszFileName As String)

   End Interface

   ' "CLSID_ShellLink" from "ShlGuid.h"
   <ComImport(),
   Guid("00021401-0000-0000-C000-000000000046")>
   Public Class ShellLink
   End Class

#End Region

#Region " Public Methods "

   ''' <summary>
   ''' Resolves the target of a shortcut.
   ''' If shortcut can't be resolved, an error message would be displayed.
   ''' This is usefull when the target path of a shortcut file is changed from a driveletter for example,
   ''' then the shortcut file need to be resolved before trying to retrieve the target path.
   ''' </summary>
   ''' <param name="ShortcutFile">
   ''' The shortcut file to resolve.
   ''' </param>
   ''' <param name="hwnd">
   ''' The new handle pointer that would be generated
   ''' for the window which should display the error message (if any).
   ''' </param>
   Public Shared Sub Resolve_Ui(ShortcutFile As String, hwnd As IntPtr)
       LoadShortcut(ShortcutFile)
       DirectCast(lnk, IShellLinkW).Resolve(hwnd, SLR_FLAGS.SLR_UPDATE)
   End Sub

   ''' <summary>
   ''' Resolves the target of a shortcut.
   ''' If shortcut can't be resolved, any error message would be displayed.
   ''' This is usefull when the target path of a shortcut file is changed from a driveletter for example,
   ''' then the shortcut file need to be resolved before trying to retrieve the target path.
   ''' </summary>
   ''' <param name="ShortcutFile">
   ''' The shortcut file to resolve.
   ''' </param>
   Public Shared Sub Resolve_NoUi(ByVal ShortcutFile As String)
       LoadShortcut(ShortcutFile)
       DirectCast(lnk, IShellLinkW).Resolve(IntPtr.Zero, SLR_FLAGS.SLR_UPDATE Or SLR_FLAGS.SLR_NO_UI)
   End Sub

   ''' <summary>
   ''' Returns the description of a shortcut file.
   ''' </summary>
   ''' <param name="ShortcutFile">
   ''' The shortcut file to retrieve the info.
   ''' </param>
   Public Shared Function Get_Description(ByVal ShortcutFile As String) As String
       LoadShortcut(ShortcutFile)
       lnk_description.Clear()
       DirectCast(lnk, IShellLinkW).GetDescription(lnk_description, lnk_description.Capacity)
       Return lnk_description.ToString()
   End Function

   ''' <summary>
   ''' Returns the Arguments of a shortcut file.
   ''' </summary>
   ''' <param name="ShortcutFile">
   ''' The shortcut file to retrieve the info.
   ''' </param>
   Public Shared Function Get_Arguments(ByVal ShortcutFile As String) As String
       LoadShortcut(ShortcutFile)
       lnk_arguments.Clear()
       DirectCast(lnk, IShellLinkW).GetArguments(lnk_arguments, lnk_arguments.Capacity)
       Return lnk_arguments.ToString()
   End Function

   ''' <summary>
   ''' Returns the path and filename of a shortcut file.
   ''' </summary>
   ''' <param name="ShortcutFile">
   ''' The shortcut file to retrieve the info.
   ''' </param>
   Public Shared Function Get_FullPath(ByVal ShortcutFile As String) As String
       LoadShortcut(ShortcutFile)
       lnk_target.Clear()
       DirectCast(lnk, IShellLinkW).GetPath(lnk_target, lnk_target.Capacity, lnk_data, SLGP_FLAGS.SLGP_UNCPRIORITY)
       Return lnk_target.ToString()
   End Function

   ''' <summary>
   ''' Returns the working directory of a shortcut file.
   ''' </summary>
   ''' <param name="ShortcutFile">
   ''' The shortcut file to retrieve the info.
   ''' </param>
   Public Shared Function Get_WorkingDir(ByVal ShortcutFile As String) As String
       LoadShortcut(ShortcutFile)
       lnk_workingdir.Clear()
       DirectCast(lnk, IShellLinkW).GetWorkingDirectory(lnk_workingdir, lnk_workingdir.Capacity)
       Return lnk_workingdir.ToString()
   End Function

   ''' <summary>
   ''' Returns the Hotkey of a shortcut file.
   ''' </summary>
   ''' <param name="ShortcutFile">
   ''' The shortcut file to retrieve the info.
   ''' </param>
   Public Shared Function Get_Hotkey(ByVal ShortcutFile As String) As Short
       LoadShortcut(ShortcutFile)
       lnk_hotkey = -1
       DirectCast(lnk, IShellLinkW).GetHotkey(lnk_hotkey)
       Return lnk_hotkey
   End Function

   ''' <summary>
   ''' Returns the Window State of a shortcut file.
   ''' </summary>
   ''' <param name="ShortcutFile">
   ''' The shortcut file to retrieve the info.
   ''' </param>
   Public Shared Function Get_WindowStyle(ByVal ShortcutFile As String) As ShortcutWindowState
       LoadShortcut(ShortcutFile)
       DirectCast(lnk, IShellLinkW).GetShowCmd(lnk_windowstate)
       Return lnk_windowstate
   End Function

   ''' <summary>
   ''' Returns the Icon location of a shortcut file.
   ''' </summary>
   ''' <param name="ShortcutFile">
   ''' The shortcut file to retrieve the info.
   ''' </param>
   ''' <param name="IconIndex">
   ''' Optional Integer type variable to store the IconIndex.
   ''' </param>
   Public Shared Function Get_IconLocation(ByVal ShortcutFile As String,
                                           Optional ByRef IconIndex As Integer = 0) As String
       LoadShortcut(ShortcutFile)
       lnk_iconpath.Clear()
       DirectCast(lnk, IShellLinkW).GetIconLocation(lnk_iconpath, lnk_iconpath.Capacity, IconIndex)
       Return lnk_iconpath.ToString()
   End Function

   ''' <summary>
   ''' Retrieves all the information about a shortcut file.
   ''' </summary>
   ''' <param name="ShortcutFile">
   ''' The shortcut file to retrieve the info.
   ''' </param>
   Public Shared Function GetInfo(ByVal ShortcutFile As String) As ShortcutInfo

       ' Load Shortcut
       LoadShortcut(ShortcutFile)

       ' Reset variables
       lnk_description.Clear()
       lnk_arguments.Clear()
       lnk_target.Clear()
       lnk_workingdir.Clear()
       lnk_iconpath.Clear()
       lnk_hotkey = -1
       lnk_iconindex = -1

       ' Retrieve Info
       DirectCast(lnk, IShellLinkW).GetDescription(lnk_description, lnk_description.Capacity)
       DirectCast(lnk, IShellLinkW).GetArguments(lnk_arguments, lnk_arguments.Capacity)
       DirectCast(lnk, IShellLinkW).GetPath(lnk_target, lnk_target.Capacity, lnk_data, SLGP_FLAGS.SLGP_UNCPRIORITY)
       DirectCast(lnk, IShellLinkW).GetWorkingDirectory(lnk_workingdir, lnk_workingdir.Capacity)
       DirectCast(lnk, IShellLinkW).GetIconLocation(lnk_iconpath, lnk_iconpath.Capacity, lnk_iconindex)
       DirectCast(lnk, IShellLinkW).GetHotkey(lnk_hotkey)
       DirectCast(lnk, IShellLinkW).GetShowCmd(lnk_windowstate)

       ' Return Info
       Return New ShortcutInfo With {
           .ShortcutFile = ShortcutFile,
           .Description = lnk_description.ToString,
           .Arguments = lnk_arguments.ToString,
           .Target = lnk_target.ToString,
           .Icon = lnk_iconpath.ToString,
           .IconIndex = lnk_iconindex,
           .WorkingDir = lnk_workingdir.ToString,
           .Hotkey = Hex(lnk_hotkey),
           .Hotkey_Modifier = [Enum].Parse(GetType(HotkeyModifiers), GetHiByte(lnk_hotkey)),
           .Hotkey_Key = [Enum].Parse(GetType(Keys), GetLoByte(lnk_hotkey)),
           .WindowState = lnk_windowstate,
           .IsFile = File.Exists(lnk_target.ToString),
           .IsDirectory = Directory.Exists(lnk_target.ToString),
           .DriveLetter = lnk_target.ToString.Substring(0, 1),
           .DirectoryName = lnk_target.ToString.Substring(0, lnk_target.ToString.LastIndexOf("\")),
           .FileName = lnk_target.ToString.Split("\").LastOrDefault.Split(".").FirstOrDefault,
           .FileExtension = lnk_target.ToString.Split(".").LastOrDefault
       }

   End Function

   ''' <summary>
   ''' Creates a shortcut file.
   ''' </summary>
   ''' <param name="FilePath">
   ''' The filepath to create the shortcut.
   ''' </param>
   ''' <param name="Target">
   ''' The target file or directory.
   ''' </param>
   ''' <param name="WorkingDirectory">
   ''' The working directory os the shortcut.
   ''' </param>
   ''' <param name="Description">
   ''' The shortcut description.
   ''' </param>
   ''' <param name="Arguments">
   ''' The target file arguments.
   ''' This value only should be set when target is an executable file.
   ''' </param>
   ''' <param name="Icon">
   ''' The icon location of the shortcut.
   ''' </param>
   ''' <param name="IconIndex">
   ''' The icon index of the icon file.
   ''' </param>
   ''' <param name="HotKey_Modifier">
   ''' The hotkey modifier(s) which should be used for the hotkey combination.
   ''' <paramref name="HotkeyModifiers"/> can be one or more modifiers.
   ''' </param>
   ''' <param name="HotKey_Key">
   ''' The key used in combination with the <paramref name="HotkeyModifiers"/> for hotkey combination.
   ''' </param>
   ''' <param name="WindowState">
   ''' The Window state for the target.
   ''' </param>
   Public Shared Sub Create(ByVal FilePath As String,
                            ByVal Target As String,
                            Optional ByVal WorkingDirectory As String = Nothing,
                            Optional ByVal Description As String = Nothing,
                            Optional ByVal Arguments As String = Nothing,
                            Optional ByVal Icon As String = Nothing,
                            Optional ByVal IconIndex As Integer = Nothing,
                            Optional ByVal HotKey_Modifier As HotkeyModifiers = Nothing,
                            Optional ByVal HotKey_Key As Keys = Nothing,
                            Optional ByVal WindowState As ShortcutWindowState = ShortcutWindowState.Normal)

       LoadShortcut(FilePath)

       DirectCast(lnk, IShellLinkW).SetPath(Target)

       DirectCast(lnk, IShellLinkW).SetWorkingDirectory(If(WorkingDirectory IsNot Nothing,
                                                           WorkingDirectory,
                                                           Path.GetDirectoryName(Target)))

       DirectCast(lnk, IShellLinkW).SetDescription(Description)
       DirectCast(lnk, IShellLinkW).SetArguments(Arguments)
       DirectCast(lnk, IShellLinkW).SetIconLocation(Icon, IconIndex)

       DirectCast(lnk, IShellLinkW).SetHotkey(If(HotKey_Modifier + HotKey_Key <> 0,
                                                 Convert.ToInt32(CInt(HotKey_Modifier & Hex(HotKey_Key)), 16),
                                                 Nothing))

       DirectCast(lnk, IShellLinkW).SetShowCmd(WindowState)

       DirectCast(lnk, IPersistFile).Save(FilePath, True)
       DirectCast(lnk, IPersistFile).SaveCompleted(FilePath)

   End Sub

#End Region

#Region " Private Methods "

   ''' <summary>
   ''' Loads the shortcut object to retrieve information.
   ''' </summary>
   ''' <param name="ShortcutFile">
   ''' The shortcut file to retrieve the info.
   ''' </param>
   Private Shared Sub LoadShortcut(ByVal ShortcutFile As String)
       DirectCast(lnk, IPersistFile).Load(ShortcutFile, 0)
   End Sub

   ''' <summary>
   ''' Gets the low order byte of a number.
   ''' </summary>
   Private Shared Function GetLoByte(ByVal Intg As Integer) As Integer
       Return Intg And &HFF&
   End Function

   ''' <summary>
   ''' Gets the high order byte of a number.
   ''' </summary>
   Private Shared Function GetHiByte(ByVal Intg As Integer) As Integer
       Return (Intg And &HFF00&) / 256
   End Function

#End Region

End Class

#End Region
#7715
Un pequeño código para facilitar la tarea de preservar las fechas de un archivo, por ejemplo cuando se modifica el texto de un archivo, o cuando se convierte un archivo de audio (al mismo u otro formato).

El modo de empleo es muy sencillo:

Código (vbnet) [Seleccionar]
FileDate.Action("C:\File.txt", FileDate.FileDateAction.Save)
IO.File.AppendAllText("C:\File.txt", "Hello World!")
FileDate.Action("C:\File.txt", FileDate.FileDateAction.Restore)


O bien:

Código (vbnet) [Seleccionar]
FileDate.Action("C:\File.txt", FileDate.FileDateAction.Save, False)
IO.File.AppendAllText("C:\File.txt", "Hello World!")
IO.File.Move("C:\File.txt", "C:\File.log")
FileDate.Action(New IO.FileInfo("C:\File.log"), FileDate.FileDateAction.Restore, False)





Código (vbnet) [Seleccionar]
#Region " Preserve FileDate "

' [ Preserve FileDate ]
'
' // By Elektro H@cker
'
' Usage Examples:

' // Example 1:
'
' FileDate.Action("C:\File.txt", FileDate.FileDateAction.Save)
' IO.File.AppendAllText("C:\File.txt", "Hello World!")
' FileDate.Action("C:\File.txt", FileDate.FileDateAction.Restore)

' // Example 2:
'
' FileDate.Action("C:\File.txt", FileDate.FileDateAction.Save, False)
' IO.File.AppendAllText("C:\File.txt", "Hello World!")
' IO.File.Move("C:\File.txt", "C:\File.log")
' FileDate.Action(New IO.FileInfo("C:\File.log"), FileDate.FileDateAction.Restore, False)

Public Class FileDate

    ''' <summary>
    ''' Collection that contains the files and their dates.
    ''' </summary>
    Private Shared FileDates As New Dictionary(Of String, Date())

    ''' <summary>
    ''' Stores the File object.
    ''' </summary>
    Private Shared _File As IO.FileInfo

    ''' <summary>
    ''' Stores the full path of the file
    ''' </summary>
    Private Shared FullPath As String

    ''' <summary>
    ''' An action to take on file dates.
    ''' </summary>
    Public Enum FileDateAction As Short

        ''' <summary>
        ''' Save file dates into filedates collection.
        ''' </summary>
        Save = 0

        ''' <summary>
        ''' Restore file dates from filedates collection.
        ''' </summary>
        Restore = 1

        ''' <summary>
        ''' Remove file dates from filedates collection,
        ''' this don't removes the dates from file.
        ''' </summary>
        Remove = 2

        ''' <summary>
        ''' Sets the file dates of specified file to "01/01/1800 00:00:00"
        ''' </summary>
        Truncate = 3

    End Enum

    ''' <summary>
    ''' Performs an action on the dates of the specified file,
    ''' Creation Date, LastAccess Date and LastWrite Date.
    ''' </summary>
    ''' <param name="File">
    ''' The File.
    ''' </param>
    ''' <param name="Action">
    ''' The action to take on file dates.
    ''' </param>
    ''' <param name="IncludeFileExtension">
    ''' Specifies if that the filename extension should be included or not.
    ''' Default value is <paramref name="True"/>.
    ''' This parameter should be set to <paramref name="False"/>  when renaming files.
    ''' </param>
    Public Shared Sub Action(ByVal File As IO.FileInfo,
                             ByVal Action As FileDateAction,
                             Optional ByVal IncludeFileExtension As Boolean = True)

        _File = File
        DoFileDateAction(_File, Action, IncludeFileExtension)

    End Sub

    ''' <summary>
    ''' Performs an action on the dates of the specified file,
    ''' Creation Date, LastAccess Date and LastWrite Date.
    ''' </summary>
    ''' <param name="File">
    ''' The File.
    ''' </param>
    ''' <param name="Action">
    ''' The action to take on file dates.
    ''' </param>
    ''' <param name="IncludeFileExtension">
    ''' Specifies if that the filename extension should be included or not.
    ''' Default value is <paramref name="True"/>.
    ''' This parameter should be set to <paramref name="False"/> when renaming files.
    ''' </param>
    Public Shared Sub Action(ByVal File As String,
                             ByVal Action As FileDateAction,
                             Optional ByVal IncludeFileExtension As Boolean = True)

        _File = New IO.FileInfo(File)
        DoFileDateAction(_File, Action, IncludeFileExtension)

    End Sub

    ''' <summary>
    ''' Clears all the dates stored in the filedates collection.
    ''' </summary>
    Public Shared Sub ClearFileDateCollection()
        FileDates.Clear()
    End Sub

    ''' <summary>
    ''' Perform an action to take on file dates.
    ''' </summary>
    Private Shared Sub DoFileDateAction(ByVal File As IO.FileInfo,
                                        ByVal Action As FileDateAction,
                                        ByVal IncludeFileExtension As Boolean)

        FullPath = If(IncludeFileExtension,
                      File.FullName,
                      If(File.Name.Contains("."),
                         File.FullName.Substring(0, File.FullName.LastIndexOf(".")),
                         File.FullName))

        HandleErrors(Action)

        Select Case Action

            Case FileDateAction.Save

                FileDates.Add(FullPath,
                             {File.CreationTime, File.LastAccessTime, File.LastWriteTime})

            Case FileDateAction.Restore

                File.CreationTime = FileDates(FullPath).First
                File.LastAccessTime = FileDates(FullPath)(1)
                File.LastWriteTime = FileDates(FullPath).Last

                FileDates.Remove(FullPath)

            Case FileDateAction.Remove

                FileDates.Remove(FullPath)

            Case FileDateAction.Truncate
                File.CreationTime = "01/01/1800 00:00:00"
                File.LastAccessTime = "01/01/1800 00:00:00"
                File.LastWriteTime = "01/01/1800 00:00:00"

        End Select

    End Sub

    ''' <summary>
    ''' Simple Error Handling.
    ''' </summary>
    Private Shared Sub HandleErrors(ByVal Action As FileDateAction)

        Select Case Action

            Case FileDateAction.Save

                If FileDates.ContainsKey(FullPath) Then
                    Throw New Exception("File already exist in collection.")
                End If

            Case FileDateAction.Restore, FileDateAction.Remove

                If Not FileDates.ContainsKey(FullPath) Then
                    Throw New Exception("File not found in collection.")
                End If

        End Select


    End Sub

End Class

#End Region
#7716
Cita de: Proweb en 16 Noviembre 2013, 20:52 PMpero haber de donde lo descargo o compro

Por lo visto sigue siendo todo un dilema abrir Google, aquí tienes una pequeña ayuda.

PD: Los libros antiguos sobre programación suelen ser muy buenos, aunque en mi opinión un libro de antes de la época de "el efecto 2000" es algo que sirve de poco, los conceptos relacionados con la programación estructurada es algo que evoluciona como todo en esta vida, pero bueno, mi recomendación no la haré en este post para perezosos.

Saludos!
#7717
Scripting / Re: Ayuda con un problema en Python
16 Noviembre 2013, 20:39 PM
Hola

Debes respeta las normas del foro, si no pones esos comentarios de código entre etiquetas me veré obligado a eliminar el post,
ya se te ha avisado de esto en otras ocasiones.

-> Normas del tablón ( LEER ANTES DE POSTEAR )

Saludos
#7718
Cita de: Proweb en 16 Noviembre 2013, 18:10 PMTiene version en español?

Cita de: xaps en 16 Noviembre 2013, 18:57 PMNi siquiera te has molestado en mirar el enlace que rir3760 te ha facilitado...

Estás hecho todo un crack Proweb!, sobran los comentarios, ni has visto el enlace.

Vago hasta para escribir VisualBasic (o cualquiera de las otras decenas de variantes de Basic a la que intentes referirte).

Un saludo!
#7719
Scripting / Re: Introduccion a los scripts.
16 Noviembre 2013, 17:56 PM
Si sigues por ese camino no me va a quedar más remedio que cerrar el post.

Aquí nadie le hace el trabajo a nadie y nadie va a programarte un script digamos de 2.000 lineas solo porque le caigas bien,
si quieres scripts, aprende a programar, aquí te ayudare(mos) lo que haga falta a aprender, corregir, y mejorar tus scripts, siempre que muestres interés por aprender.

Cita de: jemez44 en 16 Noviembre 2013, 17:12 PMquiero que me paséis scripts que me hagan la vida más fácil.
Si quieres algo rápido, para eso ya tienes Google, no especificas cuales son tus necesidades ni el tipo de scripts que te harían la vida más facil como dices... cuando se habla de programación o se dan detalles o vamos mal, busca en Google o en el buscador del foro y seguro que encuentras aquello que necesites.

Saludos!
#7720
Software / Re: gestores de descarga.
16 Noviembre 2013, 09:28 AM
Cita de: jemez44 en 12 Noviembre 2013, 14:45 PM
muchas veces cuando bajas a descargarte una peli te dice si quieres descargarla con un programa gestor de descargas, que te lo tienes que instalar previamente. Con ese me imagino que si que se podrá hacer.

No, eso suele ser puro fraude, pura basura de Scam y de aplicaciones que te instalan Spyware o malware en general, no te descargues nada de eso, si vas a descargarte un archivo y la página te muestran un enlace acabado en ".exe" diciendo que es un maravilloso gestor de descargas, sal corriendo.




Instálate JDownloader o IDM, es mi sugerencia en ese orden de preferencia.

Ventajas de un Gestor de descargas:

· Puedes pausar/continuar una descarga en cualquier momento (siempre que el host lo permita)

· Puedes descargar videos de youtube y otro tipo de contenido multimedia sin necesidad de instalar más aplicaicones dedicadas.

· Puedes administrar la velocidad de descarga.

- Puedes administrar tus cuentas premium.

· En el caso de Jdownloader, en multitud de sitios WEB comparten cada día el archivo que contiene las cuentas premium de otros usuarios, en estas webs puedes descargarte dicho archivo y usarlo para descargar de forma ilegal de cualquier servidor.

· Puedes decirle a tus amigos son estúpidos por no usar un gestor de descargas xD.

Saludos.