Sample code for 30+ languages & platforms
PowerBuilder 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 PowerBuilder Downloads

PowerBuilder
integer li_rc
long li_Success
string ls_Path
oleobject loo_CodeSign
oleobject loo_SigInfo
long li_Valid

li_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.
ls_Path = "C:/someDir/Deploy.ps1"

loo_CodeSign = create oleobject
li_rc = loo_CodeSign.ConnectToNewObject("Chilkat.CodeSign")
if li_rc < 0 then
    destroy loo_CodeSign
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//  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.
li_Success = loo_CodeSign.RemoveSignature(ls_Path)
if li_Success = 0 then
    Write-Debug loo_CodeSign.LastErrorText
    destroy loo_CodeSign
    return
end if

Write-Debug "The signature was removed."

//  The file is now unsigned, so VerifySignature returns false.
loo_SigInfo = create oleobject
li_rc = loo_SigInfo.ConnectToNewObject("Chilkat.JsonObject")

li_Valid = loo_CodeSign.VerifySignature(ls_Path,loo_SigInfo)
Write-Debug "has a valid signature: " + string(li_Valid)


destroy loo_CodeSign
destroy loo_SigInfo