elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.


Tema destacado: Recopilación Tutoriales y Manuales Hacking, Seguridad, Privacidad, Hardware, etc


  Mostrar Mensajes
Páginas: 1 ... 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 [931] 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 ... 1253
9301  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Posteen aquí sus snippets) en: 7 Mayo 2013, 14:55 pm
Ejemplo de un comentário de sumário (o Method description):

Código
  1. Public Class MyClass
  2.  
  3.    ''' <summary>
  4.    ''' A description for this variable [Default: False].
  5.    ''' </summary>
  6.    Public Shared MyVariable As Boolean = False
  7.  
  8. End class





Ejemplo de un Select case para comparar 2 o más strings (el equivalente al OR):

Código
  1.        Select Case Variable.ToUpper
  2.            Case "HELLO"
  3.                MsgBox("You said HELLO.")
  4.            Case "BYE", "HASTALAVISTA"
  5.                MsgBox("You said BYE or HASTALAVISTA.")
  6.            Case Else
  7.                MsgBox("You said nothing.")
  8.        End Select





Concatenar texto en varios colores en la consola

Código
  1. #Region " Write Color Text "
  2.  
  3.    ' [ Write Color Text ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples:
  8.    ' Write_Color_Text("TestString A", ConsoleColor.Cyan)
  9.    ' Write_Color_Text(" + ", ConsoleColor.Green)
  10.    ' Write_Color_Text("TestString B" & vbNewLine, ConsoleColor.White, ConsoleColor.DarkRed)
  11.    ' Console.ReadLine()
  12.  
  13.    Private Sub Write_Color_Text(ByVal Text As String, _
  14.                                 Optional ByVal ForeColor As System.ConsoleColor = ConsoleColor.White, _
  15.                                 Optional ByVal BackColor As System.ConsoleColor = ConsoleColor.Black)
  16.  
  17.        Console.ForegroundColor = ForeColor
  18.        Console.BackgroundColor = BackColor
  19.        Console.Write(Text)
  20.        Console.ForegroundColor = ConsoleColor.White
  21.        Console.BackgroundColor = ConsoleColor.Black
  22.  
  23.    End Sub
  24.  
  25. #End Region





Añade la aplicación actual al inicio de sesión de windows:

Código
  1. #Region " Add Application To Startup "
  2.  
  3.    ' [ Add Application To Startup Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' Add_Application_To_Startup(Startup_User.All_Users)
  9.    ' Add_Application_To_Startup(Startup_User.Current_User)
  10.    ' Add_Application_To_Startup(Startup_User.Current_User, "Application Name", """C:\ApplicationPath.exe""" & " -Arguments")
  11.  
  12.    Public Enum Startup_User
  13.        Current_User
  14.        All_Users
  15.    End Enum
  16.  
  17.    Private Function Add_Application_To_Startup(ByVal Startup_User As Startup_User, _
  18.                                            Optional ByVal Application_Name As String = Nothing, _
  19.                                            Optional ByVal Application_Path As String = Nothing) As Boolean
  20.  
  21.        If Application_Name Is Nothing Then Application_Name = Process.GetCurrentProcess().MainModule.ModuleName
  22.        If Application_Path Is Nothing Then Application_Path = Application.ExecutablePath
  23.  
  24.        Try
  25.            Select Case Startup_User
  26.                Case Startup_User.All_Users
  27.                    My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run", Application_Name, Application_Path, Microsoft.Win32.RegistryValueKind.String)
  28.                Case Startup_User.Current_User
  29.                    My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", Application_Name, Application_Path, Microsoft.Win32.RegistryValueKind.String)
  30.            End Select
  31.        Catch ex As Exception
  32.            ' Throw New Exception(ex.Message)
  33.            Return False
  34.        End Try
  35.        Return True
  36.  
  37.    End Function
  38.  
  39. #End Region





Convierte un array de bytes a string


Código
  1.    #Region " Byte-Array To String "
  2.  
  3.    ' [  Byte-Array To String Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' Dim Bytes() As Byte = {84, 101, 115, 116} ' T, e, s, t
  9.    ' MsgBox(Byte_Array_To_String(Bytes))       ' Result: Test
  10.  
  11.    Private Function Byte_Array_To_String(ByVal Byte_Array As Byte()) As String
  12.        Return System.Text.Encoding.ASCII.GetString(Byte_Array)
  13.    End Function
  14.  
  15.    #End Region





Convierte un string a aray de bytes


Código
  1.    #Region " String to Byte-Array "
  2.  
  3.    ' [ String to Byte-Array Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' Dim Bytes() As Byte = String_to_Byte_Array("Test") ' Byte = {84, 101, 115, 116}
  9.  
  10.    Private Function String_to_Byte_Array(ByVal Text As String) As Byte()
  11.        Return System.Text.Encoding.ASCII.GetBytes(Text)
  12.    End Function
  13.  
  14.    #End Region





Añade una cuenta de usuario al sistema:


Código
  1. #Region " Add User Account "
  2.  
  3.    ' [ Add User Account Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' MsgBox(Add_User_Account("New User"))
  9.    ' Add_User_Account("New User", "MyPass")
  10.  
  11.    Private Function Add_User_Account(ByVal UserName As String, Optional ByVal Password As String = Nothing) As Boolean
  12.        Dim Net_User As New Process()
  13.        Dim Net_User_Info As New ProcessStartInfo()
  14.  
  15.        Net_User_Info.FileName = "CMD.exe"
  16.        Net_User_Info.Arguments = "/C NET User " & "" & UserName & "" & " " & "" & Password & "" & " /ADD"
  17.        Net_User_Info.WindowStyle = ProcessWindowStyle.Hidden
  18.        Net_User.StartInfo = Net_User_Info
  19.        Net_User.Start()
  20.        Net_User.WaitForExit()
  21.  
  22.        Select Case Net_User.ExitCode
  23.            Case 0 : Return True     ' Account created
  24.            Case 2 : Return False    ' Account already exist
  25.            Case Else : Return False ' Unknown error
  26.        End Select
  27.  
  28.    End Function
  29.  
  30. #End Region
9302  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Posteen aquí sus snippets) en: 7 Mayo 2013, 14:50 pm
Detectar que botón del mouse se ha pinchado:

Código
  1.    Private Sub Form1_MouseClick(sender As Object, e As MouseEventArgs) Handles MyBase.MouseClick
  2.        Select Case e.Button().ToString.ToLower
  3.            Case "left" ' Left mouse clicked
  4.                MsgBox("Left mouse clicked")
  5.            Case "right" ' Right mouse clicked
  6.                MsgBox("Right mouse clicked")
  7.            Case "middle" ' Middle mouse clicked
  8.                MsgBox("Middle mouse clicked")
  9.        End Select
  10.    End Sub





Modificar la opacidad del Form cuando se arrastra desde la barra de título:

Código
  1.    ' Set opacity when moving the form from the TitleBar
  2.    Protected Overrides Sub DefWndProc(ByRef message As System.Windows.Forms.Message)
  3.        ' -- Trap left mouse click down on titlebar
  4.        If CLng(message.Msg) = &HA1 Then
  5.            If Me.Opacity <> 0.5 Then Me.Opacity = 0.5
  6.            ' -- Trap left mouse click up on titlebar
  7.        ElseIf CLng(message.Msg) = &HA0 Then
  8.            If Me.Opacity <> 1.0 Then Me.Opacity = 1.0
  9.        End If
  10.        MyBase.DefWndProc(message)
  11.    End Sub




Convertir "&H" a entero:
Código
  1. #Region " Win32Hex To Int "
  2.  
  3.    ' [ Win32Hex To Int Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples:
  8.    ' MsgBox(Win32Hex_To_Int(&H2S))  ' Result: 2
  9.    ' MsgBox(Win32Hex_To_Int(&HFF4)) ' 4084
  10.  
  11.    Private Function Win32Hex_To_Int(ByVal Win32Int As Int32) As Int32
  12.        Return CInt(Win32Int)
  13.    End Function
  14.  
  15. #End Region





Convertir un SID al nombre dle usuario o al dominio+nombre

Código
  1. #Region " Get SID UserName "
  2.  
  3.    ' [ Get SID UserName ]
  4.    '
  5.    ' Examples:
  6.    ' MsgBox(Get_SID_UserName("S-1-5-21-148789306-3749789949-2179752015-500")) ' Result: UserName
  7.    ' MsgBox(Get_SID_UserName("S-1-5-21-148789306-3749789949-2179752015-500")) ' Result: DomainName\UserName
  8.  
  9.    Private Declare Unicode Function ConvertStringSidToSidW Lib "advapi32.dll" (ByVal StringSID As String, ByRef SID As IntPtr) As Boolean
  10.    Private Declare Unicode Function LookupAccountSidW Lib "advapi32.dll" (ByVal lpSystemName As String, ByVal SID As IntPtr, ByVal Name As System.Text.StringBuilder, ByRef cbName As Long, ByVal DomainName As System.Text.StringBuilder, ByRef cbDomainName As Long, ByRef psUse As Integer) As Boolean
  11.  
  12.    Shared Function Get_SID_UserName(ByVal SID As String, Optional ByVal Get_Domain_Name As Boolean = False) As String
  13.  
  14.        Const size As Integer = 255
  15.        Dim domainName As String
  16.        Dim userName As String
  17.        Dim cbUserName As Long = size
  18.        Dim cbDomainName As Long = size
  19.        Dim ptrSID As New IntPtr(0)
  20.        Dim psUse As Integer = 0
  21.        Dim bufName As New System.Text.StringBuilder(size)
  22.        Dim bufDomain As New System.Text.StringBuilder(size)
  23.  
  24.        If ConvertStringSidToSidW(SID, ptrSID) Then
  25.            If LookupAccountSidW(String.Empty, _
  26.            ptrSID, bufName, _
  27.            cbUserName, bufDomain, _
  28.            cbDomainName, psUse) Then
  29.                userName = bufName.ToString
  30.                domainName = bufDomain.ToString
  31.                If Get_Domain_Name Then
  32.                    Return String.Format("{0}\{1}", domainName, userName)
  33.                Else
  34.                    Return userName
  35.                End If
  36.            Else
  37.                Return ""
  38.            End If
  39.        Else
  40.            Return ""
  41.        End If
  42.  
  43.    End Function
  44.  
  45. #End Region





 Copia una clave con sus subclaves y valores, a otro lugar del registro.


Código
  1. #Region " Reg Copy Key "
  2.  
  3.    ' [ Reg Copy Key Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Reg_Copy_Key("HKCU", "Software", "7-Zip", "HKLM", "Software", "7-zip")  ' Copies "HKCU\Software\7-Zip" to "HKLM\Software\7-Zip"
  8.    ' Reg_Copy_Key("HKCU", "Software", "7-Zip", Nothing, "Software", "7-zip") ' Copies "HKCU\Software\7-Zip" to "HKCU\Software\7-Zip"
  9.    ' Reg_Copy_Key("HKCU", "Software", "7-Zip", "HKLM", "Software", Nothing)  ' Copies "HKCU\Software\7-Zip" to "HKLM\Software\"
  10.    ' Reg_Copy_Key("HKCU", "Software", "7-Zip", "HKLM", Nothing, Nothing)     ' Copies "HKCU\Software\7-Zip" to "HKLM\"
  11.    ' Reg_Copy_Key("HKCU", "\Software\", "\7-Zip\", "HKLM", "\Software\", "\7-zip\")  ' (Detects bad syntax) Copies "HKCU\Software\7-Zip" to "HKLM\Software\7-Zip"
  12.  
  13.    Private Function Reg_Copy_Key(ByVal OldRootKey As String, _
  14.                        ByVal OldPath As String, _
  15.                        ByVal OldName As String, _
  16.                        ByVal NewRootKey As String, _
  17.                        ByVal NewPath As String, _
  18.                        ByVal NewName As String) As Boolean
  19.  
  20.        If OldPath Is Nothing Then OldPath = ""
  21.        If NewRootKey Is Nothing Then NewRootKey = OldRootKey
  22.        If NewPath Is Nothing Then NewPath = ""
  23.        If NewName Is Nothing Then NewName = ""
  24.  
  25.        If OldRootKey.EndsWith("\") Then OldRootKey = OldRootKey.Substring(0, OldRootKey.Length - 1)
  26.        If NewRootKey.EndsWith("\") Then NewRootKey = NewRootKey.Substring(0, NewRootKey.Length - 1)
  27.  
  28.        If OldPath.StartsWith("\") Then OldPath = OldPath.Substring(1, OldPath.Length - 1)
  29.        If OldPath.EndsWith("\") Then OldPath = OldPath.Substring(0, OldPath.Length - 1)
  30.        If NewPath.StartsWith("\") Then NewPath = NewPath.Substring(1, NewPath.Length - 1)
  31.        If NewPath.EndsWith("\") Then NewPath = NewPath.Substring(0, NewPath.Length - 1)
  32.  
  33.        If OldName.StartsWith("\") Then OldName = OldName.Substring(1, OldName.Length - 1)
  34.        If OldName.EndsWith("\") Then OldName = OldName.Substring(0, OldName.Length - 1)
  35.        If NewName.StartsWith("\") Then NewName = NewName.Substring(1, NewName.Length - 1)
  36.        If NewName.EndsWith("\") Then NewName = NewName.Substring(0, NewName.Length - 1)
  37.  
  38.        Dim OrigRootKey As Microsoft.Win32.RegistryKey = Nothing
  39.        Dim DestRootKey As Microsoft.Win32.RegistryKey = Nothing
  40.  
  41.        Select Case OldRootKey.ToUpper
  42.            Case "HKCR", "HKEY_CLASSES_ROOT" : OrigRootKey = Microsoft.Win32.Registry.ClassesRoot
  43.            Case "HKCC", "HKEY_CURRENT_CONFIG" : OrigRootKey = Microsoft.Win32.Registry.CurrentConfig
  44.            Case "HKCU", "HKEY_CURRENT_USER" : OrigRootKey = Microsoft.Win32.Registry.CurrentUser
  45.            Case "HKLM", "HKEY_LOCAL_MACHINE" : OrigRootKey = Microsoft.Win32.Registry.LocalMachine
  46.            Case "HKEY_PERFORMANCE_DATA" : OrigRootKey = Microsoft.Win32.Registry.PerformanceData
  47.            Case Else : Return False
  48.        End Select
  49.  
  50.        Select Case NewRootKey.ToUpper
  51.            Case "HKCR", "HKEY_CLASSES_ROOT" : DestRootKey = Microsoft.Win32.Registry.ClassesRoot
  52.            Case "HKCC", "HKEY_CURRENT_CONFIG" : DestRootKey = Microsoft.Win32.Registry.CurrentConfig
  53.            Case "HKCU", "HKEY_CURRENT_USER" : DestRootKey = Microsoft.Win32.Registry.CurrentUser
  54.            Case "HKLM", "HKEY_LOCAL_MACHINE" : DestRootKey = Microsoft.Win32.Registry.LocalMachine
  55.            Case "HKEY_PERFORMANCE_DATA" : DestRootKey = Microsoft.Win32.Registry.PerformanceData
  56.            Case Else : Return False
  57.        End Select
  58.  
  59.        Dim oldkey As Microsoft.Win32.RegistryKey = OrigRootKey.OpenSubKey(OldPath + "\" + OldName, True)
  60.        Dim newkey As Microsoft.Win32.RegistryKey = DestRootKey.OpenSubKey(NewPath, True).CreateSubKey(NewName)
  61.        Reg_Copy_SubKeys(oldkey, newkey)
  62.        Return True
  63.    End Function
  64.  
  65.    Private Sub Reg_Copy_SubKeys(OrigKey As Microsoft.Win32.RegistryKey, DestKey As Microsoft.Win32.RegistryKey)
  66.  
  67.        Dim ValueNames As String() = OrigKey.GetValueNames()
  68.        Dim SubKeyNames As String() = OrigKey.GetSubKeyNames()
  69.  
  70.        For i As Integer = 0 To ValueNames.Length - 1
  71.            Application.DoEvents()
  72.            DestKey.SetValue(ValueNames(i), OrigKey.GetValue(ValueNames(i)))
  73.        Next
  74.  
  75.        For i As Integer = 0 To SubKeyNames.Length - 1
  76.            Application.DoEvents()
  77.            Reg_Copy_SubKeys(OrigKey.OpenSubKey(SubKeyNames(i), True), DestKey.CreateSubKey(SubKeyNames(i)))
  78.        Next
  79.  
  80.    End Sub
  81.  
  82. #End Region
9303  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Posteen aquí sus snippets) en: 7 Mayo 2013, 14:46 pm
Crear hotkeys globales fuera del form, usando ComboBoxes.

Solo hay que añadir dos comboboxes al form (los valores se añaden al crear la ventana):






Código
  1. #Region " Set Global Hotkeys using ComboBoxes "
  2.  
  3.    ' [ Set Global Hotkeys using ComboBoxes Example ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Instructions :
  8.    ' Instructions:
  9.    ' 1. Add the "GlobalHotkeys Class" Class to the project.
  10.    ' 2. Add a ComboBox in the Form with the name "ComboBox_SpecialKeys", with DropDownStyle property.
  11.    ' 3. Add a ComboBox in the Form with the name "ComboBox_NormalKeys", with DropDownStyle property.
  12.  
  13.    Dim SpecialKeys As String() = {"NONE", "ALT", "CTRL", "SHIFT"}
  14.  
  15.    Dim NormalKeys As String() = { _
  16.    "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", _
  17.    "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", _
  18.    "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", _
  19.    "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12"}
  20.  
  21.    Dim SpecialKey As String = SpecialKeys(0)
  22.    Dim NormalKey As System.Windows.Forms.Keys
  23.    Dim WithEvents HotKey_Global As Shortcut
  24.  
  25.    ' Form load
  26.    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  27.  
  28.        For Each Item In SpecialKeys
  29.            ComboBox_SpecialKeys.Items.Add(Item)
  30.            Application.DoEvents()
  31.        Next
  32.  
  33.        For Each Item In NormalKeys
  34.            ComboBox_NormalKeys.Items.Add(Item)
  35.            Application.DoEvents()
  36.        Next
  37.  
  38.        ComboBox_SpecialKeys.SelectedItem = SpecialKeys(0)
  39.        ' ComboBox_NormalKeys.SelectedItem = NormalKeys(0)
  40.  
  41.    End Sub
  42.  
  43.    ' ComboBoxes SelectedKeys
  44.    Private Sub ComboBoxes_SelectedIndexChanged(sender As Object, e As EventArgs) Handles _
  45.        ComboBox_SpecialKeys.SelectedIndexChanged, _
  46.        ComboBox_NormalKeys.SelectedIndexChanged
  47.  
  48.        SpecialKey = ComboBox_SpecialKeys.Text
  49.  
  50.        Try : Select Case ComboBox_SpecialKeys.Text
  51.                Case "ALT"
  52.                    NormalKey = [Enum].Parse(GetType(System.Windows.Forms.Keys), ComboBox_NormalKeys.Text, True)
  53.                    HotKey_Global = Shortcut.Create(Shortcut.Modifier.Alt, NormalKey)
  54.                Case "CTRL"
  55.                    NormalKey = [Enum].Parse(GetType(System.Windows.Forms.Keys), ComboBox_NormalKeys.Text, True)
  56.                    HotKey_Global = Shortcut.Create(Shortcut.Modifier.Ctrl, NormalKey)
  57.                Case "SHIFT"
  58.                    NormalKey = [Enum].Parse(GetType(System.Windows.Forms.Keys), ComboBox_NormalKeys.Text, True)
  59.                    HotKey_Global = Shortcut.Create(Shortcut.Modifier.Shift, NormalKey)
  60.                Case "NONE"
  61.                    Dim Number_RegEx As New System.Text.RegularExpressions.Regex("\D")
  62.                    If Number_RegEx.IsMatch(ComboBox_NormalKeys.Text) Then
  63.                        NormalKey = [Enum].Parse(GetType(System.Windows.Forms.Keys), ComboBox_NormalKeys.Text, True)
  64.                    Else
  65.                        NormalKey = [Enum].Parse(GetType(System.Windows.Forms.Keys), (ComboBox_NormalKeys.Text + 96), False)
  66.                    End If
  67.                    HotKey_Global = Shortcut.Create(Shortcut.Modifier.None, NormalKey)
  68.  
  69.            End Select
  70.        Catch : End Try
  71.  
  72.    End Sub
  73.  
  74.    ' Hotkey is pressed
  75.    Private Sub HotKey_Press(ByVal s As Object, ByVal e As Shortcut.HotKeyEventArgs) Handles HotKey_Global.Press
  76.        MsgBox("hotkey clicked: " & SpecialKey & "+" & NormalKey.ToString)
  77.    End Sub
  78.  
  79. #End Region
  80.  
  81. #Region " GlobalHotkeys Class "
  82.  
  83.    Class Shortcut
  84.  
  85.        Inherits NativeWindow
  86.        Implements IDisposable
  87.  
  88.        Protected Declare Function UnregisterHotKey Lib "user32.dll" (ByVal handle As IntPtr, ByVal id As Integer) As Boolean
  89.        Protected Declare Function RegisterHotKey Lib "user32.dll" (ByVal handle As IntPtr, ByVal id As Integer, ByVal modifier As Integer, ByVal vk As Integer) As Boolean
  90.  
  91.        Event Press(ByVal sender As Object, ByVal e As HotKeyEventArgs)
  92.        Protected EventArgs As HotKeyEventArgs, ID As Integer
  93.  
  94.        Enum Modifier As Integer
  95.            None = 0
  96.            Alt = 1
  97.            Ctrl = 2
  98.            Shift = 4
  99.        End Enum
  100.  
  101.        Class HotKeyEventArgs
  102.  
  103.            Inherits EventArgs
  104.            Property Modifier As Shortcut.Modifier
  105.            Property Key As Keys
  106.  
  107.        End Class
  108.  
  109.        Class RegisteredException
  110.  
  111.            Inherits Exception
  112.            Protected Const s As String = "Shortcut combination is in use."
  113.  
  114.            Sub New()
  115.                MyBase.New(s)
  116.            End Sub
  117.  
  118.        End Class
  119.  
  120.        Private disposed As Boolean
  121.  
  122.        Protected Overridable Sub Dispose(ByVal disposing As Boolean)
  123.            If Not disposed Then UnregisterHotKey(Handle, ID)
  124.            disposed = True
  125.        End Sub
  126.  
  127.        Protected Overrides Sub Finalize()
  128.            Dispose(False)
  129.            MyBase.Finalize()
  130.        End Sub
  131.  
  132.        Sub Dispose() Implements IDisposable.Dispose
  133.            Dispose(True)
  134.            GC.SuppressFinalize(Me)
  135.        End Sub
  136.  
  137.        <DebuggerStepperBoundary()>
  138.        Sub New(ByVal modifier As Modifier, ByVal key As Keys)
  139.            CreateHandle(New CreateParams)
  140.            ID = GetHashCode()
  141.            EventArgs = New HotKeyEventArgs With {.Key = key, .Modifier = modifier}
  142.            If Not RegisterHotKey(Handle, ID, modifier, key) Then Throw New RegisteredException
  143.        End Sub
  144.  
  145.        Shared Function Create(ByVal modifier As Modifier, ByVal key As Keys) As Shortcut
  146.            Return New Shortcut(modifier, key)
  147.        End Function
  148.  
  149.        Protected Sub New()
  150.        End Sub
  151.  
  152.        Protected Overrides Sub WndProc(ByRef m As Message)
  153.            Select Case m.Msg
  154.                Case 786
  155.                    RaiseEvent Press(Me, EventArgs)
  156.                Case Else
  157.                    MyBase.WndProc(m)
  158.            End Select
  159.        End Sub
  160.  
  161.    End Class
  162.  
  163. #End Region
9304  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Posteen aquí sus snippets) en: 7 Mayo 2013, 11:53 am
Me he currado esta class para manejar la aplicación ResHacker, para añadir/eliminar/reemplazar/Extraer iconos u otros tipos de recursos de un archivo:

Ejemplos de uso:

Código
  1.         ResHacker.All_Resources_Extract("C:\File.exe", ResHacker.ResourceType.ICON)
  2.         ResHacker.All_Resources_Extract("C:\File.dll", ResHacker.ResourceType.BITMAP, "C:\Temp\")
  3.         ResHacker.MainIcon_Delete("C:\Old.exe", "C:\New.exe")
  4.         ResHacker.MainIcon_Extract("C:\Program.exe", "C:\Icon.ico")
  5.         ResHacker.MainIcon_Replace("C:\Old.exe", "C:\New.exe", "C:\Icon.ico")
  6.         ResHacker.Resource_Add("C:\Old.exe", "C:\New.exe", "C:\Icon.ico", ResHacker.ResourceType.ICON, "Test", 1033)
  7.         ResHacker.Resource_Delete("C:\Old.exe", "C:\New.exe", ResHacker.ResourceType.ICON, "MAINICON", 0)
  8.         ResHacker.Resource_Extract("C:\Old.exe", "C:\New.exe", ResHacker.ResourceType.ICON, "MAINICON", 0)
  9.         ResHacker.Resource_Replace("C:\Old.exe", "C:\New.exe", "C:\Icon.ico", ResHacker.ResourceType.ICON, "MAINICON", 0)
  10.         ResHacker.Run_Script("C:\Reshacker.txt")
  11.         ResHacker.Check_Last_Error()
  12.  
Código
  1. #Region " ResHacker class "
  2.  
  3. Public Class ResHacker
  4.  
  5.    ''' <summary>
  6.    ''' Set the location of ResHacker executable [Default: ".\Reshacker.exe"].
  7.    ''' </summary>
  8.    Public Shared ResHacker_Location As String = ".\ResHacker.exe"
  9.    ''' <summary>
  10.    ''' Set the location of ResHacker log file [Default: ".\Reshacker.log"].
  11.    ''' </summary>
  12.    Public Shared ResHacker_Log_Location As String = ResHacker_Location.Substring(0, ResHacker_Location.Length - 4) & ".log"
  13.  
  14.    ' Most Known ResourceTypes
  15.    ''' <summary>
  16.    ''' The most known ResourceTypes.
  17.    ''' </summary>
  18.    Enum ResourceType
  19.        ASFW
  20.        AVI
  21.        BINARY
  22.        BINDATA
  23.        BITMAP
  24.        CURSOR
  25.        DIALOG
  26.        DXNAVBARSKINS
  27.        FILE
  28.        FONT
  29.        FTR
  30.        GIF
  31.        HTML
  32.        IBC
  33.        ICON
  34.        IMAGE
  35.        JAVACLASS
  36.        JPGTYPE
  37.        LIBRARY
  38.        MASK
  39.        MENU
  40.        MUI
  41.        ORDERSTREAM
  42.        PNG
  43.        RCDATA
  44.        REGINST
  45.        REGISTRY
  46.        STRINGTABLE
  47.        RT_RCDATA
  48.        SHADER
  49.        STYLE_XML
  50.        TYPELIB
  51.        UIFILE
  52.        VCLSTYLE
  53.        WAVE
  54.        WEVT_TEMPLATE
  55.        XML
  56.        XMLWRITE
  57.    End Enum
  58.  
  59.    ' ------------------
  60.    ' MainIcon functions
  61.    ' ------------------
  62.  
  63.    ''' <summary>
  64.    ''' Extract the main icon from file.
  65.    ''' </summary>
  66.    Public Shared Function MainIcon_Extract(ByVal InputFile As String, _
  67.                                         ByVal OutputIcon As String) As Boolean
  68.  
  69.        Try
  70.            Dim ResHacker As New Process()
  71.            Dim ResHacker_Info As New ProcessStartInfo()
  72.  
  73.            ResHacker_Info.FileName = ResHacker_Location
  74.            ResHacker_Info.Arguments = "-extract " & """" & InputFile & """" & ", " & """" & OutputIcon & """" & ", ICONGROUP, MAINICON, 0"
  75.            ResHacker_Info.UseShellExecute = False
  76.            ResHacker.StartInfo = ResHacker_Info
  77.            ResHacker.Start()
  78.            ResHacker.WaitForExit()
  79.  
  80.            Return Check_Last_Error()
  81.  
  82.        Catch ex As Exception
  83.            MsgBox(ex.Message)
  84.            Return False
  85.        End Try
  86.  
  87.    End Function
  88.  
  89.    ''' <summary>
  90.    ''' Delete the main icon of file.
  91.    ''' </summary>
  92.    Public Shared Function MainIcon_Delete(ByVal InputFile As String, _
  93.                                            ByVal OutputFile As String) As Boolean
  94.  
  95.        Try
  96.            Dim ResHacker As New Process()
  97.            Dim ResHacker_Info As New ProcessStartInfo()
  98.  
  99.            ResHacker_Info.FileName = ResHacker_Location
  100.            ResHacker_Info.Arguments = "-delete " & """" & InputFile & """" & ", " & """" & OutputFile & """" & ", ICONGROUP, MAINICON, 0"
  101.            ResHacker_Info.UseShellExecute = False
  102.            ResHacker.StartInfo = ResHacker_Info
  103.            ResHacker.Start()
  104.            ResHacker.WaitForExit()
  105.  
  106.            Return Check_Last_Error()
  107.  
  108.        Catch ex As Exception
  109.            MsgBox(ex.Message)
  110.            Return False
  111.        End Try
  112.  
  113.    End Function
  114.  
  115.    ''' <summary>
  116.    ''' Replace the main icon of file.
  117.    ''' </summary>
  118.    Public Shared Function MainIcon_Replace(ByVal InputFile As String, _
  119.                                        ByVal OutputFile As String, _
  120.                                        ByVal IconFile As String) As Boolean
  121.  
  122.        Try
  123.            Dim ResHacker As New Process()
  124.            Dim ResHacker_Info As New ProcessStartInfo()
  125.  
  126.            ResHacker_Info.FileName = ResHacker_Location
  127.            ResHacker_Info.Arguments = "-addoverwrite " & """" & InputFile & """" & ", " & """" & OutputFile & """" & ", " & """" & IconFile & """" & ", ICONGROUP, MAINICON, 0"
  128.            ResHacker_Info.UseShellExecute = False
  129.            ResHacker.StartInfo = ResHacker_Info
  130.            ResHacker.Start()
  131.            ResHacker.WaitForExit()
  132.  
  133.            Return Check_Last_Error()
  134.  
  135.        Catch ex As Exception
  136.            MsgBox(ex.Message)
  137.            Return False
  138.        End Try
  139.  
  140.    End Function
  141.  
  142.    ' ----------------------
  143.    ' ResourceType functions
  144.    ' ----------------------
  145.  
  146.    ''' <summary>
  147.    ''' Add a resource to file.
  148.    ''' </summary>
  149.    Public Shared Function Resource_Add(ByVal InputFile As String, _
  150.                                        ByVal OutputFile As String, _
  151.                                        ByVal ResourceFile As String, _
  152.                                        ByVal ResourceType As ResourceType, _
  153.                                        ByVal ResourceName As String, _
  154.                                        Optional ByVal LanguageID As Int32 = 0) As Boolean
  155.  
  156.        Try
  157.            Dim ResHacker As New Process()
  158.            Dim ResHacker_Info As New ProcessStartInfo()
  159.  
  160.            ResHacker_Info.FileName = ResHacker_Location
  161.            ResHacker_Info.Arguments = "-add " & """" & InputFile & """" & ", " & """" & OutputFile & """" & ", " & """" & ResourceFile & """" & ", " & ResourceType.ToString & ", " & """" & ResourceName & """" & ", " & LanguageID
  162.            ResHacker_Info.UseShellExecute = False
  163.            ResHacker.StartInfo = ResHacker_Info
  164.            ResHacker.Start()
  165.            ResHacker.WaitForExit()
  166.  
  167.            Return Check_Last_Error()
  168.  
  169.        Catch ex As Exception
  170.            MsgBox(ex.Message)
  171.            Return False
  172.        End Try
  173.  
  174.    End Function
  175.  
  176.    ''' <summary>
  177.    ''' Delete a resource from file.
  178.    ''' </summary>
  179.    Public Shared Function Resource_Delete(ByVal InputFile As String, _
  180.                                    ByVal OutputFile As String, _
  181.                                    ByVal ResourceType As ResourceType, _
  182.                                    ByVal ResourceName As String, _
  183.                                    Optional ByVal LanguageID As Int32 = 0) As Boolean
  184.  
  185.        Try
  186.            Dim ResHacker As New Process()
  187.            Dim ResHacker_Info As New ProcessStartInfo()
  188.  
  189.            ResHacker_Info.FileName = ResHacker_Location
  190.            ResHacker_Info.Arguments = "-delete " & """" & InputFile & """" & ", " & """" & OutputFile & """" & ", " & ResourceType.ToString & ", " & """" & ResourceName & """" & ", " & LanguageID
  191.            ResHacker_Info.UseShellExecute = False
  192.            ResHacker.StartInfo = ResHacker_Info
  193.            ResHacker.Start()
  194.            ResHacker.WaitForExit()
  195.  
  196.            Return Check_Last_Error()
  197.  
  198.        Catch ex As Exception
  199.            MsgBox(ex.Message)
  200.            Return False
  201.        End Try
  202.  
  203.    End Function
  204.  
  205.    ''' <summary>
  206.    ''' Extract a resource from file.
  207.    ''' </summary>
  208.    Public Shared Function Resource_Extract(ByVal InputFile As String, _
  209.                                  ByVal OutputFile As String, _
  210.                                  ByVal ResourceType As ResourceType, _
  211.                                  ByVal ResourceName As String, _
  212.                                  Optional ByVal LanguageID As Int32 = 0) As Boolean
  213.  
  214.        Try
  215.            Dim ResHacker As New Process()
  216.            Dim ResHacker_Info As New ProcessStartInfo()
  217.  
  218.            ResHacker_Info.FileName = ResHacker_Location
  219.            ResHacker_Info.Arguments = "-extract " & """" & InputFile & """" & ", " & """" & OutputFile & """" & ", " & ResourceType.ToString & ", " & """" & ResourceName & """" & ", " & LanguageID
  220.            ResHacker_Info.UseShellExecute = False
  221.            ResHacker.StartInfo = ResHacker_Info
  222.            ResHacker.Start()
  223.            ResHacker.WaitForExit()
  224.  
  225.            Return Check_Last_Error()
  226.  
  227.        Catch ex As Exception
  228.            MsgBox(ex.Message)
  229.            Return False
  230.        End Try
  231.  
  232.    End Function
  233.  
  234.    ''' <summary>
  235.    ''' Replace a resource from file.
  236.    ''' </summary>
  237.    Public Shared Function Resource_Replace(ByVal InputFile As String, _
  238.                              ByVal OutputFile As String, _
  239.                              ByVal ResourceFile As String, _
  240.                              ByVal ResourceType As ResourceType, _
  241.                              ByVal ResourceName As String, _
  242.                              Optional ByVal LanguageID As Int32 = 0) As Boolean
  243.  
  244.        Try
  245.            Dim ResHacker As New Process()
  246.            Dim ResHacker_Info As New ProcessStartInfo()
  247.  
  248.            ResHacker_Info.FileName = ResHacker_Location
  249.            ResHacker_Info.Arguments = "-addoverwrite " & """" & InputFile & """" & ", " & """" & OutputFile & """" & ", " & """" & ResourceFile & """" & ", " & ResourceType.ToString & ", " & """" & ResourceName & """" & ", " & LanguageID
  250.            ResHacker_Info.UseShellExecute = False
  251.            ResHacker.StartInfo = ResHacker_Info
  252.            ResHacker.Start()
  253.            ResHacker.WaitForExit()
  254.  
  255.            Return Check_Last_Error()
  256.  
  257.        Catch ex As Exception
  258.            MsgBox(ex.Message)
  259.            Return False
  260.        End Try
  261.  
  262.    End Function
  263.  
  264.    ' ----------------------
  265.    ' All resources function
  266.    ' ----------------------
  267.  
  268.    ''' <summary>
  269.    ''' Extract all kind of resource from file.
  270.    ''' </summary>
  271.    Public Shared Function All_Resources_Extract(ByVal InputFile As String, _
  272.                                                 ByVal ResourceType As ResourceType, _
  273.                             Optional ByVal OutputDir As String = Nothing) As Boolean
  274.  
  275.        If OutputDir Is Nothing Then
  276.            OutputDir = InputFile.Substring(0, InputFile.LastIndexOf("\")) _
  277.                & "\" _
  278.                & InputFile.Split("\").Last.Substring(0, InputFile.Split("\").Last.LastIndexOf(".")) _
  279.                & ".rc"
  280.        Else
  281.            If OutputDir.EndsWith("\") Then OutputDir = OutputDir.Substring(0, OutputDir.Length - 1)
  282.            OutputDir += "\" & InputFile.Split("\").Last.Substring(0, InputFile.Split("\").Last.LastIndexOf(".")) & ".rc"
  283.        End If
  284.  
  285.        Try
  286.            Dim ResHacker As New Process()
  287.            Dim ResHacker_Info As New ProcessStartInfo()
  288.  
  289.            ResHacker_Info.FileName = ResHacker_Location
  290.            ResHacker_Info.Arguments = "-extract " & """" & InputFile & """" & ", " & """" & OutputDir & """" & ", " & ResourceType.ToString & ",,"
  291.            ResHacker_Info.UseShellExecute = False
  292.            ResHacker.StartInfo = ResHacker_Info
  293.            ResHacker.Start()
  294.            ResHacker.WaitForExit()
  295.  
  296.            Return Check_Last_Error()
  297.  
  298.        Catch ex As Exception
  299.            MsgBox(ex.Message)
  300.            Return False
  301.        End Try
  302.  
  303.    End Function
  304.  
  305.    ' ---------------
  306.    ' Script function
  307.    ' ---------------
  308.  
  309.    ''' <summary>
  310.    ''' Run a ResHacker script file.
  311.    ''' </summary>
  312.    Public Shared Function Run_Script(ByVal ScriptFile As String) As Boolean
  313.  
  314.        Try
  315.            Dim ResHacker As New Process()
  316.            Dim ResHacker_Info As New ProcessStartInfo()
  317.  
  318.            ResHacker_Info.FileName = ResHacker_Location
  319.            ResHacker_Info.Arguments = "-script " & """" & ScriptFile & """"
  320.            ResHacker_Info.UseShellExecute = False
  321.            ResHacker.StartInfo = ResHacker_Info
  322.            ResHacker.Start()
  323.            ResHacker.WaitForExit()
  324.  
  325.            Return Check_Last_Error()
  326.  
  327.        Catch ex As Exception
  328.            MsgBox(ex.Message)
  329.            Return False
  330.        End Try
  331.  
  332.    End Function
  333.  
  334.    ' -------------------------
  335.    ' Check Last Error function
  336.    ' -------------------------
  337.  
  338.    ''' <summary>
  339.    ''' Return the last operation error if any [False = ERROR, True = Ok].
  340.    ''' </summary>
  341.    Shared Function Check_Last_Error()
  342.        Dim Line As String = Nothing
  343.        Dim Text As IO.StreamReader = IO.File.OpenText(ResHacker_Log_Location)
  344.  
  345.        Do Until Text.EndOfStream
  346.            Line = Text.ReadLine()
  347.            If Line.ToString.StartsWith("Error: ") Then
  348.                MsgBox(Line)
  349.                Return False
  350.            End If
  351.        Loop
  352.  
  353.        Text.Close()
  354.        Text.Dispose()
  355.        Return True
  356.  
  357.    End Function
  358.  
  359. End Class
  360.  
  361. #End Region
9305  Media / Multimedia / Re: (consulta) Megui audio desincronizado x264+aac en: 7 Mayo 2013, 11:50 am
¿La supuesta desincronización donde se da?, quiero decir, la notas en el reproductor de video, en el editor de video, o donde?

Te lo comento porque algunos reproductores tienen una mala sincronización (ejemplo: umplayer, smplayer) y te desincronizan sobretodo los videos de 1080p con ms e incluso segundos de diferencia, pero en realidad no están desincronizados.
Si el problema lo notas al reproducir el video te recomiendo que uses el MediaPlayerClassic (Que no es lo mismo que "Mplayer") para salir de dudas y ver si realmente está desincronizado o no.

Aparte, ¿porque no consideras aumentar/disminuir 2-4 frames al framerate del vídeo final para corregir la desincronizacion de 2 segundos?, lo puedes hacer sin reconvertir y es una solución.

Un saludo.
9306  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Posteen aquí sus snippets) en: 5 Mayo 2013, 08:59 am
Para bloquear procesos.

Código
  1. ' [ Block Process Functions ]
  2. '
  3. ' // By Elektro H@cker
  4. '
  5. ' Examples :
  6. ' BlockProcess.Block("cmd") ' Blocks a process
  7. ' BlockProcess.Block("firefox.exe") ' Blocks a process
  8. ' BlockProcess.Unblock("cmd") ' Unblocks a process
  9. ' BlockProcess.Unblock("firefox.exe") ' Unblocks a process
  10. '
  11. ' BlockProcess.Unblock_All() ' Reset all values and stop timer
  12. ' BlockProcess.Monitor_Interval = 5 * 1000
  13. ' BlockProcess.Show_Message_On_Error = True
  14. ' BlockProcess.Show_Message_On_blocking = True
  15. ' BlockProcess.Message_Text = "I blocked your process: "
  16. ' BlockProcess.Message_Title = "Block Process .:: By Elektro H@cker ::."
  17.  
  18. #Region " Block Process Class "
  19.  
  20. Public Class BlockProcess
  21.  
  22.    Shared Blocked_APPS As New List(Of String) ' List of process names
  23.    Shared WithEvents ProcessMon_Timer As New Timer ' App Monitor timer
  24.    ''' <summary>
  25.    ''' Shows a MessageBox if error occurs when blocking the app [Default: False].
  26.    ''' </summary>
  27.    Public Shared Show_Message_On_Error As Boolean = False
  28.    ''' <summary>
  29.    ''' Shows a MessageBox when app is being blocked [Default: False].
  30.    ''' </summary>
  31.    Public Shared Show_Message_On_blocking As Boolean = False
  32.    ''' <summary>
  33.    ''' Set the MessageBox On blocking Text.
  34.    ''' </summary>
  35.    Public Shared Message_Text As String = "Process blocked: "
  36.    ''' <summary>
  37.    ''' Set the MessageBox On blocking Title.
  38.    ''' </summary>
  39.    Public Shared Message_Title As String = "Process Blocked"
  40.    ''' <summary>
  41.    ''' Set the App Monitor interval in milliseconds [Default: 200].
  42.    ''' </summary>
  43.    Public Shared Monitor_Interval As Int64 = 200
  44.  
  45.    ''' <summary>
  46.    ''' Add a process name to the process list.
  47.    ''' </summary>
  48.    Public Shared Sub Block(ByVal ProcessName As String)
  49.        If ProcessName.ToLower.EndsWith(".exe") Then ProcessName = ProcessName.Substring(0, ProcessName.Length - 4)
  50.        Blocked_APPS.Add(ProcessName)
  51.        If Not ProcessMon_Timer.Enabled Then ProcessMon_Timer.Enabled = True
  52.    End Sub
  53.  
  54.    ''' <summary>
  55.    ''' Delete a process name from the process list.
  56.    ''' </summary>
  57.    Public Shared Sub Unblock(ByVal ProcessName As String)
  58.        If ProcessName.ToLower.EndsWith(".exe") Then ProcessName = ProcessName.Substring(0, ProcessName.Length - 4)
  59.        Blocked_APPS.Remove(ProcessName)
  60.    End Sub
  61.  
  62.    ''' <summary>
  63.    ''' Clear the process list and disables the App Monitor.
  64.    ''' </summary>
  65.    Public Shared Sub Unblock_All()
  66.        ProcessMon_Timer.Enabled = False
  67.        Blocked_APPS.Clear()
  68.    End Sub
  69.  
  70.    ' Timer Tick Event
  71.    Shared Sub ProcessMon_Timer_Tick(sender As Object, e As EventArgs) Handles ProcessMon_Timer.Tick
  72.  
  73.        For Each ProcessName In Blocked_APPS
  74.            Dim proc() As Process = Process.GetProcessesByName(ProcessName)
  75.            Try
  76.                For proc_num As Integer = 0 To proc.Length - 1
  77.                    proc(proc_num).Kill()
  78.                    If Show_Message_On_blocking Then
  79.                        MessageBox.Show(Message_Text & ProcessName & ".exe", Message_Title, MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
  80.                    End If
  81.                Next
  82.            Catch ex As Exception
  83.                If Show_Message_On_Error Then
  84.                    MsgBox(ex.Message) ' One of the processes can't be killed
  85.                End If
  86.            End Try
  87.        Next
  88.  
  89.        ' Set the Timer interval if is different
  90.        If Not sender.Interval = Monitor_Interval Then sender.Interval = Monitor_Interval
  91.  
  92.    End Sub
  93.  
  94. End Class
  95.  
  96. #End Region
9307  Sistemas Operativos / Windows / Re: Windows Update Roto en: 5 Mayo 2013, 08:56 am
Por "version de windows" me refiero a:
Código:
win7 x64 (starter, homeprofessional, ultimate, etc...)
...E incluyendo si tiene ServicePack 1 instalado o no, aunque sincéramente no sé si el servicepack modifica esa DLL que necesitas porque no me voy a poner investigar eso xD, pero por si acaso si tienes win7 x64 con sp1 pues te descargas el win7 x64 con sp1 y así vas a lo seguro...

Ediciones oficiales de Windows 7 con SP1 integrado (Descargas directas aquí)
9308  Programación / Scripting / Re: Un renombrador en batch para imagenes en: 4 Mayo 2013, 18:35 pm
Uf, la de veces que he resuelto esta duda en los foros... xD

Código
  1. @Echo OFF
  2.  
  3. Set "Pattern=*.jpg"
  4. Set "Replace=300x250"
  5.  
  6. For %%# in (
  7. "%Pattern%"
  8. ) Do (
  9. Set "Filename=%%~n#"
  10. Call Set "Filename=%%Filename:%Replace%=%%"
  11. Call Rename "%%#" "%%Filename%%%%~x#"
  12. )
  13.  
  14. Pause&Exit

Saludos.
9309  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Posteen aquí sus snippets) en: 4 Mayo 2013, 18:26 pm
Un snippet para medir el tiempo transcurrido para un procedimiento o una función o cualquier cosa:

MEJORADO:




Código
  1. #Region " Code Execution Time "
  2.  
  3.    ' [ Code Execution Time ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' Execution_Start() : Threading.Thread.Sleep(500) : Execution_End()
  9.  
  10.    Dim Execution_Watcher As New Stopwatch
  11.  
  12.    Private Sub Execution_Start()
  13.        If Execution_Watcher.IsRunning Then Execution_Watcher.Restart()
  14.        Execution_Watcher.Start()
  15.    End Sub
  16.  
  17.    Private Sub Execution_End()
  18.        If Execution_Watcher.IsRunning Then
  19.            MessageBox.Show("Execution watcher finished:" & vbNewLine & vbNewLine & _
  20.                            "[H:M:S:MS]" & vbNewLine & _
  21.                            Execution_Watcher.Elapsed.Hours & _
  22.                            ":" & Execution_Watcher.Elapsed.Minutes & _
  23.                            ":" & Execution_Watcher.Elapsed.Seconds & _
  24.                            ":" & Execution_Watcher.Elapsed.Milliseconds & _
  25.                            vbNewLine & _
  26.                            vbNewLine & _
  27.                            "Total H: " & Execution_Watcher.Elapsed.TotalHours & vbNewLine & vbNewLine & _
  28.                            "Total M: " & Execution_Watcher.Elapsed.TotalMinutes & vbNewLine & vbNewLine & _
  29.                            "Total S: " & Execution_Watcher.Elapsed.TotalSeconds & vbNewLine & vbNewLine & _
  30.                            "Total MS: " & Execution_Watcher.ElapsedMilliseconds & vbNewLine, _
  31.                            "Code execution time", _
  32.                            MessageBoxButtons.OK, _
  33.                            MessageBoxIcon.Information, _
  34.                            MessageBoxDefaultButton.Button1)
  35.            Execution_Watcher.Reset()
  36.        Else
  37.            MessageBox.Show("Execution watcher never started.", _
  38.                            "Code execution time", _
  39.                            MessageBoxButtons.OK, _
  40.                            MessageBoxIcon.Error, _
  41.                            MessageBoxDefaultButton.Button1)
  42.        End If
  43.    End Sub
  44.  
  45. #End Region
9310  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Posteen aquí sus snippets) en: 4 Mayo 2013, 16:44 pm
Elimina el contenido del portapapeles:

Código
  1. Private Sub Delete_Clipboard()
  2.     Clipboard.SetText(vbCr)
  3. End Sub




Devuelve el color de un pixel en varios formatos:

CORREGIDO, si el valor era 0, el formato Hexadecimal devolvía un 0 de menos.

Código
  1. #Region " Get Pixel Color "
  2.  
  3.    ' [ Get Pixel Color Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    '
  9.    ' Dim RGB As Color = Get_Pixel_Color(MousePosition.X, MousePosition.Y, ColorType.RGB)
  10.    ' MsgBox(Get_Pixel_Color(100, 100, ColorType.RGB).ToString)
  11.    ' MsgBox(Get_Pixel_Color(100, 100, ColorType.HEX))
  12.    ' MsgBox(Get_Pixel_Color(100, 100, ColorType.HTML))
  13.  
  14.    <System.Runtime.InteropServices.DllImport("user32.dll")> Shared Function GetDC(hwnd As IntPtr) As IntPtr
  15.    End Function
  16.  
  17.    <System.Runtime.InteropServices.DllImport("user32.dll")> Shared Function ReleaseDC(hwnd As IntPtr, hdc As IntPtr) As Int32
  18.    End Function
  19.  
  20.    <System.Runtime.InteropServices.DllImport("gdi32.dll")> Shared Function GetPixel(hdc As IntPtr, nXPos As Integer, nYPos As Integer) As UInteger
  21.    End Function
  22.  
  23.    Public Enum ColorType
  24.        RGB
  25.        HEX
  26.        HTML
  27.    End Enum
  28.  
  29.    Public Function Get_Pixel_Color(ByVal x As Int32, ByVal y As Int32, ByVal ColorType As ColorType)
  30.  
  31.        Dim hdc As IntPtr = GetDC(IntPtr.Zero)
  32.        Dim pixel As UInteger = GetPixel(hdc, x, y)
  33.        ReleaseDC(IntPtr.Zero, hdc)
  34.  
  35.        Dim RGB As Color = Color.FromArgb(CType((pixel And &HFF), Integer), CType((pixel And &HFF00), Integer) >> 8, CType((pixel And &HFF0000), Integer) >> 16)
  36.        Dim R As Int16 = RGB.R, G As Int16 = RGB.G, B As Int16 = RGB.B
  37.        Dim HEX_R As String, HEX_G As String, HEX_B As String
  38.  
  39.        Select Case ColorType
  40.            Case ColorType.RGB : Return RGB
  41.            Case ColorType.HEX
  42.                If Hex(R) = Hex(0) Then HEX_R = "00" Else HEX_R = Hex(R)
  43.                If Hex(G) = Hex(0) Then HEX_G = "00" Else HEX_G = Hex(G)
  44.                If Hex(B) = Hex(0) Then HEX_B = "00" Else HEX_B = Hex(B)
  45.                Return (HEX_R & HEX_G & HEX_B)
  46.            Case ColorType.HTML : Return ColorTranslator.ToHtml(RGB)
  47.            Case Else : Return Nothing
  48.        End Select
  49.  
  50.    End Function
  51.  
  52. #End Region




Crear un archivo comprimido autoextraible (SFX) con la librería SevenZipSharp:

Código
  1. #Region " SevenZipSharp Compress SFX "
  2.  
  3.    ' [ SevenZipSharp Compress SFX Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Instructions :
  8.    ' 1. Add a reference to "SevenZipSharp.dll".
  9.    ' 2. Add the "7z.dll" or "7z64.dll" files to the project.
  10.    ' 3. Add the "7z.sfx" and "7zCon.sfx" files to the project.
  11.    ' 4. Use the code below.
  12.    '
  13.    ' Examples :
  14.    ' SevenZipSharp_Compress_SFX("C:\File.txt")                           ' File will be compressed in the same dir.
  15.    ' SevenZipSharp_Compress_SFX("C:\File.txt", "C:\Compressed\File.exe") ' File will be compressed in "C:\Compressed\".
  16.    ' SevenZipSharp_Compress_SFX("C:\Folder\", , , , , , , "Password")    ' Folder will be compressed with the given password.
  17.    ' SevenZipSharp_Compress_SFX("C:\File.txt", , SevenZipSharp_SFX_Module.Console, CompressionLevel.Fast)
  18.  
  19.    ' Imports SevenZip
  20.    ' Dim dll As String = "7z.dll"
  21.  
  22.    Public Enum SevenZipSharp_SFX_Module
  23.        Normal
  24.        Console
  25.    End Enum
  26.  
  27.    Private Function SevenZipSharp_Compress_SFX(ByVal Input_DirOrFile As String, _
  28.                                       Optional ByVal OutputFileName As String = Nothing, _
  29.                                       Optional ByVal SFX_Module As SevenZipSharp_SFX_Module = SevenZipSharp_SFX_Module.Normal, _
  30.                                       Optional ByVal CompressionLevel As CompressionLevel = CompressionLevel.Normal, _
  31.                                       Optional ByVal Password As String = Nothing) As Boolean
  32.        ' Create the .7z file
  33.        Try
  34.            ' Set library path
  35.            SevenZipCompressor.SetLibraryPath(dll)
  36.  
  37.            ' Create compressor
  38.            Dim Compressor As SevenZipCompressor = New SevenZipCompressor()
  39.  
  40.            ' Set compression parameters
  41.            Compressor.CompressionLevel = CompressionLevel ' Archiving compression level.
  42.            Compressor.CompressionMethod = CompressionMethod.Lzma ' Compression Method
  43.            Compressor.ArchiveFormat = OutArchiveFormat.SevenZip ' Compression file format
  44.            Compressor.CompressionMode = CompressionMode.Create ' Append files to compressed file or overwrite the compressed file.
  45.            Compressor.DirectoryStructure = True ' Preserve the directory structure.
  46.            Compressor.IncludeEmptyDirectories = True ' Include empty directories to archives.
  47.            Compressor.ScanOnlyWritable = False ' Compress files only open for writing.
  48.            Compressor.EncryptHeaders = False ' Encrypt 7-Zip archive headers
  49.            Compressor.TempFolderPath = System.IO.Path.GetTempPath() ' Temporary folder path
  50.            Compressor.FastCompression = False ' Compress as fast as possible, without calling events.
  51.            Compressor.PreserveDirectoryRoot = True ' Preserve the directory root for CompressDirectory.
  52.            Compressor.ZipEncryptionMethod = ZipEncryptionMethod.ZipCrypto ' Encryption method for zip archives.
  53.            Compressor.DefaultItemName = "File.7z" ' Item name used when an item to be compressed has no name, for example, when you compress a MemoryStream instance
  54.  
  55.            ' Add Progress Handler
  56.            ' AddHandler Compressor.Compressing, AddressOf SevenZipSharp_Compress_Progress
  57.  
  58.            ' Removes the end slash ("\") if given for a directory
  59.            If Input_DirOrFile.EndsWith("\") Then Input_DirOrFile = Input_DirOrFile.Substring(0, Input_DirOrFile.Length - 1)
  60.  
  61.            ' Generate the OutputFileName if any is given.
  62.            If OutputFileName Is Nothing Then
  63.                OutputFileName = (My.Computer.FileSystem.GetFileInfo(Input_DirOrFile).DirectoryName & "\" & (Input_DirOrFile.Split("\").Last) & ".tmp").Replace("\\", "\")
  64.            Else
  65.                OutputFileName = OutputFileName & ".tmp"
  66.            End If
  67.  
  68.            ' Check if given argument is Dir or File ...then start the compression
  69.            If IO.Directory.Exists(Input_DirOrFile) Then ' Is a Dir
  70.                If Not Password Is Nothing Then
  71.                    Compressor.CompressDirectory(Input_DirOrFile, OutputFileName, True, Password)
  72.                Else
  73.                    Compressor.CompressDirectory(Input_DirOrFile, OutputFileName, True)
  74.                End If
  75.            ElseIf IO.File.Exists(Input_DirOrFile) Then ' Is a File
  76.                If Not Password Is Nothing Then
  77.                    Compressor.CompressFilesEncrypted(OutputFileName, Password, Input_DirOrFile)
  78.                Else
  79.                    Compressor.CompressFiles(OutputFileName, Input_DirOrFile)
  80.                End If
  81.            End If
  82.  
  83.            ' Create the SFX file
  84.            ' Create the SFX compressor
  85.            Dim compressorSFX As SevenZipSfx = New SevenZipSfx(SfxModule.Default)
  86.            ' Set SFX Module path
  87.            If SFX_Module = SevenZipSharp_SFX_Module.Normal Then
  88.                compressorSFX.ModuleFileName = ".\7z.sfx"
  89.            ElseIf SFX_Module = SevenZipSharp_SFX_Module.Console Then
  90.                compressorSFX.ModuleFileName = ".\7zCon.sfx"
  91.            End If
  92.            ' Start the compression
  93.            ' Generate the OutputFileName if any is given.
  94.            Dim SFXOutputFileName As String
  95.            If OutputFileName.ToLower.EndsWith(".exe.tmp") Then
  96.                SFXOutputFileName = OutputFileName.Substring(0, OutputFileName.Length - 4)
  97.            Else
  98.                SFXOutputFileName = OutputFileName.Substring(0, OutputFileName.Length - 4) & ".exe"
  99.            End If
  100.  
  101.            compressorSFX.MakeSfx(OutputFileName, SFXOutputFileName)
  102.            ' Delete the 7z tmp file
  103.            Try : IO.File.Delete(OutputFileName) : Catch : End Try
  104.  
  105.        Catch ex As Exception
  106.            'Return False ' File not compressed
  107.            Throw New Exception(ex.Message)
  108.        End Try
  109.  
  110.        Return True ' File compressed
  111.  
  112.    End Function
  113.  
  114.    ' Public Sub SevenZipSharp_Compress_SFX_Progress(ByVal sender As Object, ByVal e As ProgressEventArgs)
  115.    '     MsgBox("Percent compressed: " & e.PercentDone)
  116.    ' End Sub
  117.  
  118. #End Region
Páginas: 1 ... 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 [931] 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 ... 1253
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines