June 26, 2010

Signing Powershell and Applications the easy way

Filed under: Script — Tags: , — Kevmar @ 4:19 pm

My last post showed you an easy way to sign windows scripting host files. The same thing is available for Powershell and other executables. I found a lot of complicated way to sign applications before I figured out that Powershell can sign them too. This still assumes you have a Code Singing Cert already. Here is my Powershell signing script

$cert = @(gci cert:\currentuser\my -CodeSigningCert )[0]
Set-AuthenticodeSignature $args[0] $cert

I save that in a file called SignScript.ps1 on my computer where my cert is installed into the local store. The script I want signed is passed as $args[0] from the command line like this:

PS C:\> .\SignScript.ps1 myScript.ps1
PS C:\> .\SignScript.ps1 myApp.exe

I take this one step further by adding a sign option on the right click context menu from explorer. This is very easy to set up if you get it working from the command line. From regedit, open HKEY_CLASS_ROOT, and find Microsoft.PowerShellScript.1 (and exefile). Under the key called Shell, add a key called “Sign”. This is what will show up in the context menu. Under the key you added, add a new key called “command”. Then set the default value on that “command” key to match this .reg file.

[HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\Sign\Command]
@="\"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\" \"-file\" \"C:\\Scratch\\Scripts\\SignScript.ps1\" \"%1\""

[HKEY_CLASSES_ROOT\exefile\shell\Sign\command]
@="\"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\" \"-file\" \"C:\\Scratch\\Scripts\\SignScript.ps1\" \"%1\""

Now when you right click a .ps1 or .exe file, you can digitally sign it.

Signing scripts the easy way: VBS, JS, WScript, CScript

Filed under: Script,Uncategorized — Tags: — Kevmar @ 4:06 pm

If you have a code signing cert, it is very easy to sign scripts.  Here is the VBS script I use to sign them with.

Set objSigner = WScript.CreateObject("Scripting.Signer")
objSigner.SignFile WScript.Arguments(0), "Kevin Marquette"

I save that in a file called SignScript.vbs on my computer where my cert is installed into the local store. My cert is named “Kevin Marquette” and the script I want signed is passed as arg0 from the command line like this:

c:\> SignScript myScript.vbs

I take this one step further by adding a sign option on the right click context menu from explorer. This is very easy to set up if you get it working from the command line. From regedit, open HKEY_CLASS_ROOT, and find VBSFile (or JSFile). Under the key called Shell, add a key called “Sign”. This is what will show up in the context menu. Under the key you added, add a new key called “command”. Then set the default value on that “command” key to match this .reg file.

[HKEY_CLASSES_ROOT\VBSFile\Shell\Sign\command]
@="\"c:\\windows\\System32\\CScript.exe\" C:\\Scripts\\SignScript.vbs \"%1\""

Now when you right click a .vbs file, you can sign it.

Powered by WordPress