How to use WinVerifyTrust dll

VB_al 91 Reputation points
2021-01-24T13:29:00.377+00:00

Visual Basic .NET Framework

Hello
How to use WinVerifyTrust dll?
i wrote

 <System.Runtime.InteropServices.DllImport("Wintrust.dll")>
    Public Shared Function SignVerifier(GUID As IntPtr, LPVOID As IntPtr, pgActionID As IntPtr,  HWND  as intptr)
    End Function

But now how can I call the function amd verify a file?

Thanks

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,651 questions
{count} votes

Accepted answer
  1. Drake Wu - MSFT 991 Reputation points
    2021-01-26T03:33:31.12+00:00

    Hi @VB_al First of all, as @Castorix31 said, I did not find any function named SignVerifier on msdn. Did you want to call WinVerifyTrust?

    WinVerifyTrust requires three parameters, which should be defined as IntPtr in VB .net. According to document, the 1st parameter is the window handle of the caller. This can be passed as 0 during the actual call, but the type must not be mistaken in the declaration. The 2nd is a pointer to the GUID structure, and the 3rd is a pointer to the WINTRUST_DATA structure.

    Create a GUID instance through New Guid, then allocate a specified size of unmanaged memory through Marshal.AllocHGlobal(Marshal.SizeOf(GetType(Guid))), and then send the GUID instance to the previously allocated unmanaged memory through the Marshal.StructureToPtr method in.

    Create an instance of WINTRUST_DATA through New WINTRUST_DATA, pay attention to bring parameters to initialize when creating. The parameter is the file to be verified. This file name is used to initialize the WINTRUST_FILE_INFO structure. Initialization can be done by defining a new procedure in the declaration of the WINTRUST_DATA and WINTRUST_FILE_INFO structures.

    After the WINTRUST_DATA instance is created, it is finally sent to the unmanaged memory space as the processing steps of the GUID instance.

    After all, you can call WinVerifyTrust(0, <GUID instance address>, <WINTRUST_DATA instance address>) to verify the file.


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. VB_al 91 Reputation points
    2021-01-24T14:57:18.673+00:00

    Thanks @Castorix31 for answering me :)

    I am not understanding, the function name must be WinVerifyTrust?
    After code the function, how can i use it?

    Thanks again


  2. VB_al 91 Reputation points
    2021-01-24T16:14:23.573+00:00

    I want to verify if a file has a digital signature.

    I read this document https://video2.skills-academy.com/en-us/windows/win32/api/wintrust/nf-wintrust-winverifytrust

    if an exception occurre during runtime, the program says for example "An error has occured and exception details"

    then i'll manage that exception.

    Thanks again : - )


  3. VB_al 91 Reputation points
    2021-01-25T21:09:43.08+00:00

    Hi @Drake Wu - MSFT
    thanks for answering

    I don't know how to use this API. I read some documents about Function WinTrust and how to use API but i didn't understand.

    What did i code:`

     <System.Runtime.InteropServices.DllImport("Wintrust.dll")>  
         Public Shared Function SignVerifier(GUID As IntPtr, LPVOID As IntPtr, pgActionID As IntPtr,  HWND  as intptr)  
         End Function  
    

    Thanks

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.