Menú

Mostrar Mensajes

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

Mostrar Mensajes Menú

Mensajes - Eleкtro

#7251
No le encuentro sentido a que quieras investigar la manera de llevar a cabo esta tarea en un lenguaje inferior al que estabas usando.

EDITO: Acabo de darme cuenta que, en el otro post, dices que la API no te da los resultados esperados en windows 8, bueno, esto la verdad es que en VBNET sería mucho más simple que usando API's, en 4 líneas de código, pero usando VB6 podrías probar a utilizar el método NetUserGetInfo de la WinAPI donde en el miembro usri2_priv de la estructura USER_INFO_2 se supone que podrías verificar si es admin o no.

Aquí tienes unas pistas de como usarlo: http://www.vbforums.com/showthread.php?280359-check-if-user-is-admin




De todas formas, sabiendo que el inicio de la SID del grupo de Administradores (como los demás grupos de privilegios Elevados, etc) es un identificador constante, creo que sería suficiente con listar los grupos a los que pertenece el usuario actual y buscar el SID correspondiente al grupo.

Así pues, este es mi enfoque de como hacerlo de una manera sencilla en VBS (como querías):
Código (vb) [Seleccionar]
' Check if User is an Administrator
' ( By Elektro )

Const AdminSID= "S-1-5-32-544"

