Use Visual Studio to digitally sign an EXE file

Source: Internet
Author: User

Use the "vs2013 developer command prompt" to run the signature tool. Go to the file directory to be signed and run the command:

Signtool sign/A indicates the program .exe

Signtool-related commands

'''Csharpusage: signtool[Options]

    Valid commands:            sign       --  Sign files using an embedded signature.            timestamp  --  Timestamp previously-signed files.            verify     --  Verify embedded or catalog signatures.            catdb      --  Modify a catalog database.            remove     --  Reduce the size of an embedded signed file.

For help on a specific command, enter "signtool/? "'''

Store the signature program in a BAT file. To save trouble, I directly merged the file in "vs2013 developer command prompt". The full text is as follows.

'''Csharp

@ Call: getvscommontoolsdir @ if "% vs120comntools %" = "" Goto ErrorNoVs120comntoolsdir

@ Call "% vs120comntools % vcvarsqueryregistry. Bat" 32bit no64bit

@ If "% vsinstalldir %" = "" Goto ErrorNoVsinstalldir @ if "% frameworkdir32 %" = "" Goto ErrorNoFrameworkdir32 @ if "% frameworkversion32 %" = "" Goto ErrorNoFrameworkver32 @ if "% framework40version %" = "" Goto ErrorNoFramework40version

@ Set frameworkdir = % frameworkdir32 % @ set frameworkversion = % frameworkversion32 %

@ If not "% windowssdkExecutablepathX86 % "=" "(@ set" Path = % windowssdkExecutablepathX86 %; % PATH % ")

@ If not "% windowssdkdir %" = "" (@ set "Path = % windowssdkdir % bin \ x86; % PATH % "@ set" include = % windowssdkdir % include \ shared; % windowssdkdir % include \ Um; % windowssdkdir % include \ winrt; % include % "@ set" Lib = % windowssdkdir % Lib \ winv6.3 \ Um \ x86; % lib % "@ set" libpath = % windowssdkdir % references \ commonconfiguration \ neutral; % extensionsdkdir % \ Microsoft. vclibs \ 12.0 \ references \ commonconfiguration \ neutral; % libpath % ")

@ REM root of Visual Studio ide installed files. @ REM @ set devenvdir = % vsinstalldir % common7 \ ide \

@ REM path @ REM ---- @ if exist "% vsinstalldir % team tools \ Performance Tools" (@ set "Path = % vsinstalldir % team tools \ performance tools; % PATH % ") @ if exist "% ProgramFiles % \ HTML Help Workshop" set Path = % ProgramFiles % \ HTML Help Workshop; % PATH % @ if exist "% ProgramFiles (x86) % \ HTML Help Workshop "set Path = % ProgramFiles (x86) % \ HTML Help Workshop; % PATH % @ if exist" % vcinstalldir % vcpackages "set Path = % vcinstalldir % vcpackages; % PATH %

@ If exist "% frameworkdir % framework40version %" set Path = % frameworkdir % framework40version %; % PATH % @ if exist "% frameworkdir % frameworkversion %" set Path = % frameworkdir % frameworkversion %; % PATH % @ if exist "% vsinstalldir % common7 \ tools" set Path = % vsinstalldir % common7 \ tools; % PATH % @ if exist "% vcinstalldir % bin" set Path = % vcinstalldir % bin; % PATH % @ set Path = % devenvdir %; % PATH %

@ REM add path to msbuild binaries @ if exist "% ProgramFiles % \ msbuild \ 12.0 \ bin" set Path = % ProgramFiles % \ msbuild \ 12.0 \ bin; % PATH % @ if exist "% ProgramFiles (x86) % \ msbuild \ 12.0 \ bin" set Path = % ProgramFiles (x86) % \ msbuild \ 12.0 \ bin; % PATH %

@ REM add path to typescript compiler @ if exist "% ProgramFiles % \ microsoft sdks \ typescript \ 1.0" set Path = % ProgramFiles % \ microsoft sdks \ typescript \ 1.0; % PATH % @ if exist "% ProgramFiles (x86) % \ microsoft sdks \ typescript \ 1.0" set Path = % ProgramFiles (x86) % \ microsoft sdks \ typescript \ 1.0; % PATH %

@ If exist "% vsinstalldir % vstsdb \ deploy" (@ set "Path = % vsinstalldir % vstsdb \ deploy; % PATH % ")

@ If not "% fsharpinstalldir %" = "" (@ set "Path = % fsharpinstalldir %; % PATH % ")

@ If exist "% devenvdir % commonextensions \ Microsoft \ testwindow" (@ set "Path = % devenvdir % commonextensions \ Microsoft \ testwindow; % PATH % ")

@ REM include @ REM ------- @ if exist "% vcinstalldir % atlmfc \ include" set include = % vcinstalldir % atlmfc \ include; % include % @ if exist "% vcinstalldir % include" set include = % vcinstalldir % include; % include %

@ REM lib @ REM --- @ if exist "% vcinstalldir % atlmfc \ Lib" set Lib = % vcinstalldir % atlmfc \ Lib; % lib % @ if exist "% vcinstalldir % lib" set Lib = % vcinstalldir % LIB; % lib %

@ REM libpath @ REM ------- @ if exist "% vcinstalldir % atlmfc \ Lib" set libpath = % vcinstalldir % atlmfc \ Lib; % libpath % @ if exist "% vcinstalldir % lib" set libpath = % vcinstalldir % LIB; % libpath % @ if exist "% frameworkdir % framework40version %" set libpath = % frameworkdir % framework40version %; % libpath % @ if exist "% frameworkdir % frameworkversion %" set libpath = % frameworkdir % frameworkversion %; % libpath %

@ REM visualstudioversion @ REM ------------------- @ set visualstudioversion = 12.0

@ Goto end

@ REM coding: getvscommontoolsdir @ set vs120comntools = @ call: getvscommontoolsdirhelper32 HKLM> NUL 2> & 1 @ if errorlevel 1 call: Hangzhou hkcu> NUL 2> & 1 @ if errorlevel 1 call: getvscommontoolsdirhelper64 HKLM> NUL 2> & 1 @ if errorlevel 1 call: getvscommontoolsdirhelper64 hkcu> NUL 2> & 1 @ exit/B 0

: Getvscommontoolsdirhelper32 @ for/F "tokens = 12.0 *" % I in ('reg query "% 1 \ Software \ Microsoft \ visualstudio \ sxs \ vs7"/V "') do (@ if "% I" = "12.0" (@ set "vs120comntools = % K ")) @ if "% vs120comntools %" = "" Exit/B 1 @ set "vs120comntools = % vs120comntools % common7 \ tools \" @ exit/B 0

: Getvscommontoolsdirhelper64 @ for/F "tokens = 12.0 *" % I in ('reg query "% 1 \ Software \ wow6432node \ Microsoft \ visualstudio \ sxs \ vs7"/V" ') do (@ if "% I" = "12.0" (@ set "vs120comntools = % K ")) @ if "% vs120comntools %" = "" Exit/B 1 @ set "vs120comntools = % vs120comntools % common7 \ tools \" @ exit/B 0

@ REM -------------------------------------------------------------------------: ErrorNoVs120comntoolsdir @ echo error: cannot determine the location of the vs Common Tools Folder. @ goto end

: ErrorNoVsinstalldir @ echo error: cannot determine the location of the vs installation. @ goto end

: ErrorNoFrameworkdir32 @ echo error: cannot determine the location of the. NET Framework 32bit installation. @ goto end

: ErrorNoFrameworkver32 @ echo error: cannot determine the version of the. NET Framework 32bit installation. @ goto end

: ErrorNoFramework40version @ echo error: cannot determine the. NET Framework 4.0 version. @ goto end

: End

@ Echo off

Cd % ~ Dp0

Signtool sign/A indicates the program .exe '''

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.