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

 

 


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


  Mostrar Mensajes
Páginas: [1] 2 3 4 5 6
1  Programación / .NET (C#, VB.NET, ASP) / Re: Obtener EXEpath de la ventana activa en: 17 Abril 2023, 07:40 am
Creo que con el pedazo de código que tengo me puedo explicar mejor

Código
  1. Imports System.Runtime.InteropServices
  2.  
  3. Public Class Form1
  4.  
  5.    Private WithEvents tmr As New Timer With {.Interval = 100, .Enabled = True}
  6.  
  7.    <DllImport("user32.dll")>
  8.    Private Shared Function GetForegroundWindow() As IntPtr
  9.    End Function
  10.  
  11.    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  12.  
  13.    End Sub
  14.  
  15.    Private Sub tmr_Tick(sender As Object, e As EventArgs) Handles tmr.Tick
  16.        Dim hWnd As IntPtr = GetForegroundWindow()
  17.        Text = hWnd
  18.  
  19.        'Aquí necesito obtener la ruta de la aplicación que tiene la ventana activa
  20.        'usando el hWnd que me devuelve la API GetForegroundWindow
  21.        'o de alguna otra manera
  22.        'Lo importante es que se obtenga la ruta de la aplicación que tiene la ventana activa
  23.  
  24.    End Sub
  25.  
  26. End Class
  27.  
2  Programación / .NET (C#, VB.NET, ASP) / Obtener EXEpath de la ventana activa en: 17 Abril 2023, 05:37 am
He estado buscando y no logro encontrar la forma de obtener la ruta de la aplicación de la ventana activa, alguien tiene alguna idea de como sería
3  Programación / .NET (C#, VB.NET, ASP) / Re: Error Genérico en GDI+ en: 10 Abril 2023, 20:28 pm
Ya lo agregué, pero sigue el problema, por eso aquí comparto todo el código para que se vea mejor cual puede ser el problema

Código
  1. Public Class Form1
  2.    Private WithEvents tmrRefresh As New Timer With {.Enabled = True, .Interval = 1}
  3.  
  4.    Private Sub tmrRefresh_Tick(sender As Object, e As EventArgs) Handles tmrRefresh.Tick
  5.        Dim gr As Graphics
  6.        Dim bmp As Bitmap = My.Resources.white
  7.        Dim br As New SolidBrush(Color.Black)
  8.        Dim free As String = AutoScaleSize(My.Computer.Info.AvailablePhysicalMemory, 2, False)
  9.        Dim x() As String
  10.        Dim por As Integer
  11.        Dim colBar As Color
  12.  
  13.        Text = free
  14.        x = Split(free)
  15.        free = x(0)
  16.        x = Split(free, ",")
  17.        If Len(x(0)) = 1 Then x(0) = $"0{x(0)}"
  18.        If Len(x(1)) = 1 Then x(1) = $"0{x(1)}"
  19.  
  20.        gr = Graphics.FromImage(bmp)
  21.        gr.DrawString($"{x(0)},", New Font("Arial", 12, FontStyle.Bold), br, New PointF(0, 0))
  22.        gr.DrawString(x(1), New Font("Arial", 12, FontStyle.Bold), br, New PointF(0, 14))
  23.  
  24.        por = Porciento(My.Computer.Info.AvailablePhysicalMemory,
  25.                        My.Computer.Info.TotalPhysicalMemory)
  26.        Select Case por
  27.            Case Is >= 75 : colBar = Color.Green
  28.            Case Is >= 50 : colBar = Color.Yellow
  29.            Case Is >= 25 : colBar = Color.Orange
  30.            Case Is >= 0 : colBar = Color.Red
  31.        End Select
  32.        gr.DrawLine(New Pen(colBar, 5), 28, 2, 28, 30)
  33.  
  34.        Icon = ToIcon(bmp, 32, 32)
  35.  
  36.        bmp.Dispose()
  37.        gr.Dispose()
  38.        br.Dispose()
  39.  
  40.    End Sub
  41.  
  42. End Class
  43.  
  44. Module modExtras
  45.  
  46.    Public Function Porciento(Parte As ULong,
  47.                              Total As ULong,
  48.                              Optional Round As Boolean = False,
  49.                              Optional Decimals As Integer = 0) As Double
  50.        Porciento = 0
  51.        Try
  52.            Porciento = Parte * 100 / Total
  53.            If Round Then Porciento = Math.Round(Porciento, Decimals)
  54.        Catch ex As Exception
  55.        End Try
  56.    End Function
  57.  
  58.    Public Function ToIcon(Image As Image,
  59.                           Width As Integer,
  60.                           Height As Integer,
  61.                           Optional MakeTransparent As Boolean = False,
  62.                           Optional Transparent As Color = Nothing) As Icon
  63.        ToIcon = Nothing
  64.        'Try
  65.        If IsNothing(Transparent) Then Transparent = Color.White
  66.        Dim thumb As Bitmap = CType(Image.GetThumbnailImage(Width, Height, Nothing, IntPtr.Zero), Bitmap)
  67.        If MakeTransparent Then thumb.MakeTransparent(Transparent)
  68.        ToIcon = Icon.FromHandle(thumb.GetHicon())
  69.        thumb.Dispose()
  70.        Image.Dispose()
  71.        'Catch ex As Exception
  72.        'End Try
  73.    End Function
  74.  
  75.    Public Function AutoScaleSize(Bytes As Decimal,
  76.                                  Optional Decimals As Integer = 2,
  77.                                  Optional FullName As Boolean = False,
  78.                                  Optional BaseMil As Boolean = False) As String
  79.        AutoScaleSize = ""
  80.        Try
  81.            Dim C As Integer
  82.            Dim b As Decimal = Bytes
  83.            Dim Div As Integer
  84.  
  85.            If BaseMil Then Div = 1000 Else Div = 1024
  86.            Do While b >= Div
  87.                b /= Div
  88.                C += 1
  89.            Loop
  90.            b = Math.Round(b, Decimals)
  91.            Select Case C
  92.                Case 0 : If FullName Then Return b & " Bytes" Else Return b & " B"
  93.                Case 1 : If FullName Then Return b & " KiloBytes" Else Return b & " KB"
  94.                Case 2 : If FullName Then Return b & " MegaBytes" Else Return b & " MB"
  95.                Case 3 : If FullName Then Return b & " GigaBytes" Else Return b & " GB"
  96.                Case 4 : If FullName Then Return b & " TeraBytes" Else Return b & " TB"
  97.                Case 5 : If FullName Then Return b & " PetaBytes" Else Return b & " PB"
  98.                Case 6 : If FullName Then Return b & " ExaBytes" Else Return b & " EB"
  99.                Case 7 : If FullName Then Return b & " ZettaBytes" Else Return b & " ZB"
  100.                Case 8 : If FullName Then Return b & " YottaBytes" Else Return b & " YB"
  101.                Case Else : If FullName Then Return Bytes & " Bytes" Else Return Bytes & " B"
  102.            End Select
  103.        Catch ex As Exception
  104.        End Try
  105.    End Function
  106.  
  107. End Module
  108.  
  109.  
4  Programación / .NET (C#, VB.NET, ASP) / Error Genérico en GDI+ en: 9 Abril 2023, 08:22 am
Hola tengo esta función para convertir un bitmap a icono y en algunas ocasiones ocurre la excepción 'Error Genérico en GDI+' en la última línea, alguna idea de que pueda estar pasando

Código:
    Public Function ToIcon(Image As Image,
                                  Width As Integer,
                                  Height As Integer,
                                  Optional MakeTransparent As Boolean = False,
                                  Optional Transparent As Color = Nothing) As Icon
        ToIcon = Nothing
        If IsNothing(Transparent) Then Transparent = Color.White
        Dim thumb As Bitmap = CType(Image.GetThumbnailImage(Width, Height, Nothing, IntPtr.Zero), Bitmap)
        If MakeTransparent Then thumb.MakeTransparent(Transparent)
        ToIcon = Icon.FromHandle(thumb.GetHicon())
    End Function
5  Programación / .NET (C#, VB.NET, ASP) / Agregar propiedades a lista de tareas en: 19 Octubre 2022, 08:46 am
Lo que quiero saber es de que manera cuando se crea un control personalizado se puede colocar una propiedad del control en la lista de tareas del control, como lo hace por ejemplo el control PictureBox con la propiedad SizeMode o en el caso del TextBox lo hace con la propiedad MultiLine.
6  Programación / .NET (C#, VB.NET, ASP) / Generador de QR sin librería en: 21 Marzo 2021, 20:06 pm
He estado buscando y buscando y no he podido encontrar algún ejemplo de generar un QR sin utilizar una librería, alguien sabe de alguna clase o código que me pueda servir?
7  Programación / .NET (C#, VB.NET, ASP) / Re: Obtener número de serie de un disco físico (no volumen lógico) en: 3 Febrero 2021, 18:28 pm
Buscando me he encontrado un código en vb6, pero me parece que no logró adaptarlo correctamente a vb.net, ya que me genera un error cuando se va a usar la api ZeroMemory

Alguien que tenga alguna idea de que hay que corregir, ya que a mi no se me ocurre nada más

Código
  1. Private Declare Auto Function CreateFile _
  2.        Lib "kernel32" Alias "CreateFileA" (
  3.            ByVal lpFileName As String,
  4.            ByVal dwDesiredAccess As Integer,
  5.            ByVal dwShareMode As Integer,
  6.            ByVal lpSecurityAttributes As Integer,
  7.            ByVal dwCreationDisposition As Integer,
  8.            ByVal dwFlagsAndAttributes As Integer,
  9.            ByVal hTemplateFile As IntPtr
  10.        ) As Integer
  11.  
  12.    Private Declare Auto Function CloseHandle _
  13.        Lib "kernel32" (
  14.            ByVal hObject As IntPtr
  15.        ) As Integer
  16.  
  17.    Private Declare Auto Function DeviceIoControl _
  18.        Lib "kernel32" (
  19.            ByVal hDevice As IntPtr,
  20.            ByVal dwIoControlCode As Integer,
  21.            <MarshalAs(UnmanagedType.AsAny)>
  22.            lpInBuffer As Object,
  23.            ByVal nInBufferSize As Integer,
  24.            <MarshalAs(UnmanagedType.AsAny)>
  25.            lpOutBuffer As Object,
  26.            ByVal nOutBufferSize As Integer,
  27.            lpBytesReturned As Integer,
  28.            ByVal lpOverlapped As Integer
  29.        ) As Integer
  30.  
  31.    Private Declare Auto Sub ZeroMemory _
  32.        Lib "kernel32" Alias "RtlZeroMemory" (
  33.            <MarshalAs(UnmanagedType.AsAny)>
  34.            dest As Object,
  35.            ByVal numBytes As Integer)
  36.  
  37.    'Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Object, Source As Object, ByVal Length As Integer)
  38.    Private Declare Auto Function GetLastError Lib "kernel32" () As Integer
  39.  
  40.    Private Const DFP_RECEIVE_DRIVE_DATA = &H7C088
  41.    Private Const FILE_SHARE_READ = &H1
  42.    Private Const FILE_SHARE_WRITE = &H2
  43.    Private Const GENERIC_READ = &H80000000
  44.    Private Const GENERIC_WRITE = &H40000000
  45.    Private Const OPEN_EXISTING = 3
  46.    Private Const CREATE_NEW = 1
  47.  
  48.    Private Enum HDInfo
  49.        HD_MODEL_NUMBER = 0
  50.        HD_SERIAL_NUMBER = 1
  51.        HD_FIRMWARE_REVISION = 2
  52.    End Enum
  53.  
  54.    Private Structure IDEREGS
  55.        Public bFeaturesReg As Byte
  56.        Public bSectorCountReg As Byte
  57.        Public bSectorNumberReg As Byte
  58.        Public bCylLowReg As Byte
  59.        Public bCylHighReg As Byte
  60.        Public bDriveHeadReg As Byte
  61.        Public bCommandReg As Byte
  62.        Public bReserved As Byte
  63.    End Structure
  64.  
  65.    Private Structure SENDCMDINPARAMS
  66.        Public cBufferSize As Integer
  67.        Public irDriveRegs As IDEREGS
  68.        Public bDriveNumber As Byte
  69.        <VBFixedArray(1, 3)>
  70.        Public bReserved() As Byte
  71.        <VBFixedArray(1, 4)>
  72.        Public dwReserved() As Integer
  73.    End Structure
  74.  
  75.    Private Structure DRIVERSTATUS
  76.        Public bDriveError As Byte
  77.        Public bIDEStatus As Byte
  78.        <VBFixedArray(1, 2)>
  79.        Public bReserved() As Byte
  80.        <VBFixedArray(1, 2)>
  81.        Public dwReserved() As Integer
  82.    End Structure
  83.  
  84.    Private Structure SENDCMDOUTPARAMS
  85.        Public cBufferSize As Integer
  86.        Public DStatus As DRIVERSTATUS
  87.        <VBFixedArray(1, 512)>
  88.        Public bBuffer() As Byte
  89.    End Structure
  90.  
  91.    Private mvarCurrentDrive As Byte
  92.  
  93.    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  94.        MsgBox(GetHDDInfo(0, "serial"))
  95.        End
  96.    End Sub
  97.  
  98.    Public Function GetHDDInfo(ByVal Number As Byte, ByVal Cmd As String) As String
  99.        mvarCurrentDrive = Number
  100.  
  101.        Select Case LCase(Cmd)
  102.            Case "model" : GetHDDInfo = CmnGetHDData(HDInfo.HD_MODEL_NUMBER)
  103.            Case "serial" : GetHDDInfo = CmnGetHDData(HDInfo.HD_SERIAL_NUMBER)
  104.            Case "firmware" : GetHDDInfo = CmnGetHDData(HDInfo.HD_FIRMWARE_REVISION)
  105.            Case Else : GetHDDInfo = ""
  106.        End Select
  107.    End Function
  108.  
  109.    Private Function CmnGetHDData(hdi As HDInfo) As String
  110.        Dim Bin As SENDCMDINPARAMS
  111.        Dim Bout As SENDCMDOUTPARAMS
  112.        Dim hdh As Long
  113.        Dim br As Long
  114.        Dim Ix As Long
  115.        Dim hddfr As Long
  116.        Dim hddln As Long
  117.        Dim S As String
  118.  
  119.        Select Case hdi
  120.            Case HDInfo.HD_MODEL_NUMBER
  121.                hddfr = 55
  122.                hddln = 40
  123.            Case HDInfo.HD_SERIAL_NUMBER
  124.                hddfr = 21
  125.                hddln = 20
  126.            Case HDInfo.HD_FIRMWARE_REVISION
  127.                hddfr = 47
  128.                hddln = 8
  129.            Case Else : Err.Raise(10001, "Illegal HD Data type")
  130.        End Select
  131.        hdh = CreateFile("\\.\PhysicalDrive" & mvarCurrentDrive, GENERIC_READ + GENERIC_WRITE, FILE_SHARE_READ + FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0)
  132.  
  133.        If hdh = 0 Then Err.Raise(10003, , "Error on CreateFile")
  134.  
  135.        ZeroMemory(Bin, Len(Bin))
  136.        ZeroMemory(Bout, Len(Bout))
  137.  
  138.        With Bin
  139.            .bDriveNumber = mvarCurrentDrive
  140.            .cBufferSize = 512
  141.            With .irDriveRegs
  142.                If (mvarCurrentDrive And 1) Then
  143.                    .bDriveHeadReg = &HB0
  144.                Else
  145.                    .bDriveHeadReg = &HA0
  146.                End If
  147.                .bCommandReg = &HEC
  148.                .bSectorCountReg = 1
  149.                .bSectorNumberReg = 1
  150.            End With
  151.        End With
  152.  
  153.        DeviceIoControl(hdh, DFP_RECEIVE_DRIVE_DATA, Bin, Len(Bin), Bout, Len(Bout), br, 0)
  154.  
  155.        S = ""
  156.        For Ix = hddfr To hddfr + hddln - 1 Step 2
  157.            If Bout.bBuffer(Ix + 1) = 0 Then Exit For
  158.            S &= Chr(Bout.bBuffer(Ix + 1))
  159.            If Bout.bBuffer(Ix) = 0 Then Exit For
  160.            S &= Chr(Bout.bBuffer(Ix))
  161.        Next Ix
  162.  
  163.        CloseHandle(hdh)
  164.        CmnGetHDData = Trim(S)
  165.    End Function
8  Programación / .NET (C#, VB.NET, ASP) / Obtener número de serie de un disco físico (no volumen lógico) en: 3 Febrero 2021, 04:46 am
Alguien me pudiera aclarar como se puede obtener el número de serie de un disco físico, también el modelo del disco.

OJO!!! Que sea usando la API de Windows y en VB
9  Sistemas Operativos / Windows / Re: Papel Tapiz con carpeta de imágenes en: 3 Febrero 2021, 04:28 am
Waooo, nunca se me hubiera ocurrido eso. Pero ese mecanismo solo empeora mi situación, ya que no obtengo la ruta de la imagen original, solo la de la copia que hace windows.

Lo que necesito es la ruta de la imagen original que ahora me parece más complejo de obtener

Gracias
10  Sistemas Operativos / Windows / Re: Papel Tapiz con carpeta de imágenes en: 3 Febrero 2021, 00:32 am
Parece que no me explique bien, yo me refiero a que en el registro de Windows en la clave

HKEY_CURRENT_USER\Control Panel\Desktop

en el valor Wallpaper aparece la ruta completa de la imagen de papel tapiz actual.

El problema es que cuando pongo una carpeta de imágenes para que cambie el papel tapiz cada cierto tiempo lo que aparece en ese valor del registro es

C:\Users\Usuario\AppData\Roaming\Microsoft\Windows\Themes\TranscodedWallpaper

Y de esta manera no puedo obtener la ruta de la imagen actual y quisiera saber si existe algún método para obtener la ruta en este caso

Gracias
Páginas: [1] 2 3 4 5 6
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines