Autor
Tema: Librería de Snippets para VB.NET !! (Compartan aquí sus snippets) (Leído 533,728 veces)
Eleкtro
Ex-Staff
Desconectado
Mensajes: 9.885
Devuelve la versión instalada de InternetExplorer en el PC:
#Region " Get IExplorer Version "
' [ Get IExplorer Version Function ]
'
' // By Elektro H@cker
'
' Examples :
'
' MsgBox(Get_IExplorer_Version) ' Result: 8
' MsgBox(Get_IExplorer_Version(True)) ' Result: 8.00.7600.16385
Private Function Get_IExplorer_Version( Optional ByVal Long_Version As Boolean = False ) As String
Try
If Long_Version Then
Return FileVersionInfo.GetVersionInfo ( Environment.GetFolderPath ( Environment.SpecialFolder .System ) & "\ieframe.dll" ) .ProductVersion
Else
Return FileVersionInfo.GetVersionInfo ( Environment.GetFolderPath ( Environment.SpecialFolder .System ) & "\ieframe.dll" ) .ProductVersion .Split ( "." ) .First
End If
Catch ex As Exception
MsgBox ( ex.Message )
Return 0
End Try
End Function
#End Region
En línea
z3nth10n
Desconectado
Mensajes: 1.583
"Jack of all trades, master of none." - Zenthion
Ahora me pongo yo critico, y para que coño quiero saber la versión de mi IE? XD Hombre, se me ocurren ideas tal como parchear algunos errores en los webbrowsers pero, es poca cosa... xD
En línea
⏩
Interesados hablad por Discord.
Eleкtro
Ex-Staff
Desconectado
Mensajes: 9.885
Ahora me pongo yo critico, y para que coño quiero saber la versión de mi IE? XD Hombre, se me ocurren ideas tal como parchear algunos errores en los webbrowsers pero, es poca cosa... xD
La idea es conocer la versión de IExplorer
de otro PC que no sea el tuyo/mio para anticiparse a posibles errores, por ejemplo si te pagan por una aplicación y quieres usar el render de IE10 en un webbrowser pero ese PC tiene IE8 pues...cagada, no?
Un saludo!
En línea
Eleкtro
Ex-Staff
Desconectado
Mensajes: 9.885
Suspender o continuar un proceso externo:
VIDEO (Corregido un pequeño bug de última hora en la función "resume-thread" al comprobar si existia el proceso en el diccionario.)
#Region " Pause-Resume Thread Class "
Public Class Process_Thread
' [ Pause-Resume Thread Functions ]
'
' // By Elektro H@cker
'
' Examples :
'
' Process_Thread.Pause_Thread("ffmpeg.exe") ' Pause ffmpeg.exe (with thread 0)
' Process_Thread.Resume_Thread("ffmpeg.exe") ' Resume ffmpeg.exe (with thread 0)
' Process_Thread.Pause_Thread("cmd.exe", , True) ' Pause all instances of cmd.exe (with thread 0)
' Process_Thread.Resume_Thread("cmd.exe", , True) ' Resume all instances of cmd.exe (with thread 0)
' Process_Thread.Pause_Thread("Process.exe", 2) ' Pause the thread 2 of "Process.exe"
' Process_Thread.Resume_Thread("Process.exe", 2) ' Resume the thread 2 of "Process.exe"
<System.Runtime .InteropServices .DllImport ( "kernel32.dll" ) > _
Private Shared Function OpenThread( ByVal dwDesiredAccess As Integer , ByVal bInheritHandle As Boolean , ByVal dwThreadId As UInt32) As IntPtr
End Function
<System.Runtime .InteropServices .DllImport ( "kernel32.dll" ) > _
Private Shared Function SuspendThread( hThread As IntPtr) As UInteger
End Function
<System.Runtime .InteropServices .DllImport ( "kernel32.dll" ) > _
Private Shared Function ResumeThread( hThread As IntPtr) As UInt32
End Function
<System.Runtime .InteropServices .DllImport ( "kernel32.dll" , SetLastError:= True ) > _
Private Shared Function CloseHandle( ByVal hObject As IntPtr) As <System.Runtime .InteropServices .MarshalAs ( System.Runtime .InteropServices .UnmanagedType .Bool ) > Boolean
End Function
''' <summary>
''' Dictionary to store the current paused threads.
''' </summary>
Public Shared Thread_Handle_Dictionary
As New Dictionary ( Of String , IntPtr
)
#Region " Pause Thread "
''' <summary>
''' Function to pause a thread.
''' </summary>
'''
''' <param name="Process_Name">The name of the process, ex: cmd.exe</param>
''' <param name="Thread_Number">The thread to pause, ex: 0</param>
''' <param name="Recursive"> <value name="True">Pause the thread in all processes found recursively.</value></param>
''' <returns>True if the process is found; otherwise, False.</returns>
Public Shared Function Pause_Thread( ByRef Process_Name As String , _
Optional ByVal Thread_Number As Int32 = 0 , _
Optional ByVal Recursive As Boolean = False ) As Boolean
If Process_Name.ToLower .EndsWith ( ".exe" ) Then _
Process_Name = Process_Name.Substring ( 0 , Process_Name.Length - 4 )
Dim proc( ) As Process = Process.GetProcessesByName ( Process_Name)
If Not proc.Length = 0 Then
If Recursive Then
For proc_num As Integer = 0 To proc.Length - 1
Try
Thread_Handle_Dictionary.Add ( Process_Name.ToLower & Thread_Number.ToString & ";" & proc( proc_num) .Handle .ToString , _
OpenThread( & H2, True , proc( proc_num) .Threads ( Thread_Number) .Id ) )
SuspendThread( Thread_Handle_Dictionary.Item ( Process_Name.ToLower & Thread_Number.ToString & ";" & proc( proc_num) .Handle .ToString ) )
Application.DoEvents ( )
Catch ex As Exception
MsgBox ( ex.Message ) ' The handle already exist in the Dictionary.
Return False
End Try
Next
Else
Try
Thread_Handle_Dictionary.Add ( Process_Name.ToLower & Thread_Number.ToString & ";" & proc( 0 ) .Handle .ToString , _
OpenThread( & H2, True , proc( 0 ) .Threads ( Thread_Number) .Id ) )
SuspendThread( Thread_Handle_Dictionary.Item ( Process_Name.ToLower & Thread_Number.ToString & ";" & proc( 0 ) .Handle .ToString ) )
Catch ex As Exception
MsgBox ( ex.Message ) ' The handle already exist in the Dictionary.
Return False
End Try
End If
Else ' proc.Length = 0
Throw New Exception( "Process " "" & Process_Name & "" " not found." )
Return False
End If
Return True
End Function
#End Region
#Region " Resume Thread "
''' <summary>
''' Function to resume a thread.
''' </summary>
'''
''' <param name="Process_Name">The name of the process, ex: cmd.exe</param>
''' <param name="Thread_Number">The thread to resume, ex: 0</param>
''' <param name="Recursive"> <value name="True">Resume the thread in all processes found recursively.</value></param>
''' <returns>True if the process is found; otherwise, False.</returns>
Public Shared Function Resume_Thread( ByRef Process_Name As String , _
Optional ByVal Thread_Number As Int32 = 0 , _
Optional ByVal Recursive As Boolean = False ) As Boolean
If Process_Name.ToLower .EndsWith ( ".exe" ) Then _
Process_Name = Process_Name.Substring ( 0 , Process_Name.Length - 4 )
Dim Process_Exist As Boolean = False ' To check if process exist in the dictionary.
Dim Temp_Dictionary
As New Dictionary ( Of String , IntPtr
) ' Replic of the "Thread_Handle_Dictionary" dictionary.
For Each Process In Thread_Handle_Dictionary
If Process.Key .StartsWith ( Process_Name.ToLower & Thread_Number.ToString ) Then Process_Exist = True
Temp_Dictionary.Add ( Process.Key , Process.Value )
Next
If Process_Exist Then
If Recursive Then
For Each Process In Temp_Dictionary
If Process.Key .ToLower .Contains ( Process_Name.ToLower & Thread_Number.ToString ) Then
ResumeThread( Process.Value )
CloseHandle( Process.Value )
Thread_Handle_Dictionary.Remove ( Process.Key )
End If
Application.DoEvents ( )
Next
Else
For Each Process In Temp_Dictionary
If Process.Key .ToLower .Contains ( Process_Name.ToLower & Thread_Number.ToString ) Then
ResumeThread( Process.Value )
CloseHandle( Process.Value )
Thread_Handle_Dictionary.Remove ( Process.Key )
Exit For
End If
Application.DoEvents ( )
Next
End If
Return True
Else
Throw New Exception( "Process " "" & Process_Name & "" " with thread number " "" & Thread_Number & "" " not found." )
Return False
End If
End Function
#End Region
End Class
#End Region
« Última modificación: 8 Junio 2013, 08:08 am por EleKtro H@cker »
En línea
Eleкtro
Ex-Staff
Desconectado
Mensajes: 9.885
Resalta en colores la sintaxis de un script.
(Lo convierte a código HTML)
http://colorcode.codeplex.com/releases/view/103657 #Region " [ColorCode] Color Code "
' [ColorCode] Color Code
'
' // By Elektro H@cker
'
' Instructions:
' 1. Add a reference to ColorCode.dll
'
' Examples:
' HtmlTextBox1.Text = Color_Code(IO.File.ReadAllText("c:\Code.vb"), ColorCode.Languages.VbDotNet)
' HtmlTextbox1.Text = Color_Code(IO.File.ReadAllText("c:\Code.cs"), ColorCode.Languages.CSharp)
Private Function Color_Code( ByVal Code As String , ByVal Language As ColorCode.ILanguage ) As String
Return New ColorCode.CodeColorizer ( ) .Colorize ( Code, Language)
End Function
#End Region
Randomizar el contenido de un Array de tipo String:
#Region " Randomize String Array "
' [ Randomize String Array Function ]
'
' Examples :
' Dim MyArray As Array = Randomize_String_Array({"a", "b", "c", "d", "e"}) ' Result: {"d", "a", "c", "e", "b"}
Dim Array_randomizer As New Random
Private Function Randomize_String_Array( ByVal array ( ) As String ) As Array
Return array .OrderBy ( Function ( ) Array_randomizer.Next ) .ToArray
End Function
#End Region
Randomizar el contenido de cualquier tipo de Array:
#Region " Randomize Array "
' [ Randomize Array ]
'
' Examples :
' Dim strarray() As String = {"a", "b", "3"}
' Dim IntArray As Array = {1, 2, 3}
' Randomize_Array(strarray)
' Randomize_Array(IntArray)
Dim Array_Randomizer As New Random
Public Sub Randomize_Array( ByVal array As Array )
For i As Int64 = array .Length To 1 Step - 1
Dim j As Int64 = Array_Randomizer.Next ( i)
Dim tmp As Object = array ( j)
array ( j) = array ( i - 1 )
array ( i - 1 ) = tmp
Next
End Sub
#End Region
Une el contenido de un Array de cualquier tipo
(hace unos días posteé un código parecido, pero solo funcionaba para arrays de string)
#Region " Join Array "
' [ Join Array Function ]
'
' Examples :
'
' Dim StrArray() As String = {"a", "b", "c"} ' String array
' Dim IntArray As Array = {1, 2, 3} ' Integer array
' MsgBox(Join_Array(StrArray, " ")) ' Result: a b c
' MsgBox(Join_Array(IntArray, " ")) ' Result: 1 2 3
Private Function Join_Array( ByVal array As Array , ByVal Separator As String )
Return String .Join ( Separator, array .Cast ( Of Object ) .Select ( Function ( x) x.ToString ) )
End Function
#End Region
cifrar-descifrar un string de manera selectiva (usando los caracteres que nos de la gana, por eso el código es así de largo)
#Region " Encrypt-Decrypt String Selective "
' [ Encrypt-Decrypt String Selective Function ]
'
' // By Elektro H@cker
'
' Examples :
'
' MsgBox(Encrypt_Text("Hello world")) ' Result: à`336 L6ë3m
' MsgBox(Decrypt_Text("à`336 L6ë3m")) ' Result: Hello world
' MsgBox(Encrypt_Text("¡ Hello world !", True)) ' Result: = <ÁÍÍÀ cÀ,Í3 Ï
' MsgBox(Decrypt_Text("= <ÁÍÍÀ cÀ,Í3 Ï", True)) ' Result: ¡ Hello world !
Public Shared Function Encrypt_Text( ByVal str As String , _
Optional ByVal Include_Special_Characters As Boolean = False ) As String
Dim Temp_String As String = String .Empty
Dim Replacement_Found As Boolean = False
Static Characters As Char( )
Static Replacements As Char( )
If Include_Special_Characters Then
Characters = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ0123456789áéíóúÁÉÍÓÚàèìòùÀÈÌÒÙäëïöüÄËÏÖÜçǺª<>¡!¿?()[]{}/\|·.:;,-+=_~¬^'`´¨*$%&€#@" "" .ToCharArray
Replacements = { "h" , "ó" , "Ó" , "3" , "Á" , "è" , "A" , "^" , "ö" , "~" , "O" , "Í" , "€" , "q" , "ú" , "À" , "Ç" , "È" , "," , "ì" , "i" , "ï" , "ò" , "c" , "0" , "ñ" , "4" , "l" , "Ü" , "ª" , "¬" , "S" , "&" , "?" , "<" , ":" , "T" , "*" , "e" , "." , "R" , "É" , "D" , "7" , "9" , "Ú" , "n" , "¿" , "L" , "m" , "¨" , "Ë" , "]" , "Ä" , "Q" , "w" , "V" , "'" , "G" , "K" , "é" , "v" , "ù" , "}" , "P" , "E" , "X" , "+" , "í" , "´" , "$" , "{" , "_" , "Ñ" , "u" , "ë" , "H" , "g" , "d" , "x" , "8" , "/" , "ä" , "#" , "|" , "-" , "1" , "M" , "Ò" , "o" , ")" , "N" , "Y" , "á" , "Ù" , "Ì" , "%" , "ç" , "" "" , "a" , "=" , "Ï" , "z" , "Ö" , ">" , ";" , "2" , "6" , "B" , "y" , "b" , "`" , "s" , "5" , "t" , "[" , "(" , "à" , "ü" , "!" , "¡" , "f" , "W" , "k" , "r" , "U" , "J" , "·" , "Z" , "F" , "C" , "º" , "I" , "@" , "p" , "j" }
Else
Characters = _
"abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ0123456789áéíóúÁÉÍÓÚàèìòùÀÈÌÒÙäëïöüÄËÏÖÜçǺª¡¿·¬`´¨€" .ToCharArray
' Removed chars for better improvement in code encryptation: = & + - ^ " % ' < > ( ) { } . $ [ ] ; @ ! ? ~ : / \ | * # , _
Replacements = _
{ "u" , "Ñ" , "T" , "m" , "`" , "P" , "Ç" , "Z" , "h" , "x" , "á" , "3" , "¬" , "R" , "ª" , "6" , "ò" , "N" , "ë" , "Ì" , "g" , "ö" , "I" , "L" , "a" , "À" , "·" , "V" , "5" , "Ë" , "Ù" , "´" , "Ö" , "J" , "à" , "¡" , "n" , "4" , "È" , "j" , "ç" , "b" , "c" , "y" , "E" , "ù" , "Ó" , "f" , "º" , "Q" , "q" , "G" , "e" , "B" , "0" , "€" , "9" , "o" , "ì" , "O" , "8" , "¿" , "r" , "v" , "ó" , "2" , "Ï" , "1" , "¨" , "i" , "Á" , "D" , "t" , "Í" , "k" , "Ú" , "C" , "ñ" , "Ä" , "S" , "A" , "é" , "7" , "Ü" , "K" , "z" , "í" , "è" , "Y" , "ü" , "F" , "s" , "p" , "X" , "U" , "Ò" , "l" , "É" , "ú" , "d" , "ï" , "M" , "W" , "H" , "ä" , "w" }
' a, b, c, d, e, f, g, h, i, j, k, l, m, n, ñ, o, p, q, r, s, t, u, v, w, x, y, z, A, B, C, D, E, F, G, H, I, J, K, L, M, N, Ñ, O, P, Q, R, S, T, U, V, W, X, Y, Z, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, á, é, í, ó, ú, Á, É, Í, Ó, Ú, à, è, ì, ò, ù, À, È, Ì, Ò, Ù, ä, ë, ï, ö, ü, Ä, Ë, Ï, Ö, Ü, ç, Ç, º, ª, ¡, ¿, ·, ¬, `, ´, ¨, €
End If
For Each character As Char In str
For x As Int32 = 0 To Characters.Length - 1
If character = Characters( x) Then
Replacement_Found = True
Temp_String &= Replacements( x)
Exit For
End If
Next
If Not Replacement_Found Then Temp_String &= character Else Replacement_Found = False
Application.DoEvents ( )
Next
Return Temp_String
End Function
Public Shared Function Decrypt_Text( ByVal str As String , _
Optional ByVal Include_Special_Characters As Boolean = False ) As String
Dim Temp_String As String = String .Empty
Dim Replacement_Found As Boolean = False
Static Characters As Char( )
Static Replacements As Char( )
If Include_Special_Characters Then
Characters = { "h" , "ó" , "Ó" , "3" , "Á" , "è" , "A" , "^" , "ö" , "~" , "O" , "Í" , "€" , "q" , "ú" , "À" , "Ç" , "È" , "," , "ì" , "i" , "ï" , "ò" , "c" , "0" , "ñ" , "4" , "l" , "Ü" , "ª" , "¬" , "S" , "&" , "?" , "<" , ":" , "T" , "*" , "e" , "." , "R" , "É" , "D" , "7" , "9" , "Ú" , "n" , "¿" , "L" , "m" , "¨" , "Ë" , "]" , "Ä" , "Q" , "w" , "V" , "'" , "G" , "K" , "é" , "v" , "ù" , "}" , "P" , "E" , "X" , "+" , "í" , "´" , "$" , "{" , "_" , "Ñ" , "u" , "ë" , "H" , "g" , "d" , "x" , "8" , "/" , "ä" , "#" , "|" , "-" , "1" , "M" , "Ò" , "o" , ")" , "N" , "Y" , "á" , "Ù" , "Ì" , "%" , "ç" , "" "" , "a" , "=" , "Ï" , "z" , "Ö" , ">" , ";" , "2" , "6" , "B" , "y" , "b" , "`" , "s" , "5" , "t" , "[" , "(" , "à" , "ü" , "!" , "¡" , "f" , "W" , "k" , "r" , "U" , "J" , "·" , "Z" , "F" , "C" , "º" , "I" , "@" , "p" , "j" }
Replacements = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ0123456789áéíóúÁÉÍÓÚàèìòùÀÈÌÒÙäëïöüÄËÏÖÜçǺª<>¡!¿?()[]{}/\|·.:;,-+=_~¬^'`´¨*$%&€#@" "" .ToCharArray
Else
Characters = _
{ "u" , "Ñ" , "T" , "m" , "`" , "P" , "Ç" , "Z" , "h" , "x" , "á" , "3" , "¬" , "R" , "ª" , "6" , "ò" , "N" , "ë" , "Ì" , "g" , "ö" , "I" , "L" , "a" , "À" , "·" , "V" , "5" , "Ë" , "Ù" , "´" , "Ö" , "J" , "à" , "¡" , "n" , "4" , "È" , "j" , "ç" , "b" , "c" , "y" , "E" , "ù" , "Ó" , "f" , "º" , "Q" , "q" , "G" , "e" , "B" , "0" , "€" , "9" , "o" , "ì" , "O" , "8" , "¿" , "r" , "v" , "ó" , "2" , "Ï" , "1" , "¨" , "i" , "Á" , "D" , "t" , "Í" , "k" , "Ú" , "C" , "ñ" , "Ä" , "S" , "A" , "é" , "7" , "Ü" , "K" , "z" , "í" , "è" , "Y" , "ü" , "F" , "s" , "p" , "X" , "U" , "Ò" , "l" , "É" , "ú" , "d" , "ï" , "M" , "W" , "H" , "ä" , "w" }
' a, b, c, d, e, f, g, h, i, j, k, l, m, n, ñ, o, p, q, r, s, t, u, v, w, x, y, z, A, B, C, D, E, F, G, H, I, J, K, L, M, N, Ñ, O, P, Q, R, S, T, U, V, W, X, Y, Z, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, á, é, í, ó, ú, Á, É, Í, Ó, Ú, à, è, ì, ò, ù, À, È, Ì, Ò, Ù, ä, ë, ï, ö, ü, Ä, Ë, Ï, Ö, Ü, ç, Ç, º, ª, ¡, ¿, ·, ¬, `, ´, ¨, €
Replacements = _
"abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ0123456789áéíóúÁÉÍÓÚàèìòùÀÈÌÒÙäëïöüÄËÏÖÜçǺª¡¿·¬`´¨€" .ToCharArray
' Removed chars for better improvement in code encryptation: = & + - ^ " % ' < > ( ) { } . $ [ ] ; @ ! ? ~ : / \ | * # , _
End If
For Each character As Char In str
For x As Int32 = 0 To Characters.Length - 1
If character = Characters( x) Then
Replacement_Found = True
Temp_String &= Replacements( x)
Exit For
End If
Next
If Not Replacement_Found Then Temp_String &= character Else Replacement_Found = False
Application.DoEvents ( )
Next
Return Temp_String
End Function
#End Region
« Última modificación: 9 Junio 2013, 19:01 pm por EleKtro H@cker »
En línea
Eleкtro
Ex-Staff
Desconectado
Mensajes: 9.885
Otro código de ORO:
Devuelve de la manera más eficaz y sencilla una lista de tipo FileInfo con todos los archivos de un directorio,
Le hice dos overloads para poder usar la función de varias maneras y evitar posibles errores en el "SearchPattern",
La función es "IgnoreCase", devuelve la extensión en uppercase y lowercase y todas las variantes posibles, en fin, esto es la perfección:
#Region " Get Files "
' [ Get Files Function ]
'
' // By Elektro H@cker
'
' Examples :
'
' For Each file In Get_Files("C:\Windows", False) : MsgBox(file.Name) : Next
'
' For Each file In Get_Files("C:\Windows", True, "dll") : MsgBox(file.Name) : Next
' For Each file In Get_Files("C:\Windows", True, ".dll") : MsgBox(file.Name) : Next
' For Each file In Get_Files("C:\Windows", True, "*.dll") : MsgBox(file.Name) : Next
'
' For Each file In Get_Files("C:\Windows", False, {"dll", "ini"}) : MsgBox(file.Name) : Next
' For Each file In Get_Files("C:\Windows", False, {".dll", ".ini"}) : MsgBox(file.Name) : Next
' For Each file In Get_Files("C:\Windows", False, {"*.dll", "*.ini"}) : MsgBox(file.Name) : Next
' Get Files {directory} {recursive}
Private Function Get_Files( ByVal directory As String , ByVal recursive As Boolean ) As List( Of IO.FileInfo )
Dim searchOpt As IO.SearchOption = If ( recursive, IO.SearchOption .AllDirectories , IO.SearchOption .TopDirectoryOnly )
Return IO.Directory .GetFiles ( directory , "*" , searchOpt) .Select ( Function ( p) New IO.FileInfo ( p) ) .ToList
End Function
' Get Files {directory} {recursive} {ext}
Private Function Get_Files( ByVal directory As String , ByVal recursive As Boolean , ext As String ) As List( Of IO.FileInfo )
If ext.StartsWith ( "*" ) Then
ext = ext.Substring ( 1 , ext.Length - 1 )
ElseIf Not ext = "*" AndAlso Not ext.StartsWith ( "." ) Then
ext = ( "." & ext)
ElseIf ext = "*" Then
ext = Nothing
End If
Dim searchOpt As IO.SearchOption = If ( recursive, IO.SearchOption .AllDirectories , IO.SearchOption .TopDirectoryOnly )
Return IO.Directory .GetFiles ( directory , "*" & ext, searchOpt) .Select ( Function ( p) New IO.FileInfo ( p) ) .ToList
End Function
' Get Files {directory} {recursive} {exts()}
Private Function Get_Files( ByVal directory As String , ByVal recursive As Boolean , ParamArray exts( ) As String ) As List( Of IO.FileInfo )
Dim FileExts( exts.Count ) As String
Dim ExtCount As Int32 = 0
For Each ext In exts
If ext.StartsWith ( "*" ) Then
FileExts( ExtCount) = ext.Substring ( 1 , ext.Length - 1 )
ElseIf Not ext = "*" AndAlso Not ext.StartsWith ( "." ) Then
FileExts( ExtCount) = ( "." & ext)
ElseIf Not ext = "*" AndAlso ext.StartsWith ( "." ) Then
FileExts( ExtCount) = ext
ElseIf ext = "*" Then
FileExts( ExtCount) = Nothing
End If
ExtCount += 1
Next
Dim searchOpt As IO.SearchOption = If ( recursive, IO.SearchOption .AllDirectories , IO.SearchOption .TopDirectoryOnly )
Dim filenameExtComparer As New FilenameExtensionComparer
Return IO.Directory .GetFiles ( directory , "*" , searchOpt) .Where ( Function ( o) FileExts.Contains ( IO.Path .GetExtension ( o) , filenameExtComparer) ) .Select ( Function ( p) New IO.FileInfo ( p) ) .ToList
End Function
' FilenameExtensionComparer
Public Class FilenameExtensionComparer : Implements IEqualityComparer( Of String )
Public Function Equals1( s As String , t As String ) As Boolean Implements IEqualityComparer( Of String ) .Equals
Return String .Compare ( s, t, StringComparison.OrdinalIgnoreCase ) = 0
End Function
Public Function GetHashCode1( s As String ) As Integer Implements IEqualityComparer( Of String ) .GetHashCode
Return s.GetHashCode ( )
End Function
End Class
#End Region
« Última modificación: 11 Junio 2013, 11:59 am por EleKtro H@cker »
En línea
Eleкtro
Ex-Staff
Desconectado
Mensajes: 9.885
Cargar o guardar valores fácilmente en un archivo INI:
#Region " INI Manager "
' [ INI Manager Functions ]
'
' // By Elektro H@cker
'
' Examples :
'
' INI_Manager.Set_Value(".\Test.ini", "TextValue", TextBox1.Text) ' Save
' TextBox1.Text = INI_Manager.Load_Value(".\Test.ini", "TextValue") ' Load
' INI_Manager.Delete_Value(".\Test.ini", "TextValue") ' Delete
' INI_Manager.Sort_Values(".\Test.ini") ' Sort INI File
Public Class INI_Manager
''' <summary>
''' The INI File Location.
''' </summary>
Public Shared INI_File As String = IO.Path .Combine ( Application.StartupPath , Process.GetCurrentProcess ( ) .ProcessName & ".ini" )
''' <summary>
''' Set a value.
''' </summary>
''' <param name="File">The INI file location</param>
''' <param name="ValueName">The value name</param>
''' <param name="Value">The value data</param>
Public Shared Sub Set_Value
( ByVal File As String ,
ByVal ValueName
As String ,
ByVal Value
As String )
Try
If Not IO.
File .
Exists ( File ) Then ' Create a new INI File with "Key=Value""
My.
Computer .
FileSystem .
WriteAllText ( File , ValueName
& "=" & Value,
False ) Exit Sub
Else ' Search line by line in the INI file for the "Key"
Dim Line_Number As Int64 = 0
Dim strArray
( ) As String = IO.
File .
ReadAllLines ( File )
For Each line In strArray
If line .ToLower .StartsWith ( ValueName.ToLower & "=" ) Then
strArray( Line_Number) = ValueName & "=" & Value
IO.
File .
WriteAllLines ( File , strArray
) ' Replace "value" Exit Sub
End If
Line_Number += 1
Next
Application.DoEvents ( )
My.
Computer .
FileSystem .
WriteAllText ( File , vbNewLine
& ValueName
& "=" & Value,
True ) ' Key don't exist, then create the new "Key=Value"
End If
Catch ex As Exception
MsgBox ( ex.Message )
End Try
End Sub
''' <summary>
''' Load a value.
''' </summary>
''' <param name="File">The INI file location</param>
''' <param name="ValueName">The value name</param>
''' <returns>The value itself</returns>
Public Shared Function Load_Value
( ByVal File As String ,
ByVal ValueName
As String ) As Object
Throw New Exception
( File & " not found." ) ' INI File not found. Return Nothing
Else
For Each line In IO.
File .
ReadAllLines ( File ) If line .ToLower .StartsWith ( ValueName.ToLower & "=" ) Then Return line .Split ( "=" ) .Last
Next
Application.DoEvents ( )
Throw New Exception( "Key: " & "" "" & ValueName & "" "" & " not found." ) ' Key not found.
Return Nothing
End If
End Function
''' <summary>
''' Delete a key.
''' </summary>
''' <param name="File">The INI file location</param>
''' <param name="ValueName">The value name</param>
Public Shared Sub Delete_Value
( ByVal File As String ,
ByVal ValueName
As String )
Throw New Exception
( File & " not found." ) ' INI File not found. Exit Sub
Else
Try
Dim Line_Number As Int64 = 0
Dim strArray
( ) As String = IO.
File .
ReadAllLines ( File )
For Each line In strArray
If line .ToLower .StartsWith ( ValueName.ToLower & "=" ) Then
strArray( Line_Number) = Nothing
Exit For
End If
Line_Number += 1
Next
Array .Copy ( strArray, Line_Number + 1 , strArray, Line_Number, UBound ( strArray) - Line_Number)
ReDim Preserve strArray( UBound ( strArray) - 1 )
My.
Computer .
FileSystem .
WriteAllText ( File ,
String .
Join ( vbNewLine, strArray
) ,
False )
Catch ex As Exception
MsgBox ( ex.Message )
End Try
End If
End Sub
''' <summary>
''' Sorts the entire INI File.
''' </summary>
''' <param name="File">The INI file location</param>
Public Shared Sub Sort_Values
( ByVal File As String )
Throw New Exception
( File & " not found." ) ' INI File not found. Exit Sub
Else
Try
Dim Line_Number As Int64 = 0
Dim strArray
( ) As String = IO.
File .
ReadAllLines ( File ) Dim TempList As New List( Of String )
For Each line As String In strArray
If line <> "" Then TempList.Add ( strArray( Line_Number) )
Line_Number += 1
Next
TempList.Sort ( )
Catch ex As Exception
MsgBox ( ex.Message )
End Try
End If
End Sub
End Class
#End Region
« Última modificación: 11 Junio 2013, 20:02 pm por EleKtro H@cker »
En línea
z3nth10n
Desconectado
Mensajes: 1.583
"Jack of all trades, master of none." - Zenthion
Entonces este IniReader usa Secciones? Si no explicame, como hago para llamar a 2 pcbs desde el mismo .INI
En línea
⏩
Interesados hablad por Discord.
Eleкtro
Ex-Staff
Desconectado
Mensajes: 9.885
Entonces este IniReader usa Secciones?
No, no lee secciones ni tampoco guarda secciones, no me gustan las secciones ni tampoco las considero útiles, menos para aplicaciones grandes como CCleaner.
explicame, como hago para llamar a 2 pcbs desde el mismo .INI
Pues primero guardas el valor de cada PictureBox en el ini, y luego obtienes los valores préviamente guardados y los asignas a... a lo que estés intentando asignarlo.
Lee los comentarios al principio de la Class, ahí hay ejemplos, no sé que puede resultar tán dificil (de verdad), crea un post porque si con esos ejemplos no te aclara entonces ya no se que más decir.
Saludos!
« Última modificación: 11 Junio 2013, 21:57 pm por EleKtro H@cker »
En línea
z3nth10n
Desconectado
Mensajes: 1.583
"Jack of all trades, master of none." - Zenthion
Nada ya se como quedaría, a veces parezco tonto.
« Última modificación: 11 Junio 2013, 22:26 pm por Ikillnukes »
En línea
⏩
Interesados hablad por Discord.
Mensajes similares
Asunto
Iniciado por
Respuestas
Vistas
Último mensaje
Librería de Snippets en C/C++
« 1 2 3 4 »
Programación C/C++
z3nth10n
31
26,095
2 Agosto 2013, 17:13 pm
por 0xDani
[APORTE] [VBS] Snippets para manipular reglas de bloqueo del firewall de Windows
Scripting
Eleкtro
1
4,116
3 Febrero 2014, 20:19 pm
por Eleкtro
Librería de Snippets para Delphi
« 1 2 »
Programación General
crack81
15
21,359
25 Marzo 2016, 18:39 pm
por crack81
Una organización en Github para subir, proyectos, snippets y otros?
Sugerencias y dudas sobre el Foro
z3nth10n
0
3,106
21 Febrero 2017, 10:47 am
por z3nth10n
índice de la Librería de Snippets para VB.NET !!
.NET (C#, VB.NET, ASP)
Eleкtro
7
6,594
4 Julio 2018, 21:35 pm
por Eleкtro