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

 

 


Tema destacado: Trabajando con las ramas de git (tercera parte)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  Librería de Snippets para VB.NET !! (Compartan aquí sus snippets)
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: 1 2 3 [4] 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ... 59 Ir Abajo Respuesta Imprimir
Autor Tema: Librería de Snippets para VB.NET !! (Compartan aquí sus snippets)  (Leído 484,582 veces)
Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.809



Ver Perfil
Re: [APORTE] Snippets !! (Posteen aquí sus snippets)
« Respuesta #30 en: 16 Enero 2013, 20:38 pm »

Tienes que intentar mejorar tus conceptos  :¬¬ es algo bastante básico

Pues el que hizo la función original es un pedazo de Coder de CodeProject que ha hecho unos 10 controles extendido... así que quizás si usa ByVal es por algo... no sé, no me culpeis a mí xD.

PD: Cuanto más me adentro en .NET más me doy cuenta que es imposible saberlo todo al milímetro!

Saludos!


En línea

Novlucker
Ninja y
Colaborador
***
Desconectado Desconectado

Mensajes: 10.683

Yo que tu lo pienso dos veces


Ver Perfil
Re: [APORTE] Snippets !! (Posteen aquí sus snippets)
« Respuesta #31 en: 16 Enero 2013, 21:12 pm »

Pues el que hizo la función original es un pedazo de Coder de CodeProject que ha hecho unos 10 controles extendido... así que quizás si usa ByVal es por algo... no sé, no me culpeis a mí xD.

PD: Cuanto más me adentro en .NET más me doy cuenta que es imposible saberlo todo al milímetro!

Ahí es donde se diferencia C# de VB.NET. C# te obliga a hacer cosas que en VB.NET son opcionales, como declarar el tipo de dato de retorno de una función, o sabes que todo objeto va siempre por referencia y los otros por valor (boolean, double, etc), salvo que se especifique que va por referencia :-\

Saludos


« Última modificación: 16 Enero 2013, 21:15 pm por Novlucker » En línea

Contribuye con la limpieza del foro, reporta los "casos perdidos" a un MOD XD
"Hay dos cosas infinitas: el Universo y la estupidez  humana. Y de la primera no estoy muy seguro."
Albert Einstein
ABDERRAMAH


Desconectado Desconectado

Mensajes: 431


en ocasiones uso goto ¬¬


Ver Perfil WWW
Re: [APORTE] Snippets !! (Posteen aquí sus snippets)
« Respuesta #32 en: 16 Enero 2013, 21:23 pm »

El concepto de byval y byref se entiende mejor en c++ que en visualbasic, yo que soy de los que aprendió con vb me costó entender a qué se refiere, en cierta forma es como pasar punteros en c++.
En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.809



Ver Perfil
Re: [APORTE] Snippets !! (Posteen aquí sus snippets)
« Respuesta #33 en: 18 Enero 2013, 07:33 am »

Cargar un recurso embedido (.exe) al disco duro

Código
  1. #Region " Load Resource To Disk Function "
  2.  
  3.    ' [ Load Exe Resource To Disk Function ]
  4.    '
  5.    ' // By Elektro H@cker (Gracias a Kubox)
  6.    '
  7.    ' Examples:
  8.    '
  9.    ' Load__Exe_Resource_To_Disk(My.Resources.Exe_Name, "C:\File.exe")
  10.    ' ' Process.Start("C:\File.exe")
  11.  
  12.    Private Function Load__Exe_Resource_To_Disk(ByVal Resource As Byte(), ByVal Target_File As String) As Boolean
  13.        Try
  14.            Dim File_Buffer As Byte() = Resource
  15.            Dim Buffer_FileStream As New IO.FileStream(Target_File, IO.FileMode.Create, IO.FileAccess.Write)
  16.            Buffer_FileStream.Write(File_Buffer, 0, File_Buffer.Length) : Buffer_FileStream.Close()
  17.            Return True
  18.        Catch ex As Exception
  19.            Return False
  20.        End Try
  21.    End Function
  22.  
  23. #End Region



MessageBox Question - Cancel operation