UserName = CreateObject("WScript.Network").UserName
IsAdmin  = Not CBool(CreateObject("WScript.Shell"). _
      Run("%ComSpec% /C WhoAmI.exe /All | Find  """ & AdminSID & """", 0, True))

MsgBox "'" &     UserName    & "'" &          _
      " " & "Is Administrator?: " & IsAdmin, _
      64, "Administrator check"

Wscript.Quit(CInt(Not IsAdmin)) ' 0 = Success (IsAdmin), -1 = Failed (IsNotAdmin)


Saludos!
#7252
Si quieres una respuesta rápida entonces te digo que puedes eliminar TODAS las carpetas menos la que se llama 'Microsoft', ya que es la única carpeta crítica que se instala por defecto con el SO, aunque dentro de esa carpeta, puede haber más basura innecesaria.

Pero esto no es tan simple como decirte "Puedes borrar esa carpeta" o "No borres esa", en cada una de esas carpetas (menos 'TEMP') se guardan las configuraciones y en general otros datos de cada programa que has instalado, tienes carpetas que hacen referencia a programas instalados de Adobe, AVG, Panda, Nero, Google, WinRAR, etc... así que la eliminación de cada carpeta es algo que debe quedar a tu criterio ...no al nuestro.
Si has desinstalado esos programas pues no hay problema en que elimines esas carpetas, ya que sólamente son residuos que quedan a pesar de haber desinstalado el software.

De todas formas, lo más sensato es que utilices CCleaner...

Saludos.
#7253
Windows / Re: Error archivos .exe
23 Febrero 2014, 13:57 PM
Hola

1. ¿Has probado a restaurar la asociación de archivos .exe de forma completa? (En la url que has citado, la solución que proporciona Microsoft es penosa)
http://www.sevenforums.com/tutorials/19449-default-file-type-associations-restore.html
(Si usas otra versión de Windows, asegúrate de restaurar la asociación para la versión específica para tu SO)

2. ¿Has realizado una búsqueda de datos (no valores ni claves) en el registro de Windows usando como patrón de búsqueda el nombre del instalador, a ver si encuentras algo sospechoso?
(Ejemplo de algo sospechoso: @Command = "explorer.exe "CeltXSetup.exe"")

Saludos
#7254
Windows / Re: ayuda con windows...
23 Febrero 2014, 13:38 PM
Opino lo mismo que @Dato000,
trastear con el bootloader sólamente para probar un SO (o en este caso decidir si te gusta un Windows) se podría considerar algo prehistórico en los tiempos que corren (y peligroso para las personas que no se manejan bien con los dual-boots), teniendo virtualizadores de sistemas operativos como VirtualBox, lo pruebas y luego si decides que te gusta pues te lo instalas en tu PC para comprobar los demás aspectos como la compatibilidad de Hardware, aunque si lo único que te preocupa es la compatibilidad con tu Bios, según Microsoft se puede instalar en una Bios MBR, EFI o UEFI:

http://windows.microsoft.com/en-us/windows-8/system-requirements
http://technet.microsoft.com/en-us/windows/jj721676.aspx

Saludos.
#7255
@CrashSomeMore

Thankyou for comment.

It's possible that maybe (or maybe not) the reason why you've encountered bugs/crashes could be that I only did the script testing it on a Win7 x64 ISO build in Spanish lang and maybe some critical English directories are removed by the Script (I don't remember it now).

Sorry mate but since I've migrated to Win 8.1 I've never performed updates on the Shrinker-script for Win 7.

PS: If you're interested into the Shrinker for Win8.1 just reply to this message to provide it for you, but instead working on a installed Windows now the script works on a mounted directory of the ISO, to shrink it and burn it, it shrinks more than 1 GB on the original ISO (that means a lot of GB's on the installation) and all works as expected, even NetFX 3.5 and Win updates. :)

Regards.
#7256
(Porfavor la próxima vez no hagas doble post, utiliza el botón MODIFICAR)




Tienes toda la razón del mundo, es un coñazo usar el FolderBrowserDialog, yo lo veo como un diálogo obsoleto y dificil de manejar, con muy poco rendimiento, ya que con el diálogo de carpetas de Windows puedes acceder a una ubicación en 5 segundos escribiendo la ubicación o usando las ubicaciones favoritas, mientras que con el FolderBrowserDialog pierdes mucho más tiempo expandiendo carpetas ...una por una.
Es una completa basura.

La solución de terceros que has mostrado ....bueno, es una solución y es customizable, pero no tiene ventajas sobre la navegación de directorios, debería customizarse en más aspectos la Class ...cosa que resultaría laboriosa. Así que sin ánimo de ofender al autor del código, me parece algo muy cutre heredar un 'CommonDialog' para hacer sólamente eso.

Te propongo algo más eficiente, usando la librería Windows API Code Pack que provee Microsoft.

Te muestro un ejemplo de uso:

Código (vbnet) [Seleccionar]
   ' WindowsAPICodePack 'CommonOpenFileDialog' Example.
   ' ( By Elektro )
   '
   ' Instructions:
   ' 1. Reference "Microsoft.WindowsAPICodePack.dll" and "Microsoft.WindowsAPICodePack.Shell.dll".

   Imports Microsoft.WindowsAPICodePack.Dialogs
   Imports Microsoft.WindowsAPICodePack.Shell

   ''' <summary>
   ''' The WindowsAPICodePack 'CommonOpenFileDialog' instance.
   ''' </summary>
   Private WithEvents FolderPicker As New CommonOpenFileDialog With
       {
           .Title = "Folder Picker Test",
           .DefaultDirectory = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}",
           .InitialDirectory = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}",
           .DefaultFileName = "C:\",
           .IsFolderPicker = True,
           .Multiselect = False,
           .ShowPlacesList = True,
           .ShowHiddenItems = True,
           .EnsurePathExists = True,
           .RestoreDirectory = False,
           .NavigateToShortcut = True,
           .AllowNonFileSystemItems = True,
           .AddToMostRecentlyUsedList = True
       }

   ''' <summary>
   ''' Handles the Click event of the Button1 control.
   ''' </summary>
   ''' <param name="sender">The source of the event.</param>
   ''' <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
   Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

       ' If folder is picked then...
       If FolderPicker.ShowDialog() = CommonFileDialogResult.Ok Then

           Dim SelectedFolder As ShellObject = FolderPicker.FileAsShellObject
           MsgBox(SelectedFolder.GetDisplayName(DisplayNameType.FileSystemPath))

       End If

       ' FolderPicker.Dispose()

   End Sub

   ''' <summary>
   ''' Handles the FolderChanging event of the FolderPicker control.
   ''' </summary>
   ''' <param name="sender">The source of the event.</param>
   ''' <param name="e">The <see cref="Microsoft.WindowsAPICodePack.Dialogs.CommonFileDialogFolderChangeEventArgs"/> instance containing the event data.</param>
   Private Sub FolderPicker_FolderChanging(sender As Object, e As CommonFileDialogFolderChangeEventArgs) _
   Handles FolderPicker.FolderChanging

       ' Restrict the navigation on specific folders.
       Select Case True

           Case e.Folder = Environment.GetFolderPath(Environment.SpecialFolder.Windows)
               '  Restricts the navigation to 'Windows' directory.
               e.Cancel = True

           Case e.Folder.Equals("C:\Juegos", StringComparison.CurrentCultureIgnoreCase)
               ' Restricts the navigation to 'C:\Juegos' directory.
               e.Cancel = True

           Case e.Folder.Split("\").Last.Equals("Administrador", StringComparison.CurrentCultureIgnoreCase)
               ' Restricts the navigation to any directory name ending in "Administrador" keyword.
               e.Cancel = True

           Case Else
               ' Allow navigation on that directory.
               e.Cancel = False

       End Select

   End Sub


PD: Y si no quieres depender de librerías siempre puedes sacar la parte importante del código fuente que va incluido.
PD: Además, ese kit de librerías en el futuro te proporcionarían ventajas y comodidades para usar otros tipos de controles y classes muy interesantes.

O también puedes usar la librería Ooki Dialogs, que son diálogos basados en Windows VISTA y es la librería que yo usaba como reemplazamiento del 'FolderBrowserDialog', antes de conocer la existencia de 'WindowsAPICodePack'.

Un mini ejemplo de uso:

Código (vbnet) [Seleccionar]
 Dim FolderPicker As New Ookii.Dialogs.VistaFolderBrowserDialog
 FolderPicker.ShowNewFolderButton = True

 If FolderPicker.ShowDialog.ToString() = "OK" Then
     msgbox(FolderPicker.SelectedPath)
 End If

 ' FolderPicker.Dispose()


Saludos.
#7257
Un helper class para el método SendInput de la WinAPI

Cita de: http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspxSynthesizes keystrokes, mouse motions, and button clicks.

PD: El método 'sendkeys' no es 100% perfecto con caracteres especiales como la 'Ñ', pero tampoco lo voy a elaborar más por el momento,ya que es un coñazo por los distintos layouts del teclado.

Código (vbnet) [Seleccionar]
' ***********************************************************************
' Author   : Elektro
' Modified : 02-21-2014
' ***********************************************************************
' <copyright file="SendInputs.vb" company="Elektro Studios">
'     Copyright (c) Elektro Studios. All rights reserved.
' </copyright>
' ***********************************************************************

#Region " Usage Examples "

'Private Sub Test() Handles Button1.Click

' AppActivate(Process.GetProcessesByName("notepad").First.Id)

' Dim c As Char = Convert.ToChar(Keys.Oemtilde) ' Ñ
' Dim Result As Integer = SendInputs.SendKey(Convert.ToChar(c.ToString.ToLower))
' MessageBox.Show(String.Format("Successfull events: {0}", CStr(Result)))

' SendInputs.SendKey(Keys.Enter)
' SendInputs.SendKey(Convert.ToChar(Keys.Back))
' SendInputs.SendKeys("Hello World", True)
' SendInputs.SendKey(Convert.ToChar(Keys.D0))
' SendInputs.SendKeys(Keys.Insert, BlockInput:=True)

' SendInputs.MouseClick(SendInputs.MouseButton.RightPress, False)
' SendInputs.MouseMove(5, -5)
' SendInputs.MousePosition(New Point(100, 500))

'End Sub

#End Region

#Region " Imports "

Imports System.Runtime.InteropServices
Imports System.ComponentModel

#End Region

''' <summary>
''' Synthesizes keystrokes, mouse motions, and button clicks.
''' </summary>
Public Class SendInputs

#Region " P/Invoke "

   Friend Class NativeMethods

#Region " Methods "

       ''' <summary>
       ''' Blocks keyboard and mouse input events from reaching applications.
       ''' For more info see here:
       ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ms646290%28v=vs.85%29.aspx
       ''' </summary>
       ''' <param name="fBlockIt">
       ''' The function's purpose.
       ''' If this parameter is 'TRUE', keyboard and mouse input events are blocked.
       ''' If this parameter is 'FALSE', keyboard and mouse events are unblocked.
       ''' </param>
       ''' <returns>
       ''' If the function succeeds, the return value is nonzero.
       ''' If input is already blocked, the return value is zero.
       ''' </returns>
       ''' <remarks>
       ''' Note that only the thread that blocked input can successfully unblock input.
       ''' </remarks>
       <DllImport("User32.dll", CharSet:=CharSet.Auto, CallingConvention:=CallingConvention.StdCall,
       SetLastError:=True)>
       Friend Shared Function BlockInput(
              ByVal fBlockIt As Boolean
       ) As Integer
       End Function

       ''' <summary>
       ''' Synthesizes keystrokes, mouse motions, and button clicks.
       ''' For more info see here:
       ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx
       ''' </summary>
       ''' <param name="nInputs">
       ''' Indicates the number of structures in the pInputs array.
       ''' </param>
       ''' <param name="pInputs">
       ''' Indicates an Array of 'INPUT' structures.
       ''' Each structure represents an event to be inserted into the keyboard or mouse input stream.
       ''' </param>
       ''' <param name="cbSize">
       ''' The size, in bytes, of an 'INPUT' structure.
       ''' If 'cbSize' is not the size of an 'INPUT' structure, the function fails.
       ''' </param>
       ''' <returns>
       ''' The function returns the number of events that it successfully
       ''' inserted into the keyboard or mouse input stream.
       ''' If the function returns zero, the input was already blocked by another thread.
       ''' </returns>
       <DllImport("user32.dll", SetLastError:=True)>
       Friend Shared Function SendInput(
              ByVal nInputs As Integer,
              <MarshalAs(UnmanagedType.LPArray), [In]> ByVal pInputs As INPUT(),
              ByVal cbSize As Integer
       ) As Integer
       End Function

#End Region

#Region " Enumerations "

       ''' <summary>
       ''' VirtualKey codes.
       ''' </summary>
       Friend Enum VirtualKeys As Short

           ''' <summary>
           ''' The Shift key.
           ''' VK_SHIFT
           ''' </summary>
           SHIFT = &H10S

           ''' <summary>
           ''' The DEL key.
           ''' VK_DELETE
           ''' </summary>
           DELETE = 46S

           ''' <summary>
           ''' The ENTER key.
           ''' VK_RETURN
           ''' </summary>
           [RETURN] = 13S

       End Enum

       ''' <summary>
       ''' The type of the input event.
       ''' For more info see here:
       ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ms646270%28v=vs.85%29.aspx
       ''' </summary>
       <Description("Enumeration used for 'type' parameter of 'INPUT' structure")>
       Friend Enum InputType As Integer

           ''' <summary>
           ''' The event is a mouse event.
           ''' Use the mi structure of the union.
           ''' </summary>
           Mouse = 0

           ''' <summary>
           ''' The event is a keyboard event.
           ''' Use the ki structure of the union.
           ''' </summary>
           Keyboard = 1

           ''' <summary>
           ''' The event is a hardware event.
           ''' Use the hi structure of the union.
           ''' </summary>
           Hardware = 2

       End Enum

       ''' <summary>
       ''' Specifies various aspects of a keystroke.
       ''' This member can be certain combinations of the following values.
       ''' For more info see here:
       ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ms646271%28v=vs.85%29.aspx
       ''' </summary>
       <Description("Enumeration used for 'dwFlags' parameter of 'KeyboardInput' structure")>
       <Flags>
       Friend Enum KeyboardInput_Flags As Integer

           ''' <summary>
           ''' If specified, the scan code was preceded by a prefix byte that has the value '0xE0' (224).
           ''' </summary>
           ExtendedKey = &H1

           ''' <summary>
           ''' If specified, the key is being pressed.
           ''' </summary>
           KeyDown = &H0

           ''' <summary>
           ''' If specified, the key is being released.
           ''' If not specified, the key is being pressed.
           ''' </summary>
           KeyUp = &H2

           ''' <summary>
           ''' If specified, 'wScan' identifies the key and 'wVk' is ignored.
           ''' </summary>
           ScanCode = &H8

           ''' <summary>
           ''' If specified, the system synthesizes a 'VK_PACKET' keystroke.
           ''' The 'wVk' parameter must be '0'.
           ''' This flag can only be combined with the 'KEYEVENTF_KEYUP' flag.
           ''' </summary>
           Unicode = &H4

       End Enum

       ''' <summary>
       ''' A set of bit flags that specify various aspects of mouse motion and button clicks.
       ''' The bits in this member can be any reasonable combination of the following values.
       ''' For more info see here:
       ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ms646273%28v=vs.85%29.aspx
       ''' </summary>
       <Description("Enumeration used for 'dwFlags' parameter of 'MouseInput' structure")>
       <Flags>
       Friend Enum MouseInput_Flags As Integer

           ''' <summary>
           ''' The 'dx' and 'dy' members contain normalized absolute coordinates.
           ''' If the flag is not set, 'dx' and 'dy' contain relative data
           ''' (the change in position since the last reported position).
           ''' This flag can be set, or not set,
           ''' regardless of what kind of mouse or other pointing device, if any, is connected to the system.
           ''' </summary>
           Absolute = &H8000I

           ''' <summary>
           ''' Movement occurred.
           ''' </summary>
           Move = &H1I

           ''' <summary>
           ''' The 'WM_MOUSEMOVE' messages will not be coalesced.
           ''' The default behavior is to coalesce 'WM_MOUSEMOVE' messages.
           ''' </summary>
           Move_NoCoalesce = &H2000I

           ''' <summary>
           ''' The left button was pressed.
           ''' </summary>
           LeftDown = &H2I

           ''' <summary>
           ''' The left button was released.
           ''' </summary>
           LeftUp = &H4I

           ''' <summary>
           ''' The right button was pressed.
           ''' </summary>
           RightDown = &H8I

           ''' <summary>
           ''' The right button was released.
           ''' </summary>
           RightUp = &H10I

           ''' <summary>
           ''' The middle button was pressed.
           ''' </summary>
           MiddleDown = &H20I

           ''' <summary>
           ''' The middle button was released.
           ''' </summary>
           MiddleUp = &H40I

           ''' <summary>
           ''' Maps coordinates to the entire desktop.
           ''' Must be used in combination with 'Absolute'.
           ''' </summary>
           VirtualDesk = &H4000I

           ''' <summary>
           ''' The wheel was moved, if the mouse has a wheel.
           ''' The amount of movement is specified in 'mouseData'.
           ''' </summary>
           Wheel = &H800I

           ''' <summary>
           ''' The wheel was moved horizontally, if the mouse has a wheel.
           ''' The amount of movement is specified in 'mouseData'.
           ''' </summary>
           HWheel = &H1000I

           ''' <summary>
           ''' An X button was pressed.
           ''' </summary>
           XDown = &H80I

           ''' <summary>
           ''' An X button was released.
           ''' </summary>
           XUp = &H100I

       End Enum

#End Region

#Region " Structures "

       ''' <summary>
       ''' Used by 'SendInput' function
       ''' to store information for synthesizing input events such as keystrokes, mouse movement, and mouse clicks.
       ''' For more info see here:
       ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ms646270%28v=vs.85%29.aspx
       ''' </summary>
       <Description("Structure used for 'INPUT' parameter of 'SendInput' API method")>
       <StructLayout(LayoutKind.Explicit)>
       Friend Structure Input

           ' ******
           '  NOTE
           ' ******
           ' Field offset for 32 bit machine: 4
           ' Field offset for 64 bit machine: 8

           ''' <summary>
           ''' The type of the input event.
           ''' </summary>
           <FieldOffset(0)>
           Public type As InputType

           ''' <summary>
           ''' The information about a simulated mouse event.
           ''' </summary>
           <FieldOffset(8)>
           Public mi As MouseInput

           ''' <summary>
           ''' The information about a simulated keyboard event.
           ''' </summary>
           <FieldOffset(8)>
           Public ki As KeyboardInput

           ''' <summary>
           ''' The information about a simulated hardware event.
           ''' </summary>
           <FieldOffset(8)>
           Public hi As HardwareInput

       End Structure

       ''' <summary>
       ''' Contains information about a simulated mouse event.
       ''' For more info see here:
       ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ms646273%28v=vs.85%29.aspx
       ''' </summary>
       <Description("Structure used for 'mi' parameter of 'INPUT' structure")>
       Friend Structure MouseInput

           ''' <summary>
           ''' The absolute position of the mouse,
           ''' or the amount of motion since the last mouse event was generated,
           ''' depending on the value of the dwFlags member.
           ''' Absolute data is specified as the 'x' coordinate of the mouse;
           ''' relative data is specified as the number of pixels moved.
           ''' </summary>
           Public dx As Integer

           ''' <summary>
           ''' The absolute position of the mouse,
           ''' or the amount of motion since the last mouse event was generated,
           ''' depending on the value of the dwFlags member.
           ''' Absolute data is specified as the 'y' coordinate of the mouse;
           ''' relative data is specified as the number of pixels moved.
           ''' </summary>
           Public dy As Integer

           ''' <summary>
           ''' If 'dwFlags' contains 'MOUSEEVENTF_WHEEL',
           ''' then 'mouseData' specifies the amount of wheel movement.
           ''' A positive value indicates that the wheel was rotated forward, away from the user;
           ''' a negative value indicates that the wheel was rotated backward, toward the user.
           ''' One wheel click is defined as 'WHEEL_DELTA', which is '120'.
           '''
           ''' If 'dwFlags' does not contain 'MOUSEEVENTF_WHEEL', 'MOUSEEVENTF_XDOWN', or 'MOUSEEVENTF_XUP',
           ''' then mouseData should be '0'.
           ''' </summary>
           Public mouseData As Integer

           ''' <summary>
           ''' A set of bit flags that specify various aspects of mouse motion and button clicks.
           ''' The bits in this member can be any reasonable combination of the following values.
           ''' The bit flags that specify mouse button status are set to indicate changes in status,
           ''' not ongoing conditions.
           ''' For example, if the left mouse button is pressed and held down,
           ''' 'MOUSEEVENTF_LEFTDOWN' is set when the left button is first pressed,
           ''' but not for subsequent motions.
           ''' Similarly, 'MOUSEEVENTF_LEFTUP' is set only when the button is first released.
           '''
           ''' You cannot specify both the 'MOUSEEVENTF_WHEE'L flag
           ''' and either 'MOUSEEVENTF_XDOWN' or 'MOUSEEVENTF_XUP' flags simultaneously in the 'dwFlags' parameter,
           ''' because they both require use of the 'mouseData' field.
           ''' </summary>
           Public dwFlags As MouseInput_Flags

           ''' <summary>
           ''' The time stamp for the event, in milliseconds.
           ''' If this parameter is '0', the system will provide its own time stamp.
           ''' </summary>
           Public time As Integer

           ''' <summary>
           ''' An additional value associated with the mouse event.
           ''' An application calls 'GetMessageExtraInfo' to obtain this extra information.
           ''' </summary>
           Public dwExtraInfo As IntPtr

       End Structure

       ''' <summary>
       ''' Contains information about a simulated keyboard event.
       ''' For more info see here:
       ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ms646271%28v=vs.85%29.aspx
       ''' </summary>
       <Description("Structure used for 'ki' parameter of 'INPUT' structure")>
       Friend Structure KeyboardInput

           ''' <summary>
           ''' A virtual-key code.
           ''' The code must be a value in the range '1' to '254'.
           ''' If the 'dwFlags' member specifies 'KEYEVENTF_UNICODE', wVk must be '0'.
           ''' </summary>
           Public wVk As Short

           ''' <summary>
           ''' A hardware scan code for the key.
           ''' If 'dwFlags' specifies 'KEYEVENTF_UNICODE',
           ''' 'wScan' specifies a Unicode character which is to be sent to the foreground application.
           ''' </summary>
           Public wScan As Short

           ''' <summary>
           ''' Specifies various aspects of a keystroke.
           ''' </summary>
           Public dwFlags As KeyboardInput_Flags

           ''' <summary>
           ''' The time stamp for the event, in milliseconds.
           ''' If this parameter is '0', the system will provide its own time stamp.
           ''' </summary>
           Public time As Integer

           ''' <summary>
           ''' An additional value associated with the keystroke.
           ''' Use the 'GetMessageExtraInfo' function to obtain this information.
           ''' </summary>
           Public dwExtraInfo As IntPtr

       End Structure

       ''' <summary>
       ''' Contains information about a simulated message generated by an input device other than a keyboard or mouse.
       ''' For more info see here:
       ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ms646269%28v=vs.85%29.aspx
       ''' </summary>
       <Description("Structure used for 'hi' parameter of 'INPUT' structure")>
       Friend Structure HardwareInput

           ''' <summary>
           ''' The message generated by the input hardware.
           ''' </summary>
           Public uMsg As Integer

           ''' <summary>
           ''' The low-order word of the lParam parameter for uMsg.
           ''' </summary>
           Public wParamL As Short

           ''' <summary>
           ''' The high-order word of the lParam parameter for uMsg.
           ''' </summary>
           Public wParamH As Short

       End Structure

#End Region

   End Class

#End Region

#Region " Enumerations "

   ''' <summary>
   ''' Indicates a mouse button.
   ''' </summary>
   <Description("Enumeration used for 'MouseAction' parameter of 'MouseClick' function.")>
   Public Enum MouseButton As Integer

       ''' <summary>
       ''' Hold the left button.
       ''' </summary>
       LeftDown = &H2I

       ''' <summary>
       ''' Release the left button.
       ''' </summary>
       LeftUp = &H4I

       ''' <summary>
       ''' Hold the right button.
       ''' </summary>
       RightDown = &H8I

       ''' <summary>
       ''' Release the right button.
       ''' </summary>
       RightUp = &H10I

       ''' <summary>
       ''' Hold the middle button.
       ''' </summary>
       MiddleDown = &H20I

       ''' <summary>
       ''' Release the middle button.
       ''' </summary>
       MiddleUp = &H40I

       ''' <summary>
       ''' Press the left button.
       ''' ( Hold + Release )
       ''' </summary>
       LeftPress = LeftDown + LeftUp

       ''' <summary>
       ''' Press the Right button.
       ''' ( Hold + Release )
       ''' </summary>
       RightPress = RightDown + RightUp

       ''' <summary>
       ''' Press the Middle button.
       ''' ( Hold + Release )
       ''' </summary>
       MiddlePress = MiddleDown + MiddleUp

   End Enum

#End Region

#Region " Public Methods "

   ''' <summary>
   ''' Sends a keystroke.
   ''' </summary>
   ''' <param name="key">
   ''' Indicates the keystroke to simulate.
   ''' </param>
   ''' <param name="BlockInput">
   ''' If set to <c>true</c>, the keyboard and mouse are blocked until the keystroke is sent.
   ''' </param>
   ''' <returns>
   ''' The function returns the number of events that it successfully inserted into the keyboard input stream.
   ''' If the function returns zero, the input was already blocked by another thread.
   ''' </returns>
   Public Shared Function SendKey(ByVal key As Char,
                                  Optional BlockInput As Boolean = False) As Integer

       ' Block Keyboard and mouse.
       If BlockInput Then NativeMethods.BlockInput(True)

       ' The inputs structures to send.
       Dim Inputs As New List(Of NativeMethods.INPUT)

       ' The current input to add into the Inputs list.
       Dim CurrentInput As New NativeMethods.INPUT

       ' Determines whether a character is an alphabetic letter.
       Dim IsAlphabetic As Boolean = Not (key.ToString.ToUpper = key.ToString.ToLower)

       ' Determines whether a character is an uppercase alphabetic letter.
       Dim IsUpperCase As Boolean =
           (key.ToString = key.ToString.ToUpper) AndAlso Not (key.ToString.ToUpper = key.ToString.ToLower)

       ' Determines whether the CapsLock key is pressed down.
       Dim CapsLockON As Boolean = My.Computer.Keyboard.CapsLock

       ' Set the passed key to upper-case.
       If IsAlphabetic AndAlso Not IsUpperCase Then
           key = Convert.ToChar(key.ToString.ToUpper)
       End If

       ' If character is alphabetic and is UpperCase and CapsLock is pressed down,
       ' OrElse character is alphabetic and is not UpperCase and CapsLock is not pressed down,
       ' OrElse character is not alphabetic.
       If (IsAlphabetic AndAlso IsUpperCase AndAlso CapsLockON) _
       OrElse (IsAlphabetic AndAlso Not IsUpperCase AndAlso Not CapsLockON) _
       OrElse (Not IsAlphabetic) Then

           ' Hold the character key.
           With CurrentInput
               .type = NativeMethods.InputType.Keyboard
               .ki.wVk = Convert.ToInt16(CChar(key))
               .ki.dwFlags = NativeMethods.KeyboardInput_Flags.KeyDown
           End With : Inputs.Add(CurrentInput)

           ' Release the character key.
           With CurrentInput
               .type = NativeMethods.InputType.Keyboard
               .ki.wVk = Convert.ToInt16(CChar(key))
               .ki.dwFlags = NativeMethods.KeyboardInput_Flags.KeyUp
           End With : Inputs.Add(CurrentInput)

           ' If character is alphabetic and is UpperCase and CapsLock is not pressed down,
           ' OrElse character is alphabetic and is not UpperCase and CapsLock is pressed down.
       ElseIf (IsAlphabetic AndAlso IsUpperCase AndAlso Not CapsLockON) _
       OrElse (IsAlphabetic AndAlso Not IsUpperCase AndAlso CapsLockON) Then

           ' Hold the Shift key.
           With CurrentInput
               .type = NativeMethods.InputType.Keyboard
               .ki.wVk = NativeMethods.VirtualKeys.SHIFT
               .ki.dwFlags = NativeMethods.KeyboardInput_Flags.KeyDown
           End With : Inputs.Add(CurrentInput)

           ' Hold the character key.
           With CurrentInput
               .type = NativeMethods.InputType.Keyboard
               .ki.wVk = Convert.ToInt16(CChar(key))
               .ki.dwFlags = NativeMethods.KeyboardInput_Flags.KeyDown
           End With : Inputs.Add(CurrentInput)

           ' Release the character key.
           With CurrentInput
               .type = NativeMethods.InputType.Keyboard
               .ki.wVk = Convert.ToInt16(CChar(key))
               .ki.dwFlags = NativeMethods.KeyboardInput_Flags.KeyUp
           End With : Inputs.Add(CurrentInput)

           ' Release the Shift key.
           With CurrentInput
               .type = NativeMethods.InputType.Keyboard
               .ki.wVk = NativeMethods.VirtualKeys.SHIFT
               .ki.dwFlags = NativeMethods.KeyboardInput_Flags.KeyUp
           End With : Inputs.Add(CurrentInput)

       End If ' UpperCase And My.Computer.Keyboard.CapsLock is...

       ' Send the input key.
       Return NativeMethods.SendInput(Inputs.Count, Inputs.ToArray,
                                      Marshal.SizeOf(GetType(NativeMethods.Input)))

       ' Unblock Keyboard and mouse.
       If BlockInput Then NativeMethods.BlockInput(False)

   End Function

   ''' <summary>
   ''' Sends a keystroke.
   ''' </summary>
   ''' <param name="key">
   ''' Indicates the keystroke to simulate.
   ''' </param>
   ''' <param name="BlockInput">
   ''' If set to <c>true</c>, the keyboard and mouse are blocked until the keystroke is sent.
   ''' </param>
   ''' <returns>
   ''' The function returns the number of events that it successfully inserted into the keyboard input stream.
   ''' If the function returns zero, the input was already blocked by another thread.
   ''' </returns>
   Public Shared Function SendKey(ByVal key As Keys,
                                  Optional BlockInput As Boolean = False) As Integer

       Return SendKey(Convert.ToChar(key), BlockInput)

   End Function

   ''' <summary>
   ''' Sends a string.
   ''' </summary>
   ''' <param name="String">
   ''' Indicates the string to send.
   ''' </param>
   ''' <param name="BlockInput">
   ''' If set to <c>true</c>, the keyboard and mouse are blocked until the keystroke is sent.
   ''' </param>
   ''' <returns>
   ''' The function returns the number of events that it successfully inserted into the keyboard input stream.
   ''' If the function returns zero, the input was already blocked by another thread.
   ''' </returns>
   Public Shared Function SendKeys(ByVal [String] As String,
                                   Optional BlockInput As Boolean = False) As Integer

       Dim SuccessCount As Integer = 0

       ' Block Keyboard and mouse.
       If BlockInput Then NativeMethods.BlockInput(True)

       For Each c As Char In [String]
           SuccessCount += SendKey(c, BlockInput:=False)
       Next c

       ' Unblock Keyboard and mouse.
       If BlockInput Then NativeMethods.BlockInput(False)

       Return SuccessCount

   End Function

   ''' <summary>
   ''' Slices the mouse position.
   ''' </summary>
   ''' <param name="Offset">
   ''' Indicates the offset, in coordinates.
   ''' </param>
   ''' <param name="BlockInput">
   ''' If set to <c>true</c>, the keyboard and mouse are blocked until the mouse movement is sent.
   ''' </param>
   ''' <returns>
   ''' The function returns the number of events that it successfully inserted into the mouse input stream.
   ''' If the function returns zero, the input was already blocked by another thread.
   ''' </returns>
   Public Shared Function MouseMove(ByVal Offset As Point,
                                    Optional BlockInput As Boolean = False) As Integer

       ' Block Keyboard and mouse.
       If BlockInput Then NativeMethods.BlockInput(True)

       ' The inputs structures to send.
       Dim Inputs As New List(Of NativeMethods.Input)

       ' The current input to add into the Inputs list.
       Dim CurrentInput As New NativeMethods.Input

       ' Add a mouse movement.
       With CurrentInput
           .type = NativeMethods.InputType.Mouse
           .mi.dx = Offset.X
           .mi.dy = Offset.Y
           .mi.dwFlags = NativeMethods.MouseInput_Flags.Move
       End With : Inputs.Add(CurrentInput)

       ' Send the mouse movement.
       Return NativeMethods.SendInput(Inputs.Count, Inputs.ToArray,
                                      Marshal.SizeOf(GetType(NativeMethods.Input)))

       ' Unblock Keyboard and mouse.
       If BlockInput Then NativeMethods.BlockInput(False)

   End Function

   ''' <summary>
   ''' Slices the mouse position.
   ''' </summary>
   ''' <param name="X">
   ''' Indicates the 'X' offset.
   ''' </param>
   ''' <param name="Y">
   ''' Indicates the 'Y' offset.
   ''' </param>
   ''' <param name="BlockInput">
   ''' If set to <c>true</c>, the keyboard and mouse are blocked until the mouse movement is sent.
   ''' </param>
   ''' <returns>
   ''' The function returns the number of events that it successfully inserted into the mouse input stream.
   ''' If the function returns zero, the input was already blocked by another thread.
   ''' </returns>
   Public Shared Function MouseMove(ByVal X As Integer, ByVal Y As Integer,
                                    Optional BlockInput As Boolean = False) As Integer

       Return MouseMove(New Point(X, Y), BlockInput)

   End Function

   ''' <summary>
   ''' Moves the mouse hotspot to an absolute position, in coordinates.
   ''' </summary>
   ''' <param name="Position">
   ''' Indicates the absolute position.
   ''' </param>
   ''' <param name="BlockInput">
   ''' If set to <c>true</c>, the keyboard and mouse are blocked until the mouse movement is sent.
   ''' </param>
   ''' <returns>
   ''' The function returns the number of events that it successfully inserted into the mouse input stream.
   ''' If the function returns zero, the input was already blocked by another thread.
   ''' </returns>
   Public Shared Function MousePosition(ByVal Position As Point,
                                        Optional BlockInput As Boolean = False) As Integer

       ' Block Keyboard and mouse.
       If BlockInput Then NativeMethods.BlockInput(True)

       ' The inputs structures to send.
       Dim Inputs As New List(Of NativeMethods.Input)

       ' The current input to add into the Inputs list.
       Dim CurrentInput As New NativeMethods.Input

       ' Transform the coordinates.
       Position.X = CInt(Position.X * 65535 / (Screen.PrimaryScreen.Bounds.Width - 1))
       Position.Y = CInt(Position.Y * 65535 / (Screen.PrimaryScreen.Bounds.Height - 1))

       ' Add an absolute mouse movement.
       With CurrentInput
           .type = NativeMethods.InputType.Mouse
           .mi.dx = Position.X
           .mi.dy = Position.Y
           .mi.dwFlags = NativeMethods.MouseInput_Flags.Absolute Or NativeMethods.MouseInput_Flags.Move
           .mi.time = 0
       End With : Inputs.Add(CurrentInput)

       ' Send the absolute mouse movement.
       Return NativeMethods.SendInput(Inputs.Count, Inputs.ToArray,
                                      Marshal.SizeOf(GetType(NativeMethods.Input)))

       ' Unblock Keyboard and mouse.
       If BlockInput Then NativeMethods.BlockInput(False)

   End Function

   ''' <summary>
   ''' Moves the mouse hotspot to an absolute position, in coordinates.
   ''' </summary>
   ''' <param name="X">
   ''' Indicates the absolute 'X' coordinate.
   ''' </param>
   ''' <param name="Y">
   ''' Indicates the absolute 'Y' coordinate.
   ''' </param>
   ''' <param name="BlockInput">
   ''' If set to <c>true</c>, the keyboard and mouse are blocked until the mouse movement is sent.
   ''' </param>
   ''' <returns>
   ''' The function returns the number of events that it successfully inserted into the mouse input stream.
   ''' If the function returns zero, the input was already blocked by another thread.
   ''' </returns>
   Public Shared Function MousePosition(ByVal X As Integer, ByVal Y As Integer,
                                        Optional BlockInput As Boolean = False) As Integer

       Return MousePosition(New Point(X, Y), BlockInput)

   End Function

   ''' <summary>
   ''' Simulates a mouse click.
   ''' </summary>
   ''' <param name="MouseAction">
   ''' Indicates the mouse action to perform.
   ''' </param>
   ''' <param name="BlockInput">
   ''' If set to <c>true</c>, the keyboard and mouse are blocked until the mouse movement is sent.
   ''' </param>
   ''' <returns>
   ''' The function returns the number of events that it successfully inserted into the mouse input stream.
   ''' If the function returns zero, the input was already blocked by another thread.
   ''' </returns>
   Public Shared Function MouseClick(ByVal MouseAction As MouseButton,
                                     Optional BlockInput As Boolean = False) As Integer

       ' Block Keyboard and mouse.
       If BlockInput Then NativeMethods.BlockInput(True)

       ' The inputs structures to send.
       Dim Inputs As New List(Of NativeMethods.Input)

       ' The current input to add into the Inputs list.
       Dim CurrentInput As New NativeMethods.Input

       ' The mouse actions to perform.
       Dim MouseActions As New List(Of MouseButton)

       Select Case MouseAction

           Case MouseButton.LeftPress ' Left button, hold and release.
               MouseActions.Add(MouseButton.LeftDown)
               MouseActions.Add(MouseButton.LeftUp)

           Case MouseButton.RightPress ' Right button, hold and release.
               MouseActions.Add(MouseButton.RightDown)
               MouseActions.Add(MouseButton.RightUp)

           Case MouseButton.MiddlePress ' Middle button, hold and release.
               MouseActions.Add(MouseButton.MiddleDown)
               MouseActions.Add(MouseButton.MiddleUp)

           Case Else ' Other
               MouseActions.Add(MouseAction)

       End Select ' MouseAction

       For Each Action As MouseButton In MouseActions

           ' Add the mouse click.
           With CurrentInput
               .type = NativeMethods.InputType.Mouse
               '.mi.dx = Offset.X
               '.mi.dy = Offset.Y
               .mi.dwFlags = Action
           End With : Inputs.Add(CurrentInput)

       Next Action

       ' Send the mouse click.
       Return NativeMethods.SendInput(Inputs.Count, Inputs.ToArray,
                                      Marshal.SizeOf(GetType(NativeMethods.Input)))

       ' Unblock Keyboard and mouse.
       If BlockInput Then NativeMethods.BlockInput(False)

   End Function

#End Region

End Class
#7258
Ejemplo de como encontrar e invocar un método usando Reflection, si solo tenemos un String que contiene el nombre del método, y como pasarle un parámetro nulo al invocar.

Código (vbnet) [Seleccionar]
Imports System.Reflection
Imports System.Globalization

Public Class Form1

    Private Shadows Sub Load() Handles MyBase.Load

        Dim MethodName As String = "Test"

        Dim Method As MethodInfo =
            Me.GetType().GetMethod(MethodName, BindingFlags.IgnoreCase Or BindingFlags.Instance Or
                                               BindingFlags.Public Or BindingFlags.NonPublic)

        If Method IsNot Nothing Then
            Method.Invoke(Me, BindingFlags.IgnoreCase Or BindingFlags.Instance Or
                              BindingFlags.Public Or BindingFlags.NonPublic,
                          Nothing,
                          New Object() {"Hello World!", Type.Missing}, CultureInfo.InvariantCulture)

        Else
            MsgBox("Method not found.")

        End If

    End Sub

    Private Sub Test(ByVal StringValue As String, Optional ByVal IntValue As Integer = 1)
        MessageBox.Show(StringValue & IntValue)
    End Sub

End Class





Un DateDifference personalizado:

Código (vbnet) [Seleccionar]
    ' Date Difference
    ' ( By Elektro )
    '
    ' Usage Examples :
    '
    ' MsgBox(DateDifference(DateTime.Parse("01/03/2013 00:00:00"),
    '                       DateTime.Parse("09/04/2014 01:01:01"),
    '                       "{0} Year(s), {1} Month(s), {2} Week(s), {3} Day(s), {4} Hour(s), {5} Minute(s) and {6} Second(s)"))

    ''' <summary>
    ''' Shows the difference between two dates with custom string format.
    ''' </summary>
    ''' <param name="Date1">Indicates the first date to compare.</param>
    ''' <param name="Date2">Indicates the second date to compare.</param>
    ''' <param name="StringFormat">
    ''' Indicates the string format to display the difference, where:
    ''' {0} = Years, {1} = Months, {2} = Weeks, {3} = Days, {4} = Hours, {5} = Minutes and {6} = Seconds</param>
    ''' <returns>System.String.</returns>
    Private Function DateDifference(ByVal Date1 As DateTime,
                                    ByVal Date2 As DateTime,
                                    ByVal StringFormat As String) As String

        Dim Time As TimeSpan
        Dim YearDiff As Integer, MonthDiff As Integer, WeekDiff As Integer

        Do Until Date1 > Date2

            Date1 = Date1.AddMonths(1)
            MonthDiff += 1

            If MonthDiff = 12 Then
                YearDiff += 1
                MonthDiff = 0
            End If

        Loop

        MonthDiff -= 1
        Date1 = Date1.AddMonths(-1)
        Time = (Date2 - Date1)
        WeekDiff = (Time.Days \ 7)
        Time = (Time - TimeSpan.FromDays(WeekDiff * 7))

        Return String.Format(StringFormat, YearDiff, MonthDiff, WeekDiff, Time.Days, Time.Hours, Time.Minutes, Time.Seconds)

    End Function
#7259
A ver si dejas de duplicar posts, y empiezas por leer las normas del foro.

Saludos
#7260
Una helper class para las librerías 'SautinSoft.HtmlToRtf' y 'SautinSoft.RtfToHtml', como sus nombres indican, para convertir distintos documentos entre HTML, RTF, DOC y TXT.

La verdad es que se consiguen muy buenos resultados y tiene muchas opciones de customización, esta librería es mucho mejor que la que posteé hace unas semanas del cual también hice un ayudante.

Código (vbnet) [Seleccionar]
' ***********************************************************************
' Author   : Elektro
' Modified : 02-20-2014
' ***********************************************************************
' <copyright file="DocumentConverter.vb" company="Elektro Studios">
'     Copyright (c) Elektro Studios. All rights reserved.
' </copyright>
' ***********************************************************************

#Region " Example Usages "

' ' HTML 2 RTF
' RichTextBox1.Rtf = HTMLConverter.Html2Rtf(IO.File.ReadAllText("C:\File.htm", System.Text.Encoding.Default),
'                                           SautinSoft.HtmlToRtf.eEncoding.AutoDetect, False,
'                                           DocumentConverter.PageSize.Auto, SautinSoft.HtmlToRtf.ePageNumbers.PageNumFirst,
'                                           "Page {page} of {numpages}", SautinSoft.HtmlToRtf.eAlign.Undefined,
'                                           DocumentConverter.PageOrientation.Auto, "Header", "Footer",
'                                           SautinSoft.HtmlToRtf.eImageCompatible.WordPad)


' ' HTML 2 TXT
' RichTextBox1.Text = HTMLConverter.Html2Txt(IO.File.ReadAllText("C:\File.htm", System.Text.Encoding.Default),
'                                            SautinSoft.HtmlToRtf.eEncoding.AutoDetect, False,
'                                            DocumentConverter.PageSize.Auto, SautinSoft.HtmlToRtf.ePageNumbers.PageNumFirst,
'                                            "Page {page} of {numpages}", SautinSoft.HtmlToRtf.eAlign.Undefined,
'                                            DocumentConverter.PageOrientation.Auto, "Header", "Footer",
'                                            SautinSoft.HtmlToRtf.eImageCompatible.WordPad)


' ' HTML 2 DOC
' Dim MSDocText As String = HTMLConverter.Html2Doc(IO.File.ReadAllText("C:\File.htm", System.Text.Encoding.Default),
'                                                  SautinSoft.HtmlToRtf.eEncoding.AutoDetect, False,
'                                                  DocumentConverter.PageSize.Auto, SautinSoft.HtmlToRtf.ePageNumbers.PageNumFirst,
'                                                  "Page {page} of {numpages}", SautinSoft.HtmlToRtf.eAlign.Undefined,
'                                                  DocumentConverter.PageOrientation.Auto, "Header", "Footer",
'                                                  SautinSoft.HtmlToRtf.eImageCompatible.MSWord)
' IO.File.WriteAllText("C:\DocFile.doc", MSDocText, System.Text.Encoding.Default)


' ' TXT 2 RTF
' RichTextBox1.Rtf = DocumentConverter.Txt2Rtf("Hello World!",
'                                              SautinSoft.HtmlToRtf.eEncoding.AutoDetect, False,
'                                              DocumentConverter.PageSize.Auto, SautinSoft.HtmlToRtf.ePageNumbers.PageNumFirst,
'                                              "Page {page} of {numpages}", SautinSoft.HtmlToRtf.eAlign.Undefined,
'                                              DocumentConverter.PageOrientation.Auto, "Header", "Footer",
'                                              SautinSoft.HtmlToRtf.eImageCompatible.WordPad)


' ' TXT 2 DOC
' Dim MSDocText As String = DocumentConverter.Txt2Doc("Hello World!",
'                                                     SautinSoft.HtmlToRtf.eEncoding.AutoDetect, False,
'                                                     DocumentConverter.PageSize.Auto, SautinSoft.HtmlToRtf.ePageNumbers.PageNumFirst,
'                                                     "Page {page} of {numpages}", SautinSoft.HtmlToRtf.eAlign.Undefined,
'                                                     DocumentConverter.PageOrientation.Auto, "Header", "Footer",
'                                                     SautinSoft.HtmlToRtf.eImageCompatible.WordPad)
' IO.File.WriteAllText("C:\DocFile.doc", MSDocText, System.Text.Encoding.Default)


' ' RTF 2 HTML
' Dim HTMLString As String =
'     DocumentConverter.Rtf2Html(IO.File.ReadAllText("C:\File.rtf"),
'                                SautinSoft.RtfToHtml.eOutputFormat.XHTML_10,
'                                SautinSoft.RtfToHtml.eEncoding.UTF_8,
'                                True, "C:\")
'
' IO.File.WriteAllText("C:\File.html", HTMLString)
' Process.Start("C:\File.html")

#End Region

#Region " Imports "

Imports SautinSoft
Imports System.Reflection

#End Region

''' <summary>
''' Performs HTML document convertions to other document formats.
''' </summary>
Public Class DocumentConverter

#Region " Enumerations "

   ''' <summary>
   ''' Indicates the resulting PageSize.
   ''' </summary>
   Public Enum PageSize
       Auto
       A3
       A4
       A5
       A6
       B5Iso
       B5Jis
       B6
       Executive
       Folio
       Legal
       Letter
       Oficio2
       Statement
   End Enum

   ''' <summary>
   ''' Indicates the resulting PageOrientation.
   ''' </summary>
   Public Enum PageOrientation
       Auto
       Landscape
       Portrait
   End Enum

#End Region

#Region " Private Methods "

   ''' <summary>
   ''' Converts a document using 'SautinSoft.HtmlToRtf' library.
   ''' </summary>
   ''' <param name="Text">
   ''' Indicates the text to convert.
   ''' </param>
   ''' <param name="OutputFormat">
   ''' Indicates the output document format.
   ''' </param>
   ''' <param name="TextEncoding">
   ''' Indicates the text encoding.
   ''' </param>
   ''' <param name="PreservePageBreaks">
   ''' If set to <c>true</c> page breaks are preserved on the conversion.
   ''' </param>
   ''' <param name="PageSize">
   ''' Indicates the page size.
   ''' </param>
   ''' <param name="Pagenumbers">
   ''' Indicates the page numbers.
   ''' </param>
   ''' <param name="PagenumbersFormat">
   ''' Indicates the page numbers format.
   ''' </param>
   ''' <param name="PageAlignment">
   ''' Indicates the page alignment.
   ''' </param>
   ''' <param name="PageOrientation">
   ''' Indicates the page orientation.
   ''' </param>
   ''' <param name="PageHeader">
   ''' Indicates the page header text.
   ''' </param>
   ''' <param name="PageFooter">
   ''' Indicates the page footer text.
   ''' </param>
   ''' <param name="ImageCompatibility">
   ''' Indicates the image compatibility if the document contains images.
   ''' RichTexBox control and WordPad can't show jpeg and png images inside RTF, they can show only bitmap images.
   ''' Microsoft Word can show images in jpeg, png, etc.
   ''' If this property is set to 'eImageCompatible.WordPad' images will be stored as BMP inside RTF.
   ''' </param>
   ''' <returns>System.String.</returns>
   Private Shared Function HtmlToRtfConvert(ByVal [Text] As String,
                                            ByVal InputFormat As HtmlToRtf.eInputFormat,
                                            ByVal OutputFormat As HtmlToRtf.eOutputFormat,
                                            Optional ByVal TextEncoding As HtmlToRtf.eEncoding = HtmlToRtf.eEncoding.AutoDetect,
                                            Optional ByVal PreservePageBreaks As Boolean = False,
                                            Optional ByVal PageSize As PageSize = PageSize.Auto,
                                            Optional ByVal Pagenumbers As HtmlToRtf.ePageNumbers = HtmlToRtf.ePageNumbers.PageNumFirst,
                                            Optional ByVal PagenumbersFormat As String = "Page {page} of {numpages}",
                                            Optional ByVal PageAlignment As HtmlToRtf.eAlign = HtmlToRtf.eAlign.Undefined,
                                            Optional ByVal PageOrientation As PageOrientation = PageOrientation.Auto,
                                            Optional ByVal PageHeader As String = Nothing,
                                            Optional ByVal PageFooter As String = Nothing,
                                            Optional ByVal ImageCompatibility As HtmlToRtf.eImageCompatible = HtmlToRtf.eImageCompatible.WordPad) As String

       ' Set the PageSize.
       Dim PerformPageSize As New HtmlToRtf.CPageStyle.CPageSize()
       Dim PageSizeMethod As MethodInfo = PerformPageSize.GetType().GetMethod(PageSize.ToString())

       ' Set the PageOrientation.
       Dim PerformPageOrientation As New HtmlToRtf.CPageStyle.CPageOrientation
       Dim PageOrientationMethod As MethodInfo = PerformPageOrientation.GetType().GetMethod(PageOrientation.ToString())

       ' Call the PageSize method.
       If Not PageSizeMethod Is Nothing Then
           PageSizeMethod.Invoke(PerformPageSize, Nothing)
       Else
           Throw New Exception(String.Format("PageSize method {0} not found.", PageSize.ToString))
       End If

       ' Call the PageOrientation method.
       If Not PageOrientationMethod Is Nothing Then
           PageOrientationMethod.Invoke(PerformPageOrientation, Nothing)
       Else
           Throw New Exception(String.Format("PageOrientation method {0} not found.", PageOrientation.ToString))
       End If

       ' Instance a new document converter.
       Dim Converter As New HtmlToRtf

       ' Customize the conversion options.
       With Converter

           .Serial = "123456789012"

           .InputFormat = InputFormat
           .OutputFormat = OutputFormat
           .Encoding = TextEncoding
           .PreservePageBreaks = PreservePageBreaks
           .ImageCompatible = ImageCompatibility
           .PageAlignment = PageAlignment
           .PageNumbers = Pagenumbers
           .PageNumbersFormat = PagenumbersFormat
           .PageStyle.PageSize = PerformPageSize
           .PageStyle.PageOrientation = PerformPageOrientation
           If Not String.IsNullOrEmpty(PageHeader) Then .PageStyle.PageHeader.Text(PageHeader)
           If Not String.IsNullOrEmpty(PageFooter) Then .PageStyle.PageFooter.Text(PageFooter)

       End With

       ' Convert it.
       Return Converter.ConvertString([Text])

   End Function

   ''' <summary>
   ''' Converts a document using 'SautinSoft.RtfToHtml' library.
   ''' </summary>
   ''' <param name="Text">
   ''' Indicates the text to convert.
   ''' </param>
   ''' <param name="OutputFormat">
   ''' Indicates the output HTML format.
   ''' </param>
   ''' <param name="TextEncoding">
   ''' Indicates the text encoding.
   ''' </param>
   ''' <param name="SaveImagesToDisk">
   ''' If set to <c>true</c>, converted images are saved to a directory on hard drive.
   ''' </param>
   ''' <param name="ImageFolder">
   ''' If 'SaveImagesToDisk' parameter is set to 'True', indicates the image directory to save the images.
   ''' The directory must exist.
   ''' </param>
   ''' <returns>System.String.</returns>
   Private Shared Function RtfToHtmlConvert(ByVal [Text] As String,
                                            Optional ByVal OutputFormat As RtfToHtml.eOutputFormat = RtfToHtml.eOutputFormat.XHTML_10,
                                            Optional ByVal TextEncoding As RtfToHtml.eEncoding = RtfToHtml.eEncoding.UTF_8,
                                            Optional ByVal SaveImagesToDisk As Boolean = False,
                                            Optional ByVal ImageFolder As String = "C:\") As String


       ' Instance a new document converter.
       Dim Converter As New RtfToHtml

       ' Customize the conversion options.
       With Converter

           .Serial = "123456789012"

           .OutputFormat = OutputFormat
           .Encoding = TextEncoding
           .ImageStyle.IncludeImageInHtml = Not SaveImagesToDisk
           .ImageStyle.ImageFolder = ImageFolder ' This folder must exist to save the converted images.
           .ImageStyle.ImageSubFolder = "Pictures" ' This subfolder will be created by the component to save the images.
           .ImageStyle.ImageFileName = "picture" ' Pattern name for converted images. (Ex: 'Picture1.png')

       End With

       ' Convert it.
       Return Converter.ConvertString([Text])

   End Function

#End Region

#Region " Public Methods "

   ''' <summary>
   ''' Converts HTML text to DOC (Microsoft Word).
   ''' </summary>
   ''' <param name="HtmlText">
   ''' Indicates the HTML text to convert.
   ''' </param>
   ''' <param name="TextEncoding">
   ''' Indicates the text encoding.
   ''' </param>
   ''' <param name="PreservePageBreaks">
   ''' If set to <c>true</c> page breaks are preserved on the conversion.
   ''' </param>
   ''' <param name="PageSize">
   ''' Indicates the page size.
   ''' </param>
   ''' <param name="Pagenumbers">
   ''' Indicates the page numbers.
   ''' </param>
   ''' <param name="PagenumbersFormat">
   ''' Indicates the page numbers format.
   ''' </param>
   ''' <param name="PageAlignment">
   ''' Indicates the page alignment.
   ''' </param>
   ''' <param name="PageOrientation">
   ''' Indicates the page orientation.
   ''' </param>
   ''' <param name="PageHeader">
   ''' Indicates the page header text.
   ''' </param>
   ''' <param name="PageFooter">
   ''' Indicates the page footer text.
   ''' </param>
   ''' <param name="ImageCompatibility">
   ''' Indicates the image compatibility if the document contains images.
   ''' RichTexBox control and WordPad can't show jpeg and png images inside RTF, they can show only bitmap images.
   ''' Microsoft Word can show images in jpeg, png, etc.
   ''' If this property is set to 'eImageCompatible.WordPad' images will be stored as BMP inside RTF.
   ''' </param>
   ''' <returns>System.String.</returns>
   Public Shared Function Html2Doc(ByVal HtmlText As String,
                                   Optional ByVal TextEncoding As HtmlToRtf.eEncoding = HtmlToRtf.eEncoding.AutoDetect,
                                   Optional ByVal PreservePageBreaks As Boolean = False,
                                   Optional ByVal PageSize As PageSize = PageSize.Auto,
                                   Optional ByVal Pagenumbers As HtmlToRtf.ePageNumbers = HtmlToRtf.ePageNumbers.PageNumFirst,
                                   Optional ByVal PagenumbersFormat As String = "Page {page} of {numpages}",
                                   Optional ByVal PageAlignment As HtmlToRtf.eAlign = HtmlToRtf.eAlign.Undefined,
                                   Optional ByVal PageOrientation As PageOrientation = PageOrientation.Auto,
                                   Optional ByVal PageHeader As String = Nothing,
                                   Optional ByVal PageFooter As String = Nothing,
                                   Optional ByVal ImageCompatibility As HtmlToRtf.eImageCompatible = HtmlToRtf.eImageCompatible.WordPad
                                   ) As String

       Return HtmlToRtfConvert(HtmlText, HtmlToRtf.eInputFormat.Html, HtmlToRtf.eOutputFormat.Doc, TextEncoding,
                      PreservePageBreaks, PageSize, Pagenumbers, PagenumbersFormat,
                      PageAlignment, PageOrientation, PageHeader, PageFooter, ImageCompatibility)

   End Function

   ''' <summary>
   ''' Converts HTML text to RTF (Rich Text).
   ''' </summary>
   ''' <param name="HtmlText">
   ''' Indicates the HTML text to convert.
   ''' </param>
   ''' <param name="TextEncoding">
   ''' Indicates the text encoding.
   ''' </param>
   ''' <param name="PreservePageBreaks">
   ''' If set to <c>true</c> page breaks are preserved on the conversion.
   ''' </param>
   ''' <param name="PageSize">
   ''' Indicates the page size.
   ''' </param>
   ''' <param name="Pagenumbers">
   ''' Indicates the page numbers.
   ''' </param>
   ''' <param name="PagenumbersFormat">
   ''' Indicates the page numbers format.
   ''' </param>
   ''' <param name="PageAlignment">
   ''' Indicates the page alignment.
   ''' </param>
   ''' <param name="PageOrientation">
   ''' Indicates the page orientation.
   ''' </param>
   ''' <param name="PageHeader">
   ''' Indicates the page header text.
   ''' </param>
   ''' <param name="PageFooter">
   ''' Indicates the page footer text.
   ''' </param>
   ''' <param name="ImageCompatibility">
   ''' Indicates the image compatibility if the document contains images.
   ''' RichTexBox control and WordPad can't show jpeg and png images inside RTF, they can show only bitmap images.
   ''' Microsoft Word can show images in jpeg, png, etc.
   ''' If this property is set to 'eImageCompatible.WordPad' images will be stored as BMP inside RTF.
   ''' </param>
   ''' <returns>System.String.</returns>
   Public Shared Function Html2Rtf(ByVal HtmlText As String,
                                   Optional ByVal TextEncoding As HtmlToRtf.eEncoding = HtmlToRtf.eEncoding.AutoDetect,
                                   Optional ByVal PreservePageBreaks As Boolean = False,
                                   Optional ByVal PageSize As PageSize = PageSize.Auto,
                                   Optional ByVal Pagenumbers As HtmlToRtf.ePageNumbers = HtmlToRtf.ePageNumbers.PageNumFirst,
                                   Optional ByVal PagenumbersFormat As String = "Page {page} of {numpages}",
                                   Optional ByVal PageAlignment As HtmlToRtf.eAlign = HtmlToRtf.eAlign.Undefined,
                                   Optional ByVal PageOrientation As PageOrientation = PageOrientation.Auto,
                                   Optional ByVal PageHeader As String = Nothing,
                                   Optional ByVal PageFooter As String = Nothing,
                                   Optional ByVal ImageCompatibility As HtmlToRtf.eImageCompatible = HtmlToRtf.eImageCompatible.WordPad
                                   ) As String

       Return HtmlToRtfConvert(HtmlText, HtmlToRtf.eInputFormat.Html, HtmlToRtf.eOutputFormat.Rtf, TextEncoding,
                      PreservePageBreaks, PageSize, Pagenumbers, PagenumbersFormat,
                      PageAlignment, PageOrientation, PageHeader, PageFooter, ImageCompatibility)

   End Function

   ''' <summary>
   ''' Converts HTML text to TXT (Plain Text).
   ''' </summary>
   ''' <param name="HtmlText">
   ''' Indicates the HTML text to convert.
   ''' </param>
   ''' <param name="TextEncoding">
   ''' Indicates the text encoding.
   ''' </param>
   ''' <param name="PreservePageBreaks">
   ''' If set to <c>true</c> page breaks are preserved on the conversion.
   ''' </param>
   ''' <param name="PageSize">
   ''' Indicates the page size.
   ''' </param>
   ''' <param name="Pagenumbers">
   ''' Indicates the page numbers.
   ''' </param>
   ''' <param name="PagenumbersFormat">
   ''' Indicates the page numbers format.
   ''' </param>
   ''' <param name="PageAlignment">
   ''' Indicates the page alignment.
   ''' </param>
   ''' <param name="PageOrientation">
   ''' Indicates the page orientation.
   ''' </param>
   ''' <param name="PageHeader">
   ''' Indicates the page header text.
   ''' </param>
   ''' <param name="PageFooter">
   ''' Indicates the page footer text.
   ''' </param>
   ''' <param name="ImageCompatibility">
   ''' Indicates the image compatibility if the document contains images.
   ''' RichTexBox control and WordPad can't show jpeg and png images inside RTF, they can show only bitmap images.
   ''' Microsoft Word can show images in jpeg, png, etc.
   ''' If this property is set to 'eImageCompatible.WordPad' images will be stored as BMP inside RTF.
   ''' </param>
   ''' <returns>System.String.</returns>
   Public Shared Function Html2Txt(ByVal HtmlText As String,
                                   Optional ByVal TextEncoding As HtmlToRtf.eEncoding = HtmlToRtf.eEncoding.AutoDetect,
                                   Optional ByVal PreservePageBreaks As Boolean = False,
                                   Optional ByVal PageSize As PageSize = PageSize.Auto,
                                   Optional ByVal Pagenumbers As HtmlToRtf.ePageNumbers = HtmlToRtf.ePageNumbers.PageNumFirst,
                                   Optional ByVal PagenumbersFormat As String = "Page {page} of {numpages}",
                                   Optional ByVal PageAlignment As HtmlToRtf.eAlign = HtmlToRtf.eAlign.Undefined,
                                   Optional ByVal PageOrientation As PageOrientation = PageOrientation.Auto,
                                   Optional ByVal PageHeader As String = Nothing,
                                   Optional ByVal PageFooter As String = Nothing,
                                   Optional ByVal ImageCompatibility As HtmlToRtf.eImageCompatible = HtmlToRtf.eImageCompatible.WordPad
                                   ) As String

       Return HtmlToRtfConvert(HtmlText, HtmlToRtf.eInputFormat.Html, HtmlToRtf.eOutputFormat.TextAnsi, TextEncoding,
                      PreservePageBreaks, PageSize, Pagenumbers, PagenumbersFormat,
                      PageAlignment, PageOrientation, PageHeader, PageFooter, ImageCompatibility)

   End Function

   ''' <summary>
   ''' Converts TXT to DOC (Microsoft Word).
   ''' </summary>
   ''' <param name="Text">
   ''' Indicates the plain text to convert.
   ''' </param>
   ''' <param name="TextEncoding">
   ''' Indicates the text encoding.
   ''' </param>
   ''' <param name="PreservePageBreaks">
   ''' If set to <c>true</c> page breaks are preserved on the conversion.
   ''' </param>
   ''' <param name="PageSize">
   ''' Indicates the page size.
   ''' </param>
   ''' <param name="Pagenumbers">
   ''' Indicates the page numbers.
   ''' </param>
   ''' <param name="PagenumbersFormat">
   ''' Indicates the page numbers format.
   ''' </param>
   ''' <param name="PageAlignment">
   ''' Indicates the page alignment.
   ''' </param>
   ''' <param name="PageOrientation">
   ''' Indicates the page orientation.
   ''' </param>
   ''' <param name="PageHeader">
   ''' Indicates the page header text.
   ''' </param>
   ''' <param name="PageFooter">
   ''' Indicates the page footer text.
   ''' </param>
   ''' <param name="ImageCompatibility">
   ''' Indicates the image compatibility if the document contains images.
   ''' RichTexBox control and WordPad can't show jpeg and png images inside RTF, they can show only bitmap images.
   ''' Microsoft Word can show images in jpeg, png, etc.
   ''' If this property is set to 'eImageCompatible.WordPad' images will be stored as BMP inside RTF.
   ''' </param>
   ''' <returns>System.String.</returns>
   Public Shared Function Txt2Doc(ByVal [Text] As String,
                                  Optional ByVal TextEncoding As HtmlToRtf.eEncoding = HtmlToRtf.eEncoding.AutoDetect,
                                  Optional ByVal PreservePageBreaks As Boolean = False,
                                  Optional ByVal PageSize As PageSize = PageSize.Auto,
                                  Optional ByVal Pagenumbers As HtmlToRtf.ePageNumbers = HtmlToRtf.ePageNumbers.PageNumFirst,
                                  Optional ByVal PagenumbersFormat As String = "Page {page} of {numpages}",
                                  Optional ByVal PageAlignment As HtmlToRtf.eAlign = HtmlToRtf.eAlign.Undefined,
                                  Optional ByVal PageOrientation As PageOrientation = PageOrientation.Auto,
                                  Optional ByVal PageHeader As String = Nothing,
                                  Optional ByVal PageFooter As String = Nothing,
                                  Optional ByVal ImageCompatibility As HtmlToRtf.eImageCompatible = HtmlToRtf.eImageCompatible.WordPad
                                  ) As String

       Return HtmlToRtfConvert([Text], HtmlToRtf.eInputFormat.Text, HtmlToRtf.eOutputFormat.Doc, TextEncoding,
                      PreservePageBreaks, PageSize, Pagenumbers, PagenumbersFormat,
                      PageAlignment, PageOrientation, PageHeader, PageFooter, ImageCompatibility)

   End Function

   ''' <summary>
   ''' Converts TXT to RTF (Rich Text).
   ''' </summary>
   ''' <param name="Text">
   ''' Indicates the plain text to convert.
   ''' </param>
   ''' <param name="TextEncoding">
   ''' Indicates the text encoding.
   ''' </param>
   ''' <param name="PreservePageBreaks">
   ''' If set to <c>true</c> page breaks are preserved on the conversion.
   ''' </param>
   ''' <param name="PageSize">
   ''' Indicates the page size.
   ''' </param>
   ''' <param name="Pagenumbers">
   ''' Indicates the page numbers.
   ''' </param>
   ''' <param name="PagenumbersFormat">
   ''' Indicates the page numbers format.
   ''' </param>
   ''' <param name="PageAlignment">
   ''' Indicates the page alignment.
   ''' </param>
   ''' <param name="PageOrientation">
   ''' Indicates the page orientation.
   ''' </param>
   ''' <param name="PageHeader">
   ''' Indicates the page header text.
   ''' </param>
   ''' <param name="PageFooter">
   ''' Indicates the page footer text.
   ''' </param>
   ''' <param name="ImageCompatibility">
   ''' Indicates the image compatibility if the document contains images.
   ''' RichTexBox control and WordPad can't show jpeg and png images inside RTF, they can show only bitmap images.
   ''' Microsoft Word can show images in jpeg, png, etc.
   ''' If this property is set to 'eImageCompatible.WordPad' images will be stored as BMP inside RTF.
   ''' </param>
   ''' <returns>System.String.</returns>
   Public Shared Function Txt2Rtf(ByVal [Text] As String,
                                  Optional ByVal TextEncoding As HtmlToRtf.eEncoding = HtmlToRtf.eEncoding.AutoDetect,
                                  Optional ByVal PreservePageBreaks As Boolean = False,
                                  Optional ByVal PageSize As PageSize = PageSize.Auto,
                                  Optional ByVal Pagenumbers As HtmlToRtf.ePageNumbers = HtmlToRtf.ePageNumbers.PageNumFirst,
                                  Optional ByVal PagenumbersFormat As String = "Page {page} of {numpages}",
                                  Optional ByVal PageAlignment As HtmlToRtf.eAlign = HtmlToRtf.eAlign.Undefined,
                                  Optional ByVal PageOrientation As PageOrientation = PageOrientation.Auto,
                                  Optional ByVal PageHeader As String = Nothing,
                                  Optional ByVal PageFooter As String = Nothing,
                                  Optional ByVal ImageCompatibility As HtmlToRtf.eImageCompatible = HtmlToRtf.eImageCompatible.WordPad
                                  ) As String

       Return HtmlToRtfConvert([Text], HtmlToRtf.eInputFormat.Text, HtmlToRtf.eOutputFormat.Rtf, TextEncoding,
                      PreservePageBreaks, PageSize, Pagenumbers, PagenumbersFormat,
                      PageAlignment, PageOrientation, PageHeader, PageFooter, ImageCompatibility)

   End Function

   ''' <summary>
   ''' Converts RtF to HtML.
   ''' </summary>
   ''' <param name="RtfText">
   ''' Indicates the rich text to convert.
   ''' </param>
   ''' <param name="OutputFormat">
   ''' Indicates the output HTML format.
   ''' </param>
   ''' <param name="TextEncoding">
   ''' Indicates the text encoding.
   ''' </param>
   ''' <param name="SaveImagesToDisk">
   ''' If set to <c>true</c>, converted images are saved to a directory on hard drive.
   ''' </param>
   ''' <param name="ImageFolder">
   ''' If 'SaveImagesToDisk' parameter is set to 'True', indicates the image directory to save the images.
   ''' The directory must exist.
   ''' </param>
   ''' <returns>System.String.</returns>
   Public Shared Function Rtf2Html(ByVal RtfText As String,
                                   Optional ByVal OutputFormat As RtfToHtml.eOutputFormat = RtfToHtml.eOutputFormat.XHTML_10,
                                   Optional ByVal TextEncoding As RtfToHtml.eEncoding = RtfToHtml.eEncoding.UTF_8,
                                   Optional ByVal SaveImagesToDisk As Boolean = False,
                                   Optional ByVal ImageFolder As String = "C:\") As String

       Return RtfToHtmlConvert(RtFText, OutputFormat, TextEncoding, SaveImagesToDisk, ImageFolder)

   End Function

#End Region

End Class