CLEAR CACHÉ GECKOFX


Sub clearChaceGecko()
    Gecko.Cache.ImageCache.ClearCache(True)
    Gecko.Cache.ImageCache.ClearCache(False)

    Dim historyMan As nsIBrowserHistory = Xpcom.GetService(Of nsIBrowserHistory)(Gecko.Contracts.NavHistoryService)
    historyMan = Xpcom.QueryInterface(Of nsIBrowserHistory)(historyMan)
    historyMan.RemoveAllPages()
End Sub

CefSharp.WinForms

https://www.nuget.org/packages/CefSharp.WinForms/

Imports CefSharp
Imports CefSharp.WinForms

 Private ChromeBrowser As ChromiumWebBrowser

 Public Sub New()
    InitializeComponent()

    Dim settings As New CefSettings()
    CefSharp.Cef.Initialize(settings)

   'main browser
    ChromeBrowser = New ChromiumWebBrowser("https://www.miweb.com/")
    Me.Controls.Add(ChromeBrowser)
    ChromeBrowser.Visible = True
    ChromeBrowser.Dock = DockStyle.Fill
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    AddHandler ChromeBrowser.FrameLoadEnd, AddressOf ChromeBrowser_FrameLoadEnd
End Sub

Sub ChromeBrowser_FrameLoadEnd()
    With ChromeBrowser
       'Complete web form
       Dim identifiers As List(Of Long) = .GetBrowser.GetFrameIdentifiers()
       For Each i As Long In identifiers
          Try
           Dim frame As CefSharp.IFrame = .GetBrowser.GetFrame(i)
           frame.ExecuteJavaScriptAsync("document.getElementById('user').value='root';")
           frame.ExecuteJavaScriptAsync("document.getElementById('paw').value='1234';")
           frame.ExecuteJavaScriptAsync("document.getElementById('btgo').click();")
           Exit For
   Catch ex As Exception
          End Try
      End With
End Sub


Google Authenticator


'Google Play App -> https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2&hl=es


Imports Google.Authenticator
Imports System.Net
Imports System.IO
Function RegisterAppFromQrCode() As String

        Dim tfa As New TwoFactorAuthenticator()

        Dim setupInfo As SetupCode = tfa.GenerateSetupCode("AppName", "AppSubName", "SuperSecretKeyGoesHere", 300, 300)

        Dim qrCodeImageUrl As String = setupInfo.QrCodeSetupImageUrl
        Dim AppKey As String = setupInfo.ManualEntryKey

        Dim tClient As WebClient = New WebClient
        Dim URlImage As String = qrCodeImageUrl
        Dim tImage As Bitmap = Bitmap.FromStream(New MemoryStream(tClient.DownloadData(URlImage)))

        PictureBox1.Image = tImage '<- app="" code="" qr="" register="" span="" to="">

        Return AppKey '<- app="" for="" in="" key="" registered="" span="" validate="">

    End Function

    Function ValidateVerificationCode(VerificationCode As String) As Boolean

        Dim tfa As New TwoFactorAuthenticator()
        Dim isCorrectPIN As Boolean = False
        
        isCorrectPIN = tfa.ValidateTwoFactorPIN("SuperSecretKeyGoesHere", VerificationCode) '<- code="" from="" qr="" span="" verify="">
        
        Return isCorrectPIN

    End Function

CAPTURAR VENTANA DE IE

Sub CaptureIe()


        Dim docProm As mshtml.HTMLDocument
        Dim shellWindows = New SHDocVw.ShellWindows 'referenciar Microsoft Internet Controls 
        
        For Each ie As SHDocVw.WebBrowser In shellWindows

             If ie.Name = "Internet Explorer" And ie.Visible Then
                Try
                    docProm = ie.Document

                    If Not IsDBNull(docProm) Then

                        MsgBox(docProm.url)
                        MsgBox(docProm.body.innerHTML)
                        ' MsgBox(docProm. ...

                    End If
                Catch ex As Exception

                End Try
            End If
        Next

    End Sub

REDIMENSIONAR IMAGEN

Private Shared Function ImageResize(IMG As System.Drawing.Image, newW As Integer, newH As Integer) As System.Drawing.Image

        Dim newImg As New Bitmap(IMG) ', newW, newH)
        newImg.Clone(New System.Drawing.Rectangle(1, 1, 50, 50), PixelFormat.Undefined)
        Dim g As Graphics = Graphics.FromImage(newImg)
        g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear
        g.DrawImage(IMG, 0, 0, newImg.Width, newImg.Height)
        g.RotateTransform(90)
        Return newImg

  End Function