Código
  1.  Dim Answer = MessageBox.Show("Want to cancel the current operation?", "Cancel", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
  2.  If Answer = MsgBoxResult.Yes Then Application.Exit() Else e.Cancel = True



Mover un archivo, con varias opciones adicionales.

Código
  1. #Region " Move File Function "
  2.  
  3.    ' [ Move File Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    '
  9.    ' MsgBox(Move_File("C:\File.txt", "C:\Test\")) ' Standard move
  10.    ' MsgBox(Move_File("C:\File.txt", "C:\Test\", True)) ' Create the directory if doesn't exists
  11.    ' MsgBox(Move_File("C:\File.txt", "C:\Test\", , True)) ' Replace any existing file
  12.    ' MsgBox(Move_File("C:\File.txt", "C:\Test\", , , IO.FileAttributes.Hidden + IO.FileAttributes.ReadOnly)) ' Apply new attributes
  13.  
  14.    Private Function Move_File(ByVal File As String, ByVal Target_Path As String, _
  15.                               Optional ByVal Force_Target_Path As Boolean = False, Optional ByVal Force_File_Replace As Boolean = False, _
  16.                               Optional ByVal Attributes As System.IO.FileAttributes = IO.FileAttributes.Normal)
  17.  
  18.        Dim File_Information = My.Computer.FileSystem.GetFileInfo(File) ' Get Input File Information
  19.  
  20.        ' Directory
  21.        If Not Force_Target_Path And Not My.Computer.FileSystem.DirectoryExists(Target_Path) Then
  22.            Return False ' Target Directory don't exists
  23.        ElseIf Force_Target_Path Then
  24.            Try
  25.                My.Computer.FileSystem.CreateDirectory(Target_Path) ' Create directory
  26.            Catch ex As Exception
  27.                'Return False
  28.                Return ex.Message ' Directory can't be created maybe beacuse user permissions
  29.            End Try
  30.        End If
  31.  
  32.        ' File
  33.        Try
  34.            My.Computer.FileSystem.MoveFile(File, Target_Path & "\" & File_Information.Name, Force_File_Replace) ' Moves the file
  35.            If Not Attributes = IO.FileAttributes.Normal Then My.Computer.FileSystem.GetFileInfo(Target_Path & "\" & File_Information.Name).Attributes = Attributes ' Apply File Attributes
  36.            Return True ' File is copied OK
  37.        Catch ex As Exception
  38.            'Return False
  39.            Return ex.Message ' File can't be created maybe beacuse user permissions
  40.        End Try
  41.    End Function
  42.  
  43. #End Region
En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.809



Ver Perfil
Re: [APORTE] Snippets !! (Posteen aquí sus snippets)
« Respuesta #34 en: 18 Enero 2013, 11:27 am »

Obtener la arquitectura del OS

Código
  1. #Region " Get OS Architecture Function "
  2.  
  3.    ' [ Get OS Architecture Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' Dim Architecture = Get_OS_Architecture()
  9.  
  10.    Private Function Get_OS_Architecture() As Integer
  11.        Dim Bits = Runtime.InteropServices.Marshal.SizeOf(GetType(IntPtr)) * 8
  12.        Select Case Bits
  13.            Case 32 : Return 32 ' x86
  14.            Case 64 : Return 64 ' x64
  15.            Case Else : Return Nothing ' xD
  16.        End Select
  17.    End Function
  18.  
  19. #End Region



Ejemplo de un overload

Código
  1.    ' Examples:
  2.    '
  3.    ' Test(0)
  4.    ' Test"0")
  5.  
  6.    Sub Test(ByVal Argument As Integer)
  7.        MsgBox("Integer: " & Argument)
  8.    End Sub
  9.  
  10.    Sub Test(ByVal Argument As String)
  11.        MsgBox("String: " & Argument)
  12.    End Sub



El snippet de Get All Files, mejorado:

Código
  1. #Region " Get All Files Function "
  2.  
  3.    ' [ Get All Files Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples:
  8.    '
  9.    ' Dim Files As Array = Get_All_Files("C:\Test", True)
  10.    ' For Each File In Get_All_Files("C:\Test", False) : MsgBox(File) : Next
  11.  
  12.    Private Function Get_All_Files(ByVal Directory As String, Optional ByVal Recursive As Boolean = False) As Array
  13.        If System.IO.Directory.Exists(Directory) Then
  14.            If Not Recursive Then : Return System.IO.Directory.GetFiles(Directory, "*", IO.SearchOption.TopDirectoryOnly)
  15.            Else : Return IO.Directory.GetFiles(Directory, "*", IO.SearchOption.AllDirectories)
  16.            End If
  17.        Else
  18.            Return Nothing
  19.        End If
  20.    End Function
  21.  
  22. #End Region
En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.809



Ver Perfil
Re: [APORTE] Snippets !! (Posteen aquí sus snippets)
« Respuesta #35 en: 18 Enero 2013, 14:06 pm »

No es mucho, pero puede servir...

Obtener la ruta del directorio o del archivo "user.config"

Código
  1. #Region " Get User Config Function "
  2.  
  3.    ' [ Get User Config Function ]
  4.    '
  5.    ' // By Elektro H@cker (Gracias a Seba123Neo)
  6.    '
  7.    ' Examples :
  8.    '
  9.    ' * First add a reference to "System.Configuration" in the proyect
  10.    '
  11.    ' MsgBox(Get_User_Config(User_Config.File))
  12.    ' MsgBox(Get_User_Config(User_Config.Path))
  13.  
  14.    Enum User_Config
  15.        File
  16.        Path
  17.    End Enum
  18.  
  19.    Private Function Get_User_Config(ByVal Setting As User_Config) As String
  20.        Dim UserConfig As String = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.PerUserRoaming).FilePath
  21.        Select Case Setting
  22.            Case User_Config.File : Return UserConfig
  23.            Case User_Config.Path : Return UserConfig.Substring(0, UserConfig.LastIndexOf("\"))
  24.            Case Else : Return False
  25.        End Select
  26.    End Function
  27.  
  28. #End Region
En línea

$Edu$


Desconectado Desconectado

Mensajes: 1.842



Ver Perfil
Re: [APORTE] Snippets !! (Posteen aquí sus snippets)
« Respuesta #36 en: 18 Enero 2013, 15:09 pm »

Se supone que todos los apuntes que has hecho desde que aprendiste vb.net estan aca no? digo porque te los iba a pedir pero veo que estan todos aca xD
En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.809



Ver Perfil
Re: [APORTE] Snippets !! (Posteen aquí sus snippets)
« Respuesta #37 en: 18 Enero 2013, 16:03 pm »

Sí xDDDDDD, apuntes convertidos en funciones/snippets, creo que para lo poco que sé de .NET me lo curro ;D.
En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.809



Ver Perfil
Re: [APORTE] Snippets !! (Posteen aquí sus snippets)
« Respuesta #38 en: 3 Febrero 2013, 05:07 am »

Calcular el hash MD5 de un archivo:

Código
  1.    #Region " Get MD5 Of File Function "
  2.  
  3.       ' [ Get MD5 Of File Function ]
  4.       '
  5.       ' Examples :
  6.       '
  7.       ' MsgBox(Get_MD5_Of_File("C:\Test.txt"))
  8.  
  9.       Private Function Get_MD5_Of_File(ByVal File As String) As String
  10.           Using MD5_Reader As New System.IO.FileStream(File, IO.FileMode.Open, IO.FileAccess.Read)
  11.               Using MD5 As New System.Security.Cryptography.MD5CryptoServiceProvider
  12.                   Dim MD5_Byte() As Byte = MD5.ComputeHash(MD5_Reader)
  13.                   Dim MD5_Hex As New System.Text.StringBuilder(MD5.ComputeHash(MD5_Reader).Length * 2)
  14.                   For Number As Integer = 0 To MD5_Byte.Length - 1 : MD5_Hex.Append(MD5_Byte(Number).ToString("X2")) : Next
  15.                   Return MD5_Hex.ToString().ToLower
  16.               End Using
  17.           End Using
  18.       End Function
  19.  
  20.    #End Region




Calcular el hash MD5 de un string:

Código
  1. #Region " Get MD5 Of String Function "
  2.  
  3.    ' [ Get MD5 Of String Function ]
  4.    '
  5.    ' Examples :
  6.    '
  7.    ' MsgBox(Get_MD5_Of_String("C:\Test.txt"))
  8.  
  9.    Private Function Get_MD5_Of_String(ByVal str As String) As String
  10.        Dim MD5_Hex As String = Nothing
  11.        Dim MD5 As New System.Security.Cryptography.MD5CryptoServiceProvider()
  12.        Dim MD5_Byte = System.Text.Encoding.UTF8.GetBytes(str)
  13.        Dim MD5_Hash = MD5.ComputeHash(MD5_Byte)
  14.        MD5.Clear()
  15.        For Number As Integer = 0 To MD5_Hash.Length - 1 : MD5_Hex &= MD5_Hash(Number).ToString("x").PadLeft(2, "0") : Next
  16.        Return MD5_Hex
  17.    End Function
  18.  
  19. #End Region



Obtener la ID de la placa base:

Código
  1. #Region " Get Motherboard ID Function "
  2.  
  3.    ' [ Get Motherboard ID Function ]
  4.    '
  5.    ' Examples :
  6.    '
  7.    ' Dim Motherboard_ID As String = Get_Motherboard_ID()
  8.    ' MsgBox(Get_Motherboard_ID())
  9.  
  10.    Private Function Get_Motherboard_ID() As String
  11.        For Each Motherboard As Object In GetObject("WinMgmts:").InstancesOf("Win32_BaseBoard") : Return Motherboard.SerialNumber : Next Motherboard
  12.        Return Nothing
  13.    End Function
  14.  
  15. #End Region




Obtener la ID del procesador:

Código
  1. #Region " Get CPU ID Function "
  2.  
  3.    ' [ Get CPU ID Function ]
  4.    '
  5.    ' Examples :
  6.    '
  7.    ' Dim Processor_ID As String = Get_Motherboard_ID()
  8.    ' MsgBox(Get_CPU_ID())
  9.  
  10.    Private Function Get_CPU_ID() As String
  11.        For Each CPU_ID As Object In GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2").ExecQuery("Select * from Win32_Processor") : Return CPU_ID.ProcessorId : Next CPU_ID
  12.        Return Nothing
  13.    End Function
  14.  
  15. #End Region
En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.809



Ver Perfil
Re: [APORTE] Snippets !! (Posteen aquí sus snippets)
« Respuesta #39 en: 5 Febrero 2013, 03:05 am »

Para cambiar los cursores de Windows (En el sistema, fuera del form)

Código
  1. #Region " Set System Cursor Function "
  2.  
  3.    ' [ Set System Cursor Function ]
  4.    '
  5.    ' Examples :
  6.    '
  7.    ' Set_System_Cursor("C:\Cursors\Arrow.ani", System_Cursor.ARROW))
  8.    ' MsgBox(Set_System_Cursor("C:\Cursors\Cross.cur", System_Cursor.CROSS))
  9.  
  10.    ' Set System Cursor [ API declarations ]
  11.    Private Declare Function SetSystemCursor Lib "user32.dll" (ByVal hCursor As IntPtr, ByVal id As Integer) As Boolean
  12.    Private Declare Function LoadCursorFromFile Lib "user32.dll" Alias "LoadCursorFromFileA" (ByVal lpFileName As String) As IntPtr
  13.  
  14.    ' Set System Cursor [ API Constants ]
  15.    Private Enum System_Cursor As UInt32
  16.        APP_STARTING = 32650
  17.        ARROW = 32512
  18.        CROSS = 32515
  19.        HAND = 32649
  20.        HELP = 32651
  21.        I_BEAM = 32513
  22.        NO = 32648
  23.        SIZE_ALL = 32646
  24.        SIZE_NESW = 32643
  25.        SIZE_NS = 32645
  26.        SIZE_NWSE = 32642
  27.        SIZE_WE = 32644
  28.        UP = 32516
  29.        WAIT = 32514
  30.    End Enum
  31.  
  32.    ' Set System Cursor [ Function ]
  33.    Private Function Set_System_Cursor(ByVal Cursor_File As String, ByVal Cursor_Type As System_Cursor) As Boolean
  34.        If SetSystemCursor(LoadCursorFromFile(Cursor_File), Cursor_Type) = 0 Then Return False ' Error loading cursor from file
  35.        Return True
  36.    End Function
  37.  
  38. #End Region




Hotmail sender (Envía correos desde hotmail)

* Es necesario descargar la librería EASENDMAIL (Es gratis aunque se puede comprar licencia): http://www.emailarchitect.net/webapp/download/easendmail.exe  

PD: Sé que esto se puede hacer con la class system.net.mail, pero con esto no dependemos de puertos, y el SSL de los servidores que usemos en la librería se detecta automáticamente...

Código
  1. #Region " Hotmail Sender Function "
  2.  
  3.    ' [ Hotmail Sender Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' * First add a reference to "EASendMail" into the project.
  8.    '
  9.    ' Examples :
  10.    '
  11.    '  MsgBox(Hotmail_Sender("ElektroHacker@hotmail.com", "MyPass", "Anonym@gmail.com", "Test subject", "Test body", {"C:\File1.txt", "C:\File2.txt"}))
  12.  
  13.    Private Function Hotmail_Sender(ByVal Account_User As String, ByVal Account_Password As String, ByVal Mail_To As String, ByVal Mail_Subject As String, ByVal Mail_Body As String, Optional ByVal Mail_Attachments() As String = Nothing) As Boolean
  14.  
  15.        Dim Hot_Mail As New EASendMail.SmtpMail("TryIt")
  16.        Dim Hot_Server As New EASendMail.SmtpServer("smtp.live.com")
  17.        Dim Hot_Smtp As New EASendMail.SmtpClient()
  18.  
  19.        Hot_Server.User = Account_User
  20.        Hot_Server.Password = Account_Password
  21.        Hot_Server.ConnectType = EASendMail.SmtpConnectType.ConnectSSLAuto
  22.  
  23.        Hot_Mail.From = Account_User
  24.        Hot_Mail.To = Mail_To
  25.        Hot_Mail.Subject = Mail_Subject
  26.        Hot_Mail.TextBody = Mail_Body
  27.        If Mail_Attachments IsNot Nothing Then For Each Attachment In Mail_Attachments : Hot_Mail.AddAttachment(Attachment) : Next
  28.  
  29.        Try : Hot_Smtp.SendMail(Hot_Server, Hot_Mail) : Return True
  30.        Catch ex As Exception : Return False : End Try
  31.  
  32.    End Function
  33.  
  34. #End Region
« Última modificación: 5 Febrero 2013, 03:08 am por EleKtro H@cker » En línea

Páginas: 1 2 3 [4] 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ... 59 Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines