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

 

 


Tema destacado: Guía actualizada para evitar que un ransomware ataque tu empresa


+  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 4 Visitantes 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 20 21 22 23 24 25 26 27 ... 60 Ir Abajo Respuesta Imprimir
Autor Tema: Librería de Snippets para VB.NET !! (Compartan aquí sus snippets)  (Leído 526,947 veces)
Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.866



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #110 en: 8 Mayo 2013, 11:14 am »

Una class con funciones para realizar todo tipo de operaciones en el Registro de Windows:

- Crear clave
- Eliminar clave
- Crear valor
- Eliminar valor
- Obtener los datos de un valor
- Exportar clave
- Importar archivo
- Saltar a clave (abrir Regedit en clave específica)
- Comprobar si un valor existe
- Comprobar si los datos de un valor están vacíos
- Copiar clave a otro lugar del registro
- Copiar valor a otro lugar del registro
- Establecer permisos de usuario para una clave

Código
  1. #Region " RegEdit "
  2.  
  3. ' [ RegEdit Functions ]
  4. '
  5. ' // By Elektro H@cker
  6. '
  7. ' Examples :
  8. '
  9. ' -----------
  10. ' Create Key:
  11. ' -----------
  12. ' RegEdit.Create_Key("HKCU\Software\MyProgram")                        ' Creates "HKCU\Software\MyProgram"
  13. ' RegEdit.Create_Key("HKEY_CURRENT_USER\Software\MyProgram\Settings\") ' Creates "HKCU\Software\MyProgram\Settings"
  14. '
  15. ' -----------
  16. ' Delete Key:
  17. ' -----------
  18. ' RegEdit.Delete_Key("HKLM\Software\7-zip")                ' Deletes the "7-zip" tree including subkeys
  19. ' RegEdit.Delete_Key("HKEY_LOCAL_MACHINE\Software\7-zip\") ' Deletes the "7-zip" tree including subkeys
  20. '
  21. ' -------------
  22. ' Delete Value:
  23. ' -------------
  24. ' RegEdit.Delete_Value("HKCU\Software\7-Zip", "Lang")               ' Deletes "Lang" Value
  25. ' RegEdit.Delete_Value("HKEY_CURRENT_USER\Software\7-Zip\", "Lang") ' Deletes "Lang" Value
  26. '
  27. ' ----------
  28. ' Get Value:
  29. ' ----------
  30. ' Dim Data As String = RegEdit.Get_Value("HKCU\Software\MyProgram", "Value name"))
  31. ' Dim Data As String = RegEdit.Get_Value("HKEY_CURRENT_USER\Software\MyProgram", "Value name"))
  32. '
  33. ' ----------
  34. ' Set Value:
  35. ' ----------
  36. ' RegEdit.Set_Value("HKCU\Software\MyProgram", "Value name", "Data", Microsoft.Win32.RegistryValueKind.String)               ' Create/Replace "Value Name" with "Data" as string data
  37. ' RegEdit.Set_Value("HKEY_CURRENT_USER\Software\MyProgram\", "Value name", "Data", Microsoft.Win32.RegistryValueKind.String) ' Create/Replace "Value Name" with "Data" as string data
  38. '
  39. ' -----------
  40. ' Export Key:
  41. ' -----------
  42. ' RegEdit.Export_Key("HKLM", "C:\HKLM.reg")                  ' Export entire "HKEY_LOCAL_MACHINE" Tree to "C:\HKLM.reg" file.
  43. ' RegEdit.Export_Key("HKLM\Software\7-zip\", "C:\7-zip.reg") ' Export entire "7-zip" Tree to "C:\7-zip.reg" file.
  44. '
  45. ' ------------
  46. ' Import File:
  47. ' ------------
  48. ' RegEdit.Import_RegFile("C:\Registry_File.reg") ' Install a registry file.
  49. '
  50. ' ------------
  51. ' Jump To Key:
  52. ' ------------
  53. ' RegEdit.Jump_To_Key("HKLM")                               ' Opens Regedit at "HKEY_LOCAL_MACHINE" Root.
  54. ' RegEdit.Jump_To_Key("HKEY_LOCAL_MACHINE\Software\7-zip\") ' Opens Regedit at "HKEY_LOCAL_MACHINE\Software\7-zip" tree.
  55. '
  56. ' -------------
  57. ' Exist Value?:
  58. ' -------------
  59. ' MsgBox(RegEdit.Exist_Value("HKLM\software\7-zip", "Path") ' Checks if "Path" value exist.
  60. '
  61. ' ------------
  62. ' Exist Data?:
  63. ' ------------
  64. ' MsgBox(RegEdit.Exist_Data("HKLM\software\7-zip", "Path") ' Checks if "Path" value have empty data.
  65. '
  66. ' ---------
  67. ' Copy Key:
  68. ' ---------
  69. ' RegEdit.Copy_Key("HKCU", "Software", "7-Zip", "HKLM", "Software", "7-zip")          ' Copies "HKCU\Software\7-Zip" to "HKLM\Software\7-Zip"
  70. ' RegEdit.Copy_Key("HKCU", "Software", "7-Zip", Nothing, "Software", "7-zip")         ' Copies "HKCU\Software\7-Zip" to "HKCU\Software\7-Zip"
  71. ' RegEdit.Copy_Key("HKCU", "Software", "7-Zip", "HKLM", "Software", Nothing)          ' Copies "HKCU\Software\7-Zip" to "HKLM\Software\"
  72. ' RegEdit.Copy_Key("HKCU", "Software", "7-Zip", "HKLM", Nothing, Nothing)             ' Copies "HKCU\Software\7-Zip" to "HKLM\"
  73. ' RegEdit.Copy_Key("HKCU", "\Software\", "\7-Zip\", "HKLM", "\Software\", "\7-zip\")  ' Copies "HKCU\Software\7-Zip" to "HKLM\Software\7-Zip"
  74. '
  75. ' -----------
  76. ' Copy Value:
  77. ' -----------
  78. ' RegEdit.Copy_Value("HKLM\software\7-zip", "path", "HKLM\software\7-zip", "path_backup") ' Copies "Path" value with their data to "HKLM\software\7-zip" "path_backup".
  79. '
  80. ' -----------
  81. ' Set_UserAccess_Key:
  82. ' -----------
  83. ' RegEdit.Set_UserAccess_Key("HKCU\Software\7-Zip", {RegEdit.RegUserAccess.Administrators_Full_Access})
  84. ' RegEdit.Set_UserAccess_Key("HKEY_CURRENT_USER\Software\7-Zip", {RegEdit.RegUserAccess.Administrators_Full_Access, RegEdit.RegUserAccess.Creator_Full_Access, RegEdit.RegUserAccess.System_Full_Access})
  85.  
  86. #Region " RegEdit Class "
  87.  
  88. Public Class RegEdit
  89.  
  90.    ''' <summary>
  91.    ''' Create a new registry key.
  92.    ''' </summary>
  93.    Public Shared Function Create_Key(ByVal RegKey As String) As Boolean
  94.  
  95.        Dim RootKey As Microsoft.Win32.RegistryKey = Get_Root_Key(RegKey)
  96.        Dim KeyPath As String = Get_Key_Path(RegKey)
  97.  
  98.        Try
  99.            RootKey.CreateSubKey(KeyPath)
  100.            RootKey.Close()
  101.            RootKey.Dispose()
  102.            Return True
  103.        Catch ex As Exception
  104.            ' MsgBox(ex.Message)
  105.            ' Throw New Exception(ex.Message)
  106.            Return False
  107.        End Try
  108.  
  109.    End Function
  110.  
  111.    ''' <summary>
  112.    ''' Delete a registry key.
  113.    ''' </summary>
  114.    Public Shared Function Delete_Key(ByVal RegKey As String) As Boolean
  115.  
  116.        Dim RootKey As Microsoft.Win32.RegistryKey = Get_Root_Key(RegKey)
  117.        Dim KeyPath As String = Get_Key_Path(RegKey)
  118.  
  119.        Try
  120.            RootKey.DeleteSubKeyTree(KeyPath)
  121.            RootKey.Close()
  122.            RootKey.Dispose()
  123.            Return True
  124.        Catch ex As Exception
  125.            ' MsgBox(ex.Message)
  126.            ' Throw New Exception(ex.Message)
  127.            Return False
  128.        End Try
  129.  
  130.    End Function
  131.  
  132.    ''' <summary>
  133.    ''' Delete a registry key.
  134.    ''' </summary>
  135.    Public Shared Function Delete_Value(ByVal RegKey As String, ByVal RegValue As String) As Boolean
  136.  
  137.        Dim RootKey As Microsoft.Win32.RegistryKey = Get_Root_Key(RegKey)
  138.        Dim KeyPath As String = Get_Key_Path(RegKey)
  139.  
  140.        Try
  141.            RootKey.OpenSubKey(KeyPath, True).DeleteValue(RegValue)
  142.            RootKey.Close()
  143.            RootKey.Dispose()
  144.            Return True
  145.        Catch ex As Exception
  146.            ' MsgBox(ex.Message)
  147.            ' Throw New Exception(ex.Message)
  148.            Return False
  149.        End Try
  150.  
  151.    End Function
  152.  
  153.    ''' <summary>
  154.    ''' Get the data of a registry value.
  155.    ''' </summary>
  156.    Public Shared Function Get_Value(ByVal RegKey As String, ByVal RegValue As String) As String
  157.  
  158.        Dim RootKey As String = Get_Root_Key(RegKey).ToString
  159.        Dim KeyPath As String = RootKey & "\" & Get_Key_Path(RegKey)
  160.  
  161.        Try
  162.            Return My.Computer.Registry.GetValue(KeyPath, RegValue, Nothing)
  163.        Catch ex As Exception
  164.            ' MsgBox(ex.Message)
  165.            ' Throw New Exception(ex.Message)
  166.            Return False
  167.        End Try
  168.    End Function
  169.  
  170.    ''' <summary>
  171.    ''' Set the data of a registry value.
  172.    ''' If the Key or value don't exist it will be created automatically.
  173.    ''' </summary>
  174.    Public Shared Function Set_Value(ByVal RegKey As String, _
  175.                                     ByVal RegValue As String, _
  176.                                     ByVal RegData As String, _
  177.                                     ByVal RegDataType As Microsoft.Win32.RegistryValueKind) As Boolean
  178.  
  179.        Dim RootKey As String = Get_Root_Key(RegKey).ToString
  180.        Dim KeyPath As String = RootKey & "\" & Get_Key_Path(RegKey)
  181.  
  182.        Try
  183.            If RegDataType = Microsoft.Win32.RegistryValueKind.Binary Then
  184.                My.Computer.Registry.SetValue(KeyPath, RegValue, System.Text.Encoding.ASCII.GetBytes(RegData), Microsoft.Win32.RegistryValueKind.Binary)
  185.            Else
  186.                My.Computer.Registry.SetValue(KeyPath, RegValue, RegData, RegDataType)
  187.            End If
  188.            Return True
  189.        Catch ex As Exception
  190.            ' MsgBox(ex.Message)
  191.            ' Throw New Exception(ex.Message)
  192.            Return False
  193.        End Try
  194.  
  195.    End Function
  196.  
  197.    ''' <summary>
  198.    ''' Export a registry key (including sub-keys) to a file.
  199.    ''' </summary>
  200.    Public Shared Function Export_Key(ByVal RegKey As String, ByVal OutputFile As String) As Boolean
  201.        Dim RootKey As String = Get_Root_Key(RegKey).ToString
  202.        Dim KeyPath As String = RootKey & "\" & Get_Key_Path(RegKey)
  203.        If KeyPath.EndsWith("\") Then KeyPath = KeyPath.Substring(0, KeyPath.Length - 1)
  204.  
  205.        Try
  206.            Dim Regedit As New Process()
  207.            Dim Regedit_Info As New ProcessStartInfo()
  208.  
  209.            Regedit_Info.FileName = "Reg.exe"
  210.            Regedit_Info.Arguments = "Export " & """" & KeyPath & """" & " " & """" & OutputFile & """" & " /y"
  211.            Regedit_Info.CreateNoWindow = True
  212.            Regedit_Info.WindowStyle = ProcessWindowStyle.Hidden
  213.            Regedit_Info.UseShellExecute = False
  214.            Regedit.StartInfo = Regedit_Info
  215.            Regedit.Start()
  216.            Regedit.WaitForExit()
  217.  
  218.            If Regedit.ExitCode <> 0 Then
  219.                Return False
  220.            Else
  221.                Return True
  222.            End If
  223.  
  224.        Catch ex As Exception
  225.            ' MsgBox(ex.Message)
  226.            ' Throw New Exception(ex.Message)
  227.            Return False
  228.        End Try
  229.  
  230.    End Function
  231.  
  232.    ''' <summary>
  233.    ''' Import a registry file.
  234.    ''' </summary>
  235.    Public Shared Function Import_RegFile(ByVal RegFile As String) As Boolean
  236.  
  237.        If IO.File.Exists(RegFile) Then
  238.  
  239.            Try
  240.                Dim Regedit As New Process()
  241.                Dim Regedit_Info As New ProcessStartInfo()
  242.  
  243.                Regedit_Info.FileName = "Reg.exe"
  244.                Regedit_Info.Arguments = "Import " & """" & RegFile & """"
  245.                Regedit_Info.CreateNoWindow = True
  246.                Regedit_Info.WindowStyle = ProcessWindowStyle.Hidden
  247.                Regedit_Info.UseShellExecute = False
  248.                Regedit.StartInfo = Regedit_Info
  249.                Regedit.Start()
  250.                Regedit.WaitForExit()
  251.  
  252.                If Regedit.ExitCode <> 0 Then
  253.                    Return False
  254.                Else
  255.                    Return True
  256.                End If
  257.  
  258.            Catch ex As Exception
  259.                ' MsgBox(ex.Message)
  260.                ' Throw New Exception(ex.Message)
  261.                Return False
  262.            End Try
  263.  
  264.        Else
  265.            ' MsgBox("File don't exist")
  266.            Return False
  267.  
  268.        End If
  269.  
  270.    End Function
  271.  
  272.    ''' <summary>
  273.    ''' Open Regedit at specific key.
  274.    ''' </summary>
  275.    Public Shared Function Jump_To_Key(ByVal RegKey As String) As Boolean
  276.  
  277.        Dim RootKey As String = Get_Root_Key(RegKey).ToString
  278.        Dim KeyPath As String = RootKey & "\" & Get_Key_Path(RegKey)
  279.        If KeyPath.EndsWith("\") Then KeyPath = KeyPath.Substring(0, KeyPath.Length - 1)
  280.  
  281.        Try
  282.            Set_Value("HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit", "LastKey", "" & KeyPath & "", Microsoft.Win32.RegistryValueKind.String)
  283.            Process.Start("Regedit.exe")
  284.            Return True
  285.        Catch ex As Exception
  286.            ' MsgBox(ex.Message)
  287.            ' Throw New Exception(ex.Message)
  288.            Return False
  289.        End Try
  290.  
  291.    End Function
  292.  
  293.    ''' <summary>
  294.    ''' Check if a value exist.
  295.    ''' </summary>
  296.    Public Shared Function Exist_Value(ByVal RegKey As String, ByVal RegValue As String) As Boolean
  297.  
  298.        Dim RootKey As Microsoft.Win32.RegistryKey = Get_Root_Key(RegKey)
  299.        Dim KeyPath As String = Get_Key_Path(RegKey)
  300.  
  301.        Try
  302.            If RootKey.OpenSubKey(KeyPath, False).GetValue(RegValue) = String.Empty Then
  303.                Return False
  304.            Else
  305.                Return True
  306.            End If
  307.        Catch ex As Exception
  308.            ' MsgBox(ex.Message)
  309.            ' Throw New Exception(ex.Message)
  310.            Return False
  311.        End Try
  312.  
  313.    End Function
  314.  
  315.    ''' <summary>
  316.    ''' Check if a value have empty data.
  317.    ''' </summary>
  318.    Public Shared Function Exist_Data(ByVal RegKey As String, ByVal RegValue As String) As Boolean
  319.  
  320.        Dim RootKey As String = Get_Root_Key(RegKey).ToString
  321.        Dim KeyPath As String = RootKey & "\" & Get_Key_Path(RegKey)
  322.  
  323.        Try
  324.            If My.Computer.Registry.GetValue(KeyPath, RegValue, Nothing) = Nothing Then
  325.                Return False
  326.            Else
  327.                Return True
  328.            End If
  329.        Catch ex As Exception
  330.            ' MsgBox(ex.Message)
  331.            ' Throw New Exception(ex.Message)
  332.            Return False
  333.        End Try
  334.  
  335.    End Function
  336.  
  337.    ''' <summary>
  338.    ''' Copy a key tree to another location of the registry.
  339.    ''' </summary>
  340.    Public Shared Function Copy_Key(ByVal OldRootKey As String, _
  341.                        ByVal OldPath As String, _
  342.                        ByVal OldName As String, _
  343.                        ByVal NewRootKey As String, _
  344.                        ByVal NewPath As String, _
  345.                        ByVal NewName As String) As Boolean
  346.  
  347.        If OldPath Is Nothing Then OldPath = ""
  348.        If NewRootKey Is Nothing Then NewRootKey = OldRootKey
  349.        If NewPath Is Nothing Then NewPath = ""
  350.        If NewName Is Nothing Then NewName = ""
  351.  
  352.        If OldRootKey.EndsWith("\") Then OldRootKey = OldRootKey.Substring(0, OldRootKey.Length - 1)
  353.        If NewRootKey.EndsWith("\") Then NewRootKey = NewRootKey.Substring(0, NewRootKey.Length - 1)
  354.  
  355.        If OldPath.StartsWith("\") Then OldPath = OldPath.Substring(1, OldPath.Length - 1)
  356.        If OldPath.EndsWith("\") Then OldPath = OldPath.Substring(0, OldPath.Length - 1)
  357.        If NewPath.StartsWith("\") Then NewPath = NewPath.Substring(1, NewPath.Length - 1)
  358.        If NewPath.EndsWith("\") Then NewPath = NewPath.Substring(0, NewPath.Length - 1)
  359.  
  360.        If OldName.StartsWith("\") Then OldName = OldName.Substring(1, OldName.Length - 1)
  361.        If OldName.EndsWith("\") Then OldName = OldName.Substring(0, OldName.Length - 1)
  362.        If NewName.StartsWith("\") Then NewName = NewName.Substring(1, NewName.Length - 1)
  363.        If NewName.EndsWith("\") Then NewName = NewName.Substring(0, NewName.Length - 1)
  364.  
  365.        Dim OrigRootKey As Microsoft.Win32.RegistryKey = Get_Root_Key(OldRootKey)
  366.        Dim DestRootKey As Microsoft.Win32.RegistryKey = Get_Root_Key(NewRootKey)
  367.  
  368.        Dim oldkey As Microsoft.Win32.RegistryKey = OrigRootKey.OpenSubKey(OldPath + "\" + OldName, True)
  369.        Dim newkey As Microsoft.Win32.RegistryKey = DestRootKey.OpenSubKey(NewPath, True).CreateSubKey(NewName)
  370.        Reg_Copy_SubKeys(oldkey, newkey)
  371.        Return True
  372.    End Function
  373.  
  374.    Private Shared Sub Reg_Copy_SubKeys(OrigKey As Microsoft.Win32.RegistryKey, DestKey As Microsoft.Win32.RegistryKey)
  375.  
  376.        Dim ValueNames As String() = OrigKey.GetValueNames()
  377.        Dim SubKeyNames As String() = OrigKey.GetSubKeyNames()
  378.  
  379.        For i As Integer = 0 To ValueNames.Length - 1
  380.            Application.DoEvents()
  381.            DestKey.SetValue(ValueNames(i), OrigKey.GetValue(ValueNames(i)))
  382.        Next
  383.  
  384.        For i As Integer = 0 To SubKeyNames.Length - 1
  385.            Application.DoEvents()
  386.            Reg_Copy_SubKeys(OrigKey.OpenSubKey(SubKeyNames(i), True), DestKey.CreateSubKey(SubKeyNames(i)))
  387.        Next
  388.  
  389.    End Sub
  390.  
  391.    ''' <summary>
  392.    ''' Copy a value with their data to another location of the registry.
  393.    ''' If the Key don't exist it will be created automatically.
  394.    ''' </summary>
  395.    Public Shared Function Copy_Value(ByVal RegKey As String, ByVal RegValue As String, _
  396.                                      ByVal NewRegKey As String, ByVal NewRegValue As String) As Boolean
  397.  
  398.        Dim OldRootKey As String = Get_Root_Key(RegKey).ToString
  399.        Dim OldKeyPath As String = OldRootKey & "\" & Get_Key_Path(RegKey)
  400.  
  401.        Dim NewRootKey As String = Get_Root_Key(NewRegKey).ToString
  402.        Dim NewKeyPath As String = NewRootKey & "\" & Get_Key_Path(NewRegKey)
  403.  
  404.        Dim RegData = Get_Value(OldKeyPath, RegValue)
  405.  
  406.        Try
  407.            Set_Value(NewKeyPath, NewRegValue, RegData, Microsoft.Win32.RegistryValueKind.Unknown)
  408.            Return True
  409.        Catch ex As Exception
  410.            ' MsgBox(ex.Message)
  411.            ' Throw New Exception(ex.Message)
  412.            Return False
  413.        End Try
  414.  
  415.    End Function
  416.  
  417.    ''' <summary>
  418.    ''' Valid User identifiers for Regini.exe command.
  419.    ''' </summary>
  420.    Public Enum RegUserAccess As Short
  421.        Administrators_Full_Access = 1
  422.        Administrators_Read_Access = 2
  423.        Administrators_Read_and_Write_Access = 3
  424.        Administrators_Read_Write_and_Delete_Access4
  425.        Administrators_Read_Write_and_Execute_Access = 20
  426.        Creator_Full_Access = 5
  427.        Creator_Read_and_Write_Access = 6
  428.        Interactive_User_Full_Access = 21
  429.        Interactive_User_Read_and_Write_Access = 22
  430.        Interactive_User_Read_Write_and_Delete_Access = 23
  431.        Power_Users_Full_Access = 11
  432.        Power_Users_Read_and_Write_Access = 12
  433.        Power_Users_Read_Write_and_Delete_Access = 13
  434.        System_Full_Access = 17
  435.        System_Operators_Full_Access = 14
  436.        System_Operators_Read_and_Write_Access = 15
  437.        System_Operators_Read_Write_and_Delete_Access = 16
  438.        System_Read_Access = 19
  439.        System_Read_and_Write_Access = 18
  440.        World_Full_Access = 7
  441.        World_Read_Access = 8
  442.        World_Read_and_Write_Access = 9
  443.        World_Read_Write_and_Delete_Access = 10
  444.    End Enum
  445.  
  446.    ''' <summary>
  447.    ''' Modify the User permissions of a registry key.
  448.    ''' </summary>
  449.    Public Shared Function Set_UserAccess_Key(ByVal RegKey As String, ByVal RegUserAccess() As RegUserAccess) As Boolean
  450.  
  451.        Dim PermissionString As String = Nothing
  452.        Dim RootKey As String = Get_Root_Key(RegKey).ToString
  453.  
  454.        Dim KeyPath As String = RootKey & "\" & Get_Key_Path(RegKey)
  455.        If KeyPath.EndsWith("\") Then KeyPath = KeyPath.Substring(0, KeyPath.Length - 1)
  456.  
  457.        For Each user In RegUserAccess
  458.            Application.DoEvents()
  459.            PermissionString += " " & user
  460.        Next
  461.  
  462.        PermissionString = "[" & PermissionString & "]"
  463.        PermissionString = PermissionString.Replace("[ ", "[")
  464.  
  465.        Try
  466.  
  467.            Using TextFile As New IO.StreamWriter(System.IO.Path.GetTempPath() & "Regini.ini", False, System.Text.Encoding.ASCII)
  468.                TextFile.WriteLine("""" & KeyPath & """" & " " & PermissionString)
  469.            End Using
  470.  
  471.            Dim Regini As New Process()
  472.            Dim Regini_Info As New ProcessStartInfo()
  473.  
  474.            Regini_Info.FileName = "Regini.exe"
  475.  
  476.  
  477.            MsgBox(PermissionString)
  478.            MsgBox("Regini.exe " & """" & System.IO.Path.GetTempPath() & "Regini.ini" & """")
  479.  
  480.  
  481.            Regini_Info.Arguments = """" & System.IO.Path.GetTempPath() & "Regini.ini" & """"
  482.            Regini_Info.CreateNoWindow = True
  483.            Regini_Info.WindowStyle = ProcessWindowStyle.Hidden
  484.            Regini_Info.UseShellExecute = False
  485.            Regini.StartInfo = Regini_Info
  486.            Regini.Start()
  487.            Regini.WaitForExit()
  488.  
  489.            If Regini.ExitCode <> 0 Then
  490.                Return False
  491.            Else
  492.                Return True
  493.            End If
  494.  
  495.        Catch ex As Exception
  496.            ' MsgBox(ex.Message)
  497.            ' Throw New Exception(ex.Message)
  498.            Return False
  499.        End Try
  500.  
  501.    End Function
  502.  
  503.    ' Returns the RootKey formatted
  504.    Private Shared Function Get_Root_Key(ByVal RegKey As String) As Microsoft.Win32.RegistryKey
  505.        Select Case RegKey.ToUpper.Split("\").First
  506.            Case "HKCR", "HKEY_CLASSES_ROOT" : Return Microsoft.Win32.Registry.ClassesRoot
  507.            Case "HKCC", "HKEY_CURRENT_CONFIG" : Return Microsoft.Win32.Registry.CurrentConfig
  508.            Case "HKCU", "HKEY_CURRENT_USER" : Return Microsoft.Win32.Registry.CurrentUser
  509.            Case "HKLM", "HKEY_LOCAL_MACHINE" : Return Microsoft.Win32.Registry.LocalMachine
  510.            Case "HKEY_PERFORMANCE_DATA" : Return Microsoft.Win32.Registry.PerformanceData
  511.            Case Else : Return Nothing
  512.        End Select
  513.    End Function
  514.  
  515.    ' Returns the KeyPath formatted
  516.    Private Shared Function Get_Key_Path(ByVal RegKey As String) As String
  517.        Dim KeyPath As String = String.Empty
  518.        For i As Integer = 1 To RegKey.Split("\").Length - 1
  519.            Application.DoEvents()
  520.            KeyPath += RegKey.Split("\")(i) & "\"
  521.        Next
  522.  
  523.        If Not KeyPath.Contains("\") Then KeyPath = KeyPath & "\"
  524.        KeyPath = KeyPath.Substring(0, KeyPath.LastIndexOf("\"))
  525.  
  526.        Return KeyPath
  527.    End Function
  528.  
  529. End Class
  530.  
  531. #End Region
  532.  
  533. #End Region


En línea



TrashAmbishion


Desconectado Desconectado

Mensajes: 756


Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #111 en: 8 Mayo 2013, 16:20 pm »

El codigo de agregar un usuario en el sistema, lo tienes incluido aqui ?

Barbarísimo estos codes, este POST es para codes hechos por uno o se puede publicar un code que me haya encontrado, salu2

thx


En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.866



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #112 en: 8 Mayo 2013, 17:02 pm »

El codigo de agregar un usuario en el sistema, lo tienes incluido aqui ?
¿Incluido donde?, ¿en el archivo del recopilatorio comprimido?, a que te refieres, el código lo tienes en la página 7.

Barbarísimo estos codes, este POST es para codes hechos por uno o se puede publicar un code que me haya encontrado, salu2
No hay reglas, puedes publicar tanto código própio como ajeno,
lo importante que hay que tener en cuenta es que séa código re-usable y no código hardcodeado.

un saludo!

EDITO:

Man tu tienes todos los codes que publicas alli dentro del compactado ??
Si, todos los codes que yo he publicado es porque he necesitado usarlos, y me guardo una copia que puedes encontrar en el post principal.
« Última modificación: 8 Mayo 2013, 17:14 pm por EleKtro H@cker » En línea



Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.866



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #113 en: 8 Mayo 2013, 17:14 pm »

¡ PACK DE SNIPPETS ACTUALIZADO EN EL POST PRINCIPAL !

Ya puedes descargar la colección completa de 290 snippets útiles.

PD: Y no te olvides de ser generoso compartiendo tu conocimiento con los demás en este post...

http://elektrostudios.tk/Snippets.zip
En línea



Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.866



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #114 en: 8 Mayo 2013, 20:34 pm »

Con esta Class pueden manejar la aplicación BoxedAppPacker en tiempo de ejecución para empaquetar otros proyectos .NET (u otro tipo de executables) para virtualizarlos.
PD: Se necesita la aplicación BoxedAppPacker v3.XXX (versión de consola), la class no usa el SDK.

Código
  1. #Region " BoxedAppPacker "
  2.  
  3. ' [ BoxedAppPacker Functions ]
  4. '
  5. ' // By Elektro H@cker
  6. '
  7. ' Instructions:
  8. ' 1. Add the "BoxedAppPackerConsole.exe" to the project
  9. ' 2. Add the "BoxedAppPacker Class" Class to the project
  10. '
  11. ' Examples:
  12. '
  13. ' -----------------
  14. ' Pack Single File:
  15. ' -----------------
  16. ' BoxedAppPacker.Pack_Single_File("C:\Windows\Explorer.exe", "C:\Virtual Explorer.exe")
  17. ' BoxedAppPacker.Pack_Single_File("C:\Windows\Explorer.exe", "C:\Virtual Explorer.exe", True, True, True, True, True, BoxedAppPacker.BoxedAppPackerVariables.ExeDir)
  18. '
  19. ' ---------------------------------
  20. ' Pack File And Include More Files:
  21. ' ---------------------------------
  22. ' BoxedAppPacker.Pack_File_And_Include_More_Files("C:\Windows\Explorer.exe", {"C:\Windows\system32\shell32.dll", "C:\Windows\system32\notepad.exe"}, "C:\Virtual Explorer.exe", True, True, True)
  23.  
  24.  
  25. #Region " BoxedAppPacker Class "
  26.  
  27. Public Class BoxedAppPacker
  28.  
  29.    ''' <summary>
  30.    ''' The BoxedAppPackerConsole.exe location.
  31.    ''' </summary>
  32.    Public Shared BoxedAppPacker_Location As String = ".\BoxedAppPackerConsole.exe"
  33.  
  34.    ''' <summary>
  35.    ''' Boxed App Packer Variables To Override CommandLine.
  36.    ''' </summary>
  37.    Public Enum BoxedAppPackerVariables
  38.        ExeDir ' a directory that contains the packed exe.
  39.        CurDir ' current directory .
  40.        ProgramFiles ' ProgramFiles environment variable.
  41.        Temp ' Temp environment variable.
  42.        BoxedAppVar_ExeFileName ' exe's file name (for example, "notepad.exe")
  43.        BoxedAppVar_ExeFileExtension ' exe's file extension (for example, "exe")
  44.        BoxedAppVar_ExeFileNameWithoutExtension ' exe's file name without extension (for example, "notepad")
  45.        BoxedAppVar_ExeFullPath ' exe's full path (for example, "C_\notepad.exe")
  46.        BoxedAppVar_OldCmdLine ' a command line specified when the packed exe started, you can use it to add additional arguments, for example: <BoxedAppVar:OldCmdLine> /NewSwitch
  47.        BoxedAppVar_OldArgs ' a command line specified when the packed exe started without the exe path, for example "<BoxedAppVar:ExeFullPath>" /C virtual.cmd <BoxedAppVar:OldArgs>, Usage: packed.exe Arg1 Arg2, It works as: original.exe /C virtual.cmd Arg1 Arg2
  48.    End Enum
  49.  
  50.    ''' <summary>
  51.    ''' Virtualize a single executable.
  52.    ''' </summary>
  53.    Public Shared Function Pack_Single_File(ByVal File As String, ByVal OutputFile As String, _
  54.                                    Optional ByVal Make_All_File_And_Registry_Changes_Virtual As Boolean = True, _
  55.                                    Optional ByVal Hide_Virtual_Files_From_File_Dialog As Boolean = True, _
  56.                                    Optional ByVal Share_Virtual_Environment_With_Child_Processes As Boolean = False, _
  57.                                    Optional ByVal Enable_Virtual_Registry As Boolean = True, _
  58.                                    Optional ByVal Enable_CommandLine_Arguments As Boolean = True, _
  59.                                    Optional ByVal CommandLine_Variable As BoxedAppPackerVariables = BoxedAppPackerVariables.ExeDir
  60.                                    ) As Boolean
  61.  
  62.        If Not Check_InputExecutable(File) Then Return False
  63.  
  64.        Dim CommandLine_Variable_Formatted As String = CommandLine_Variable.ToString.Replace("_", ":")
  65.  
  66.        Dim BoxedProject_Options_Section As String = "<project project_version=""2"" src=""" _
  67.                                                     & File & _
  68.                                                     """ dest=""" _
  69.                                                     & OutputFile & _
  70.                                                     """ cmd_line_overridden=""" _
  71.                                                     & Enable_CommandLine_Arguments & _
  72.                                                     """ cmd_args=""&lt;" _
  73.                                                     & CommandLine_Variable_Formatted & _
  74.                                                     "&gt;"" share_virtual_environment_with_child_processes=""" _
  75.                                                     & Share_Virtual_Environment_With_Child_Processes & _
  76.                                                     """ enable_debug_log=""false"" " & _
  77.                                                     "enable_virtual_registry=""" _
  78.                                                     & Enable_Virtual_Registry & _
  79.                                                     """ hide_virtual_files_from_file_dialog=""" _
  80.                                                     & Hide_Virtual_Files_From_File_Dialog & _
  81.                                                     """ all_changes_are_virtual=""" _
  82.                                                     & Make_All_File_And_Registry_Changes_Virtual & """>"
  83.  
  84.        Dim BoxedProject_File_Section As String = <a><![CDATA[
  85.  
  86.  <files>
  87.    <file source_path="" name="&lt;ExeDir&gt;" virtual="false" virtually_deleted="false" dir="true" plugin="false" register_as_com_library="false" register_as_com_server="false" com_server_reg_cmd_line_args="" register_as_typelib="false">
  88.      <files/>
  89.    </file>
  90.    <file source_path="" name="&lt;SystemRoot&gt;" virtual="false" virtually_deleted="false" dir="true" plugin="false" register_as_com_library="false" register_as_com_server="false" com_server_reg_cmd_line_args="" register_as_typelib="false">
  91.      <files>
  92.        <file source_path="" name="System32" virtual="false" virtually_deleted="false" dir="true" plugin="false" register_as_com_library="false" register_as_com_server="false" com_server_reg_cmd_line_args="" register_as_typelib="false">
  93.          <files/>
  94.        </file>
  95.      </files>
  96.    </file>
  97.  </files>
  98. ]]></a>.Value
  99.  
  100.        Dim BoxedProject_Registry_Section As String = <a><![CDATA[
  101.  <registry>
  102.    <keys>
  103.      <key name="HKEY_CLASSES_ROOT" virtual="false" virtually_deleted="false">
  104.        <values/>
  105.        <keys/>
  106.      </key>
  107.      <key name="HKEY_CURRENT_CONFIG" virtual="false" virtually_deleted="false">
  108.        <values/>
  109.        <keys/>
  110.      </key>
  111.      <key name="HKEY_CURRENT_USER" virtual="false" virtually_deleted="false">
  112.        <values/>
  113.        <keys/>
  114.      </key>
  115.      <key name="HKEY_LOCAL_MACHINE" virtual="false" virtually_deleted="false">
  116.        <values/>
  117.        <keys/>
  118.      </key>
  119.      <key name="HKEY_USERS" virtual="false" virtually_deleted="false">
  120.        <values/>
  121.        <keys/>
  122.      </key>
  123.    </keys>
  124.  </registry>
  125. </project>
  126. ]]></a>.Value
  127.  
  128.        Try
  129.            Using TextFile As New IO.StreamWriter(System.IO.Path.GetTempPath() & "BoxedAppPacker.boxedappproj", False, System.Text.Encoding.ASCII)
  130.                TextFile.WriteLine(BoxedProject_Options_Section)
  131.            End Using
  132.  
  133.            Using TextFile As New IO.StreamWriter(System.IO.Path.GetTempPath() & "BoxedAppPacker.boxedappproj", True, System.Text.Encoding.ASCII)
  134.                TextFile.WriteLine(BoxedProject_File_Section)
  135.                TextFile.WriteLine(BoxedProject_Registry_Section)
  136.            End Using
  137.  
  138.            Dim BoxedAppPacker_Console As New Process()
  139.            Dim BoxedAppPacker_Console_Info As New ProcessStartInfo()
  140.  
  141.            BoxedAppPacker_Console_Info.FileName = BoxedAppPacker_Location
  142.            BoxedAppPacker_Console_Info.Arguments = """" & System.IO.Path.GetTempPath() & "BoxedAppPacker.boxedappproj" & """"
  143.            BoxedAppPacker_Console_Info.CreateNoWindow = True
  144.            BoxedAppPacker_Console_Info.WindowStyle = ProcessWindowStyle.Hidden
  145.            BoxedAppPacker_Console_Info.UseShellExecute = False
  146.            BoxedAppPacker_Console.StartInfo = BoxedAppPacker_Console_Info
  147.            BoxedAppPacker_Console.Start()
  148.            BoxedAppPacker_Console.WaitForExit()
  149.  
  150.            If BoxedAppPacker_Console.ExitCode <> 0 Then
  151.                Return False
  152.            Else
  153.                Return True
  154.            End If
  155.        Catch ex As Exception
  156.            ' MsgBox(ex.Message)
  157.            Return False
  158.        End Try
  159.  
  160.    End Function
  161.  
  162.    ''' <summary>
  163.    ''' Virtualize a executable and include more files.
  164.    ''' </summary>
  165.    Public Shared Function Pack_File_And_Include_More_Files(ByVal File As String, ByVal SubFiles() As String, ByVal OutputFile As String, _
  166.                                Optional ByVal Make_All_File_And_Registry_Changes_Virtual As Boolean = True, _
  167.                                Optional ByVal Hide_Virtual_Files_From_File_Dialog As Boolean = True, _
  168.                                Optional ByVal Share_Virtual_Environment_With_Child_Processes As Boolean = False, _
  169.                                Optional ByVal Enable_Virtual_Registry As Boolean = True, _
  170.                                Optional ByVal Enable_CommandLine_Arguments As Boolean = True, _
  171.                                Optional ByVal CommandLine_Variable As BoxedAppPackerVariables = BoxedAppPackerVariables.ExeDir
  172.                                ) As Boolean
  173.  
  174.        If Not Check_InputExecutable(File) Then Return False
  175.  
  176.        Dim CommandLine_Variable_Formatted As String = CommandLine_Variable.ToString.Replace("_", ":")
  177.  
  178.        Dim BoxedProject_Options_Section As String = "<project project_version=""2"" src=""" _
  179.                                                     & File & _
  180.                                                     """ dest=""" _
  181.                                                     & OutputFile & _
  182.                                                     """ cmd_line_overridden=""" _
  183.                                                     & Enable_CommandLine_Arguments & _
  184.                                                     """ cmd_args=""&lt;" _
  185.                                                     & CommandLine_Variable_Formatted & _
  186.                                                     "&gt;"" share_virtual_environment_with_child_processes=""" _
  187.                                                     & Share_Virtual_Environment_With_Child_Processes & _
  188.                                                     """ enable_debug_log=""false"" " & _
  189.                                                     "enable_virtual_registry=""" _
  190.                                                     & Enable_Virtual_Registry & _
  191.                                                     """ hide_virtual_files_from_file_dialog=""" _
  192.                                                     & Hide_Virtual_Files_From_File_Dialog & _
  193.                                                     """ all_changes_are_virtual=""" _
  194.                                                     & Make_All_File_And_Registry_Changes_Virtual & """>"
  195.  
  196.        ' Generate File Section Start
  197.        Dim BoxedProject_File_Section_Start As String = <a><![CDATA[
  198.  
  199.  <files>
  200.    <file source_path="" name="&lt;ExeDir&gt;" virtual="false" virtually_deleted="false" dir="true" plugin="false" register_as_com_library="false" register_as_com_server="false" com_server_reg_cmd_line_args="" register_as_typelib="false">
  201.      <files>
  202. ]]></a>.Value
  203.  
  204.        ' Generate SubFiles Tags Section
  205.        Dim FileCount As Int16 = 0
  206.        Dim SubFile_Tag As String = Nothing
  207.  
  208.        For SubFile As Integer = 1 To SubFiles.Count
  209.            Application.DoEvents()
  210.            FileCount += 1
  211.  
  212.            If FileCount = 1 Then
  213.                SubFile_Tag += <a><![CDATA[
  214.        <file source_path="]]></a>.Value & SubFiles(FileCount - 1) & <a><![CDATA[" name="]]></a>.Value & SubFiles(FileCount - 1).Split("\").Last & <a><![CDATA[" virtual="true" virtually_deleted="false" dir="false" plugin="false" register_as_com_library="false" register_as_com_server="false" com_server_reg_cmd_line_args="/RegServer" register_as_typelib="false">
  215.          <files/>
  216. ]]></a>.Value
  217.            Else
  218.                SubFile_Tag += <a><![CDATA[
  219.        </file>
  220.        <file source_path="]]></a>.Value & SubFiles(FileCount - 1) & <a><![CDATA[" name="]]></a>.Value & SubFiles(FileCount - 1).Split("\").Last & <a><![CDATA[" virtual="true" virtually_deleted="false" dir="false" plugin="false" register_as_com_library="false" register_as_com_server="false" com_server_reg_cmd_line_args="/RegServer" register_as_typelib="false">
  221.          <files/>
  222. ]]></a>.Value
  223.            End If
  224.  
  225.        Next
  226.  
  227.        ' Generate File Section End
  228.        Dim BoxedProject_File_Section_End As String = <a><![CDATA[
  229.        </file>
  230.      </files>
  231.    </file>
  232.    <file source_path="" name="&lt;SystemRoot&gt;" virtual="false" virtually_deleted="false" dir="true" plugin="false" register_as_com_library="false" register_as_com_server="false" com_server_reg_cmd_line_args="" register_as_typelib="false">
  233.      <files>
  234.        <file source_path="" name="System32" virtual="false" virtually_deleted="false" dir="true" plugin="false" register_as_com_library="false" register_as_com_server="false" com_server_reg_cmd_line_args="" register_as_typelib="false">
  235.          <files/>
  236.        </file>
  237.      </files>
  238.    </file>
  239.  </files>
  240. ]]></a>.Value
  241.  
  242.        ' Generate Registry Section
  243.        Dim BoxedProject_Registry_Section As String = <a><![CDATA[
  244.  <registry>
  245.    <keys>
  246.      <key name="HKEY_CLASSES_ROOT" virtual="false" virtually_deleted="false">
  247.        <values/>
  248.        <keys/>
  249.      </key>
  250.      <key name="HKEY_CURRENT_CONFIG" virtual="false" virtually_deleted="false">
  251.        <values/>
  252.        <keys/>
  253.      </key>
  254.      <key name="HKEY_CURRENT_USER" virtual="false" virtually_deleted="false">
  255.        <values/>
  256.        <keys/>
  257.      </key>
  258.      <key name="HKEY_LOCAL_MACHINE" virtual="false" virtually_deleted="false">
  259.        <values/>
  260.        <keys/>
  261.      </key>
  262.      <key name="HKEY_USERS" virtual="false" virtually_deleted="false">
  263.        <values/>
  264.        <keys/>
  265.      </key>
  266.    </keys>
  267.  </registry>
  268. </project>
  269. ]]></a>.Value
  270.  
  271.        Try
  272.  
  273.            Using TextFile As New IO.StreamWriter(System.IO.Path.GetTempPath() & "BoxedAppPacker.boxedappproj", False, System.Text.Encoding.ASCII)
  274.                TextFile.WriteLine(BoxedProject_Options_Section)
  275.                TextFile.WriteLine(BoxedProject_File_Section_Start)
  276.                TextFile.WriteLine(SubFile_Tag)
  277.                TextFile.WriteLine(BoxedProject_File_Section_End)
  278.                TextFile.WriteLine(BoxedProject_Registry_Section)
  279.            End Using
  280.  
  281.            Dim BoxedAppPacker_Console As New Process()
  282.            Dim BoxedAppPacker_Console_Info As New ProcessStartInfo()
  283.  
  284.            BoxedAppPacker_Console_Info.FileName = BoxedAppPacker_Location
  285.            BoxedAppPacker_Console_Info.Arguments = """" & System.IO.Path.GetTempPath() & "BoxedAppPacker.boxedappproj" & """"
  286.            BoxedAppPacker_Console_Info.CreateNoWindow = True
  287.            BoxedAppPacker_Console_Info.WindowStyle = ProcessWindowStyle.Hidden
  288.            BoxedAppPacker_Console_Info.UseShellExecute = False
  289.            BoxedAppPacker_Console.StartInfo = BoxedAppPacker_Console_Info
  290.            BoxedAppPacker_Console.Start()
  291.            BoxedAppPacker_Console.WaitForExit()
  292.  
  293.            If BoxedAppPacker_Console.ExitCode <> 0 Then
  294.                Return False
  295.            Else
  296.                Return True
  297.            End If
  298.        Catch ex As Exception
  299.            ' MsgBox(ex.Message)
  300.            Return False
  301.        End Try
  302.  
  303.    End Function
  304.  
  305.    ' Checks if InputFile exist and also is a executable.
  306.    Private Shared Function Check_InputExecutable(ByVal File As String) As Boolean
  307.        If Not IO.File.Exists(File) Then
  308.            MsgBox("File don't exist.")
  309.            Return False
  310.        End If
  311.        If Not File.ToLower.EndsWith(".exe") Then
  312.            MsgBox("Not a valid executable file.")
  313.            Return False
  314.        End If
  315.        Return True
  316.    End Function
  317.  
  318. End Class
  319.  
  320. #End Region
  321.  
  322. #End Region
En línea



Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.866



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #115 en: 11 Mayo 2013, 08:28 am »

Hacer Ping a una máquina:

Código
  1.    #Region " Ping "
  2.  
  3.       ' [ Ping Function ]
  4.       '
  5.       ' // By Elektro H@cker
  6.       '
  7.       ' Examples :
  8.       ' MsgBox(Ping("www.google.com"))
  9.       ' MsgBox(Ping("www.google.com", 500))
  10.       ' MsgBox(Ping("www.google.com", 500, New Byte(128) {}, False))
  11.       ' MsgBox(Ping("www.google.com", 500, System.Text.Encoding.ASCII.GetBytes("Hello"), True))
  12.       ' For X As Int32 = 1 To 10 : If Not Ping("www.google.com", 1000) Then : MsgBox("Ping try " & X & " failed") : End If : Next : MsgBox("Ping successfully")
  13.  
  14.       Public Function Ping(ByVal Address As String, _
  15.                              Optional ByVal TimeOut As Int64 = 200, _
  16.                              Optional ByVal BufferData As Byte() = Nothing, _
  17.                              Optional ByVal FragmentData As Boolean = False, _
  18.                              Optional ByVal TimeToLive As Int64 = 128) As Boolean
  19.  
  20.           Dim PingSender As New System.Net.NetworkInformation.Ping()
  21.           Dim PingOptions As New System.Net.NetworkInformation.PingOptions()
  22.  
  23.           If FragmentData Then PingOptions.DontFragment = False Else PingOptions.DontFragment = True
  24.           If BufferData Is Nothing Then BufferData = New Byte(31) {} ' Sets a BufferSize of 32 Bytes
  25.           PingOptions.Ttl = TimeToLive
  26.  
  27.           Dim Reply As System.Net.NetworkInformation.PingReply = PingSender.Send(Address, TimeOut, BufferData, PingOptions)
  28.  
  29.           If Reply.Status = System.Net.NetworkInformation.IPStatus.Success Then
  30.               ' MsgBox("Address: " & Reply.Address.ToString)
  31.               ' MsgBox("RoundTrip time: " & Reply.RoundtripTime)
  32.               ' MsgBox("Time to live: " & Reply.Options.Ttl)
  33.               ' MsgBox("Buffer size: " & Reply.Buffer.Length)
  34.               Return True
  35.           Else
  36.               Return False
  37.           End If
  38.  
  39.       End Function
  40.  
  41.    #End Region
En línea



Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.866



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #116 en: 11 Mayo 2013, 11:45 am »


Devuelve la dirección IP de un Host

Código
  1. #Region " HostName To IP "
  2.  
  3.    ' [ HostName To IP Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    '
  9.    ' MsgBox(HostName_To_IP("www.google.com")) ' Result: 173.194.41.6
  10.  
  11.    Public Function HostName_To_IP(ByVal HotsName As String) As String
  12.        Return System.Net.Dns.GetHostEntry(HotsName).AddressList(1).ToString()
  13.    End Function
  14.  
  15. #End Region



Devuelve el Hostname de una IP

Código
  1. #Region " IP To HostName "
  2.  
  3.    ' [ IP To HostName Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    '
  9.    ' MsgBox(IP_To_HostName("173.194.41.6")) ' Result: mad01s14-in-f6.1e100.net
  10.  
  11.    Public Function IP_To_HostName(ByVal IP As String) As String
  12.        Return system.net.Dns.GetHostEntry(IP).HostName.ToString
  13.    End Function
  14.  
  15. #End Region





Valida si un nombre de archivo o ruta contiene caracteres no permitidos por Windows

(Este snippet lo posteé hace tiempo pero tenía varios fallos, los he corregido.)

Código
  1. #Region " Validate Windows FileName "
  2.  
  3.    ' [ Validate Windows FileName Function ]
  4.    '
  5.    ' Examples :
  6.    ' MsgBox(Validate_Windows_FileName("C:\Test.txt"))  ' Result: True
  7.    ' MsgBox(Validate_Windows_FileName("C:\Te|st.txt")) ' Result: False
  8.  
  9.    Private Function Validate_Windows_FileName(ByRef FileName As String)
  10.        Dim Directory As String = Nothing
  11.        Dim File As String = Nothing
  12.  
  13.        Try
  14.            Directory = FileName.Substring(0, FileName.LastIndexOf("\")) & "\"
  15.            File = FileName.Split("\").Last
  16.        Catch
  17.            If Directory Is Nothing Then File = FileName
  18.        End Try
  19.  
  20.        If Directory Is Nothing AndAlso File Is Nothing Then Return False
  21.  
  22.        If Not Directory Is Nothing Then
  23.            For Each InvalidCharacter As Char In IO.Path.GetInvalidPathChars
  24.                If Directory.Contains(InvalidCharacter) Then
  25.                    ' MsgBox(InvalidCharacter)
  26.                    Return False
  27.                End If
  28.            Next
  29.        End If
  30.  
  31.        If Not File Is Nothing Then
  32.            For Each InvalidCharacter As Char In IO.Path.GetInvalidFileNameChars
  33.                If File.Contains(InvalidCharacter) Then
  34.                    ' MsgBox(InvalidCharacter)
  35.                    Return False
  36.                End If
  37.            Next
  38.        End If
  39.  
  40.        Return True ' FileName is valid
  41.    End Function
  42.  
  43. #End Region
« Última modificación: 11 Mayo 2013, 11:56 am por EleKtro H@cker » En línea



Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.866



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #117 en: 13 Mayo 2013, 07:40 am »

Una class para combinar ejecutable de .NET con dependencias (dll's) en tiempo de ejecución...

Se necesita la aplicación IlMerge

Código
  1. #Region " IlMerge "
  2.  
  3. ' [ IlMerge Functions ]
  4. '
  5. ' // By Elektro H@cker
  6. '
  7. ' Instructions:
  8. ' 1. Add the "IlMerge.exe" to the project
  9. ' 2. Add the "IlMerge" Class to the project
  10. '
  11. ' Examples:
  12. ' IlMerge.Merge({"C:\Application.exe", "C:\Dependency.dll"}, "C:\Merged.exe")
  13. ' MsgBox(IlMerge.Merge({"C:\Application.exe", "C:\Dependency.dll"}, "C:\Merged.exe"))
  14.  
  15.  
  16. #Region " IlMerge class "
  17.  
  18. Public Class IlMerge
  19.  
  20.    ''' <summary>
  21.    ''' Set the location of IlMerge executable [Default: ".\IlMerge.exe"].
  22.    ''' </summary>
  23.    Public Shared IlMerge_Location As String = ".\IlMerge.exe"
  24.    ''' <summary>
  25.    ''' Set the location of IlMerge log file [Default: ".\IlMerge.log"].
  26.    ''' </summary>
  27.    Public Shared IlMerge_Log_Location As String = IlMerge_Location.Substring(0, IlMerge_Location.Length - 4) & ".log"
  28.  
  29.    ''' <summary>
  30.    ''' Merge
  31.    ''' </summary>
  32.    Public Shared Function Merge(ByVal InputFiles As String(), ByVal OutputFile As String) As Boolean
  33.  
  34.        Dim FilesString As String = Nothing
  35.        For Each File In InputFiles : FilesString += """" & File & """" & " " : Next
  36.  
  37.        Try : IO.File.Delete(IlMerge_Log_Location) : Catch : End Try ' Deletes old log if exist
  38.  
  39.        Try
  40.            Dim ResHacker As New Process()
  41.            Dim ResHacker_Info As New ProcessStartInfo()
  42.  
  43.            ResHacker_Info.FileName = IlMerge_Location
  44.            ResHacker_Info.Arguments = "/ndebug /log:" & """" & IlMerge_Log_Location & """" & " /out:" & """" & OutputFile & """" & " " & FilesString
  45.            ResHacker_Info.UseShellExecute = False
  46.            ResHacker.StartInfo = ResHacker_Info
  47.            ResHacker.Start()
  48.            ResHacker.WaitForExit()
  49.  
  50.            Try : IO.File.Delete(OutputFile.Substring(0, OutputFile.Length - 4) & ".pdb") : Catch : End Try ' Deletes Debug Generated File
  51.            Return Check_Last_Error()
  52.  
  53.        Catch ex As Exception
  54.            MsgBox(ex.Message)
  55.            Return False
  56.        End Try
  57.  
  58.    End Function
  59.  
  60.    ''' <summary>
  61.    ''' Return the last operation error if any [False = ERROR, True = Ok].
  62.    ''' </summary>
  63.    Private Shared Function Check_Last_Error()
  64.  
  65.        Try
  66.            Dim Line As String = Nothing
  67.            Dim Text As IO.StreamReader = IO.File.OpenText(IlMerge_Log_Location)
  68.  
  69.            Do Until Text.EndOfStream
  70.                Line = Text.ReadLine()
  71.                If Line.ToString.StartsWith("An exception occurred") Then
  72.                    Process.Start(IlMerge_Log_Location)
  73.                    Return False
  74.                End If
  75.            Loop
  76.  
  77.            Text.Close()
  78.            Text.Dispose()
  79.            Return True
  80.        Catch ex As Exception
  81.            MsgBox(ex.Message)
  82.            Return False
  83.        End Try
  84.  
  85.    End Function
  86.  
  87. End Class
  88.  
  89. #End Region
  90.  
  91. #End Region
En línea



Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.866



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #118 en: 17 Mayo 2013, 15:23 pm »

Comprobar si una imagen contiene cierto color.

Esta función me ha costado la vida conseguirla, ya la pueden guardar bien xD...


Código
  1.   Private Function Image_Has_Color(ByVal image As Image, ByVal color As Color) As Boolean
  2.  
  3.        Using Bitmap_Image = New Bitmap(image.Width, image.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
  4.  
  5.            Graphics.FromImage(Bitmap_Image).DrawImage(image, 0, 0)
  6.  
  7.            Dim Bitmap_Data = Bitmap_Image.LockBits(New Rectangle(0, 0, Bitmap_Image.Width, Bitmap_Image.Height), System.Drawing.Imaging.ImageLockMode.[ReadOnly], Bitmap_Image.PixelFormat)
  8.            Dim Bitmap_Pointer As IntPtr = Bitmap_Data.Scan0
  9.  
  10.            Dim Pixel_Color As Int32
  11.            Dim Result As Boolean = False
  12.  
  13.            For i = 0 To Bitmap_Data.Height * Bitmap_Data.Width - 1
  14.  
  15.                Pixel_Color = System.Runtime.InteropServices.Marshal.ReadInt32(Bitmap_Pointer, i * 4)
  16.  
  17.                If (Pixel_Color And &HFF000000) <> 0 AndAlso (Pixel_Color And &HFFFFFF) = (color.ToArgb() And &HFFFFFF) Then
  18.                    Result = True
  19.                    Exit For
  20.                End If
  21.  
  22.            Next
  23.  
  24.            Bitmap_Image.UnlockBits(Bitmap_Data)
  25.            Return Result
  26.  
  27.        End Using
  28.  
  29.    End Function

Ejemplo:
Código
  1.    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  2.        MsgBox(Image_Has_Color(System.Drawing.Image.FromFile("C:\imagen.jpg"), Color.FromArgb(240, 240, 240)))
  3.    End Sub
En línea



Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.866



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #119 en: 17 Mayo 2013, 15:48 pm »

Devuelve una lista con todos los valores de una enumeración

Código
  1.    #Region " Get Enum Values "
  2.  
  3.       ' [ Get Enum Values Function ]
  4.       '
  5.       ' // By Elektro H@cker
  6.       '
  7.       ' Examples :
  8.       ' For Each value In Get_Enum_Values(Of KnownColor)() : MsgBox(value) : Next
  9.  
  10.    Private Function Get_Enum_Values(Of T)() As List(Of String)
  11.        Dim ValueList As New List(Of String)
  12.        For Each value In System.[Enum].GetValues(GetType(T)) : ValueList.Add(value.ToString) : Next
  13.        Return ValueList
  14.    End Function
  15.  
  16.    #End Region





Como hacer un Loop sobre todos los colores conocidos:

Código
  1.        For Each col In System.[Enum].GetValues(GetType(KnownColor))
  2.            Dim mycolor As Color = Color.FromKnownColor(col)
  3.            MsgBox(mycolor.ToString)
  4.            MsgBox(mycolor.R)
  5.            MsgBox(mycolor.G)
  6.            MsgBox(mycolor.B)
  7.        Next
« Última modificación: 17 Mayo 2013, 15:51 pm 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 20 21 22 23 24 25 26 27 ... 60 Ir Arriba Respuesta Imprimir 

Ir a:  

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