DETECTAR ESCANERES CONECTADOS

Private Sub LoadScanners(c As ComboBox, cID As ComboBox)

        Dim deviceName As String = ""
        c.Items.Clear()

        Dim deviceManager As New WIA.DeviceManager
        'Recorre la lista de disositivos y añadimos el nombre en combobox y el id en un segundo combobox

        For Each info As WIA.DeviceInfo In deviceManager.DeviceInfos
            Dim deviceID As String = info.DeviceID

            If info.Type = WIA.WiaDeviceType.ScannerDeviceType Then
                For Each p As WIA.Property In info.Properties
                    If p.Name = "Name" Then
                        deviceName = DirectCast(p, WIA.IProperty).Value.ToString()
                        c.Items.Add(deviceName)
                        cID.Items.Add(deviceID)
                    End If
                Next

            End If
        Next


   End Sub

REPARAR FICHERO EXCEL

Dim xlApp As New Excel.Application
Dim xlWorkBook As Excel.Workbook

xlWorkBook = xlApp.Workbooks.Open("C:\mifichero.xlsx",, CorruptLoad:=XlCorruptLoad.xlRepairFile)
       
xlWorkBook.SaveAs("C:\mifichero_reparado.xlsx")

xlWorkBook.Close()

PROPORCIONAR USUARIO ESPECÍFICO PARA LA EJECUCIÓN DEL CÓDIGO

'Ejecutar la aplicación de Visual Studio obtiene los derechos de lectura y escritura de archivos, por lo que el código está en ejecución, pero desde el navegador no está recibiendo los derechos adecuados para por ejemplo guardar un archivo por lo que debe proporcionar / conceder los derechos para hacerlo correctamente.

Private impersonateValitedUser As Boolean = False
Dim LOGON32_LOGON_INTERACTIVE As Integer = 2
Dim LOGON32_PROVIDER_DEFAULT As Integer = 0

#Region "Impersonation"


    Dim impersonationContext As WindowsImpersonationContext

    Declare Function LogonUserA Lib "advapi32.dll" (ByVal lpszUsername As String,
                            ByVal lpszDomain As String,
                            ByVal lpszPassword As String,
                            ByVal dwLogonType As Integer,
                            ByVal dwLogonProvider As Integer,
                            ByRef phToken As IntPtr) As Integer

    Declare Auto Function DuplicateToken Lib "advapi32.dll" (
                            ByVal ExistingTokenHandle As IntPtr,
                            ByVal ImpersonationLevel As Integer,
                            ByRef DuplicateTokenHandle As IntPtr) As Integer

    Declare Auto Function RevertToSelf Lib "advapi32.dll" () As Long
    Declare Auto Function CloseHandle Lib "kernel32.dll" (ByVal handle As IntPtr) As Long


    Private Function impersonateValidUser(ByVal userName As String,
    ByVal domain As String, ByVal password As String) As Boolean

        Dim tempWindowsIdentity As WindowsIdentity
        Dim token As IntPtr = IntPtr.Zero
        Dim tokenDuplicate As IntPtr = IntPtr.Zero
        impersonateValidUser = False

        If RevertToSelf() Then
            If LogonUserA(userName, domain, password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, token) <> 0 Then
                If DuplicateToken(token, 2, tokenDuplicate) <> 0 Then
                    tempWindowsIdentity = New WindowsIdentity(tokenDuplicate)
                    impersonationContext = tempWindowsIdentity.Impersonate()
                    If Not impersonationContext Is Nothing Then
                        impersonateValidUser = True
                        impersonateValitedUser = True
                    End If
                End If
            End If
        End If
        If Not tokenDuplicate.Equals(IntPtr.Zero) Then
            CloseHandle(tokenDuplicate)
        End If
        If Not token.Equals(IntPtr.Zero) Then
            CloseHandle(token)
        End If
    End Function

    Private Sub undoImpersonation()
        impersonationContext.Undo()
    End Sub
#End Region

Public Sub MySub()
        If impersonateValidUser("Username", "Domain", "Password") Then

            'aquí el código que se ejecuta bajo el contexto de seguridad de un usuario específico --> …

            '… <-- span="">

            undoImpersonation()
        Else

        End If

    End Sub