Sample code for 30+ languages & platforms
SQL Server Requires Chilkat v11.7.0+

Remove the Authenticode Signature from an MSI, PowerShell, or VBScript File

See more Code Signing Examples

Demonstrates how to remove the Authenticode signature from a Windows Installer package (.msi), a PowerShell file (.ps1, .psm1, .psd1), or a VBScript file (.vbs). Removing the signature from these file types requires Chilkat v11.7.0 or later.

Chilkat SQL Server Downloads

SQL Server
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int
    SELECT @success = 0

    --  This example requires the Chilkat API to have been previously unlocked.
    --  See Global Unlock Sample for sample code.

    --  Starting in Chilkat v11.7.0, RemoveSignature can remove the Authenticode signature from
    --    - Windows Installer packages (.msi)
    --    - PowerShell scripts, modules, and data files (.ps1, .psm1, .psd1)
    --    - VBScript files (.vbs)
    --  in addition to EXE and DLL files.

    --  This example removes the signature from a signed PowerShell script.
    --  To remove the signature from an .msi or a .vbs, pass the path of that file instead.
    DECLARE @path nvarchar(4000)
    SELECT @path = 'C:/someDir/Deploy.ps1'

    DECLARE @codeSign int
    EXEC @hr = sp_OACreate 'Chilkat.CodeSign', @codeSign OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    --  The file is modified in place.  Keep a copy if the signed file is still needed.
    --  
    --  For a PowerShell or VBScript file, the signature comment block is removed from the end of the file.
    --  For an MSI, the digital signature stream and the extended signature stream (MsiDigitalSignatureEx)
    --  are removed from the package.
    EXEC sp_OAMethod @codeSign, 'RemoveSignature', @success OUT, @path
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @codeSign, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @codeSign
        RETURN
      END


    PRINT 'The signature was removed.'

    --  The file is now unsigned, so VerifySignature returns false.
    DECLARE @sigInfo int
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @sigInfo OUT

    DECLARE @valid int
    EXEC sp_OAMethod @codeSign, 'VerifySignature', @valid OUT, @path, @sigInfo

    PRINT 'has a valid signature: ' + @valid

    EXEC @hr = sp_OADestroy @codeSign
    EXEC @hr = sp_OADestroy @sigInfo


END
GO