diff --git a/win32/Make.rules.mak b/win32/Make.rules.mak
index 7c1a61f8..1a4a0958 100644
--- a/win32/Make.rules.mak
+++ b/win32/Make.rules.mak
@@ -11,9 +11,22 @@ LIBLTDL_LIB = # E.g. C:\libtool-1.5.8-lib\lib\libltdl.lib
OPENSC_FEATURES = pcsc
+#Uncomment to use 'static' linking mode
+#LINK_MODE = STATIC
+
#Include support of minidriver 'cardmon'
MINIDRIVER_DEF = /DENABLE_MINIDRIVER
+
+#Build MSI with the Windows Installer XML (WIX), minimal WIX version 3.6
+#Static link mode should be used.
+#WIX_MSI_DEF = /DBUILD_MSI
+!IF "$(WIX_MSI_DEF)" == "/DBUILD_MSI"
+WIX_INSTALLED_PATH = c:\download\wix36-binaries
+LINK_MODE = STATIC
+!ENDIF
+
+
# If you want support for OpenSSL (needed for a.o. pkcs15-init tool and openssl engine):
# - download and build OpenSSL
# - uncomment the line starting with OPENSSL_DEF
@@ -22,11 +35,20 @@ MINIDRIVER_DEF = /DENABLE_MINIDRIVER
#OPENSSL_DEF = /DENABLE_OPENSSL
!IF "$(OPENSSL_DEF)" == "/DENABLE_OPENSSL"
OPENSSL_INCL_DIR = /IC:\openssl\include
+
+!IF "$(LINK_MODE)" != "STATIC"
OPENSSL_LIB = C:\openssl\out32dll\libeay32.lib
+#OPENSSL_LIB = C:\openssl\lib\VC\libeay32MD.lib C:\openssl\lib\VC\ssleay32MD.lib user32.lib advapi32.lib
+!ENDIF
+!IF "$(LINK_MODE)" == "STATIC"
+#OPENSSL_LIB = C:\openssl\lib\VC\static\libeay32MT.lib C:\openssl\lib\VC\static\ssleay32MT.lib user32.lib advapi32.lib
+!ENDIF
+
PROGRAMS_OPENSSL = pkcs15-init.exe cryptoflex-tool.exe netkey-tool.exe piv-tool.exe westcos-tool.exe
OPENSC_FEATURES = $(OPENSC_FEATURES) openssl
!ENDIF
+
# If you want support for zlib (Used for PIV, infocamere and actalis):
# - Download zlib and build
# - uncomment the line starting with ZLIB_DEF
@@ -43,8 +65,15 @@ OPENSC_FEATURES = $(OPENSC_FEATURES) zlib
# http://msinttypes.googlecode.com/files/msinttypes-r26.zip
INTTYPES_INCL_DIR = /IC:\opensc\dependencies\msys\local
+!IF "$(LINK_MODE)" != "STATIC"
COPTS = /D_CRT_SECURE_NO_DEPRECATE /Zi /MD /nologo /DHAVE_CONFIG_H /I$(TOPDIR)\win32 /I$(TOPDIR)\src $(OPENSSL_INCL_DIR) $(ZLIB_INCL_DIR) $(LIBLTDL_INCL) $(INTTYPES_INCL_DIR) /D_WIN32_WINNT=0x0400 /DWIN32_LEAN_AND_MEAN $(OPENSSL_DEF) $(ZLIB_DEF) /DOPENSC_FEATURES="\"$(OPENSC_FEATURES)\""
LINKFLAGS = /DEBUG /NOLOGO /INCREMENTAL:NO /MACHINE:IX86
+!ENDIF
+
+!IF "$(LINK_MODE)" == "STATIC"
+COPTS = /D_CRT_SECURE_NO_DEPRECATE /MT /nologo /DHAVE_CONFIG_H /I$(TOPDIR)\win32 /I$(TOPDIR)\src /I$(TOPDIR)\src\include\opensc /I$(TOPDIR)\src\common $(OPENSSL_INCL_DIR) $(ZLIB_INCL_DIR) $(LIBLTDL_INCL) $(INTTYPES_INCL_DIR) /D_WIN32_WINNT=0x0400 /DWIN32_LEAN_AND_MEAN $(OPENSSL_DEF) $(ZLIB_DEF) /DOPENSC_FEATURES="\"$(OPENSC_FEATURES)\""
+LINKFLAGS = /NOLOGO /INCREMENTAL:NO /MACHINE:IX86 /MANIFEST:NO /NODEFAULTLIB:MSVCRTD /NODEFAULTLIB:MSVCRT /NODEFAULTLIB:LIBCMTD
+!ENDIF
.c.obj::
cl $(COPTS) /c $<
diff --git a/win32/opensc-msi/Make.rules.mak.works-for-vt b/win32/opensc-msi/Make.rules.mak.works-for-vt
new file mode 100644
index 00000000..187cb122
--- /dev/null
+++ b/win32/opensc-msi/Make.rules.mak.works-for-vt
@@ -0,0 +1,93 @@
+# Note: these instructions obsolete the instructions in opensc.html
+
+# You first need to download the gnuwin32 libtool (e.g. the "Binaries" and "Developer
+# files" from http://gnuwin32.sourceforge.net/packages/libtool.htm)
+# Then fill in the directory path to ltdl.h on the LIBLTDL_INCL line below, preceeded
+# by an "/I"; and fill in the path to the libltdl.lib on the LIBLTDL_LIB line below.
+# Then you can build this OpenSC package; and afterwards you'll need to copy the
+# libltdl3.dll somewhere on your execution path.
+#LIBLTDL_INCL = # E.g. /IC:\libtool-1.5.8-lib\include
+#LIBLTDL_LIB = # E.g. C:\libtool-1.5.8-lib\lib\libltdl.lib
+LIBLTDL_INCL = /IC:\opensc\dependencies\libtool\include
+LIBLTDL_LIB = C:\opensc\dependencies\libtool\lib\ltdl.lib
+LIBLTDL_DLL = C:\opensc\dependencies\libtool\bin\libltdl3.dll
+
+OPENSC_FEATURES = pcsc
+
+#Uncomment to use 'static' linking mode
+#LINK_MODE = STATIC
+
+#Include support of minidriver 'cardmon'
+#MINIDRIVER_DEF = /DENABLE_MINIDRIVER
+
+
+#Build MSI with the Windows Installer XML (WIX), minimal WIX version 3.6
+#Static link mode should be used.
+WIX_MSI_DEF = /DBUILD_MSI
+!IF "$(WIX_MSI_DEF)" == "/DBUILD_MSI"
+WIX_INSTALLED_PATH = c:\download\wix36-binaries
+LINK_MODE = STATIC
+!ENDIF
+
+
+# If you want support for OpenSSL (needed for a.o. pkcs15-init tool and openssl engine):
+# - download and build OpenSSL
+# - uncomment the line starting with OPENSSL_DEF
+# - set the OPENSSL_INCL_DIR below to your openssl include directory, preceded by "/I"
+# - set the OPENSSL_LIB below to your openssl lib file
+OPENSSL_DEF = /DENABLE_OPENSSL
+!IF "$(OPENSSL_DEF)" == "/DENABLE_OPENSSL"
+#OPENSSL_INCL_DIR = /IC:\openssl\include
+OPENSSL_INCL_DIR = /IC:\opensc\dependencies\openssl\include
+
+!IF "$(LINK_MODE)" != "STATIC"
+#OPENSSL_LIB = C:\openssl\out32dll\libeay32.lib
+OPENSSL_LIB = C:\opensc\dependencies\openssl\lib\VC\libeay32MD.lib C:\opensc\dependencies\openssl\lib\VC\ssleay32MD.lib user32.lib advapi32.lib
+#OPENSSL_LIB = C:\opensc\dependencies\openssl\lib\VC\static\libeay32MD.lib C:\opensc\dependencies\openssl\lib\VC\static\ssleay32MD.lib user32.lib advapi32.lib
+!ENDIF
+!IF "$(LINK_MODE)" == "STATIC"
+OPENSSL_LIB = C:\opensc\dependencies\openssl\lib\VC\static\libeay32MT.lib C:\opensc\dependencies\openssl\lib\VC\static\ssleay32MT.lib user32.lib advapi32.lib
+!ENDIF
+
+PROGRAMS_OPENSSL = pkcs15-init.exe cryptoflex-tool.exe netkey-tool.exe piv-tool.exe westcos-tool.exe
+OPENSC_FEATURES = $(OPENSC_FEATURES) openssl
+!ENDIF
+
+
+# If you want support for zlib (Used for PIV, infocamere and actalis):
+# - Download zlib and build
+# - uncomment the line starting with ZLIB_DEF
+# - set the ZLIB_INCL_DIR below to the zlib include lib proceeded by "/I"
+# - set the ZLIB_LIB below to your zlib lib file
+#ZLIB_DEF = /DENABLE_ZLIB
+!IF "$(ZLIB_DEF)" == "/DENABLE_ZLIB"
+#ZLIB_INCL_DIR = /IC:\ZLIB\INCLUDE
+ZLIB_INCL_DIR = /IC:\opensc\dependencies\zlib\include
+#ZLIB_LIB = C:\ZLIB\LIB\zlib.lib
+ZLIB_LIB = C:\opensc\dependencies\zlib\lib\zlib.lib
+OPENSC_FEATURES = $(OPENSC_FEATURES) zlib
+!ENDIF
+
+
+# Mandatory path to 'ISO C9x compliant stdint.h and inttypes.h for Microsoft Visual Studio'
+# http://msinttypes.googlecode.com/files/msinttypes-r26.zip
+INTTYPES_INCL_DIR = /IC:\opensc\dependencies\msys\local
+
+!IF "$(LINK_MODE)" != "STATIC"
+COPTS = /D_CRT_SECURE_NO_DEPRECATE /Zi /MD /nologo /DHAVE_CONFIG_H /I$(TOPDIR)\win32 /I$(TOPDIR)\src $(OPENSSL_INCL_DIR) $(ZLIB_INCL_DIR) $(LIBLTDL_INCL) $(INTTYPES_INCL_DIR) /D_WIN32_WINNT=0x0400 /DWIN32_LEAN_AND_MEAN $(OPENSSL_DEF) $(ZLIB_DEF) /DOPENSC_FEATURES="\"$(OPENSC_FEATURES)\""
+LINKFLAGS = /DEBUG /NOLOGO /INCREMENTAL:NO /MACHINE:IX86
+!ENDIF
+
+!IF "$(LINK_MODE)" == "STATIC"
+COPTS = /D_CRT_SECURE_NO_DEPRECATE /MT /nologo /DHAVE_CONFIG_H /I$(TOPDIR)\win32 /I$(TOPDIR)\src /I$(TOPDIR)\src\common $(OPENSSL_INCL_DIR) $(ZLIB_INCL_DIR) $(LIBLTDL_INCL) $(INTTYPES_INCL_DIR) /D_WIN32_WINNT=0x0400 /DWIN32_LEAN_AND_MEAN $(OPENSSL_DEF) $(ZLIB_DEF) /DOPENSC_FEATURES="\"$(OPENSC_FEATURES)\""
+LINKFLAGS = /NOLOGO /INCREMENTAL:NO /MACHINE:IX86 /MANIFEST:NO /NODEFAULTLIB:MSVCRTD /NODEFAULTLIB:MSVCRT /NODEFAULTLIB:LIBCMTD
+!ENDIF
+
+.c.obj::
+ cl $(COPTS) /c $<
+
+.rc.res::
+ rc /l 0x0409 /r $<
+
+clean::
+ del /Q *.obj *.dll *.exe *.pdb *.lib *.def *.manifest
diff --git a/win32/opensc-msi/Makefile.mak b/win32/opensc-msi/Makefile.mak
new file mode 100644
index 00000000..ee9fefbc
--- /dev/null
+++ b/win32/opensc-msi/Makefile.mak
@@ -0,0 +1,17 @@
+TOPDIR = ..\..\..
+
+TARGET = OpenSC.msi
+
+all: $(TARGET)
+
+!INCLUDE $(TOPDIR)\win32\Make.rules.mak
+
+OpenSC.msi: OpenSC.wixobj
+ $(WIX_INSTALLED_PATH)\light.exe -sh -ext WixUIExtension $?
+
+OpenSC.wixobj: OpenSC.wxs
+ $(WIX_INSTALLED_PATH)\candle.exe -dSOURCE_DIR=$(TOPDIR) -dPATH_TO_LIBLTD3_DLL=$(LIBLTDL_DLL) $?
+
+clean::
+ del /Q *.msi *.wixobj *.wixpdb
+
diff --git a/win32/opensc-msi/OpenSC.ico b/win32/opensc-msi/OpenSC.ico
new file mode 100755
index 00000000..87227eeb
Binary files /dev/null and b/win32/opensc-msi/OpenSC.ico differ
diff --git a/win32/opensc-msi/OpenSC.wxs b/win32/opensc-msi/OpenSC.wxs
new file mode 100755
index 00000000..2894be2d
--- /dev/null
+++ b/win32/opensc-msi/OpenSC.wxs
@@ -0,0 +1,173 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/win32/opensc-msi/README b/win32/opensc-msi/README
new file mode 100755
index 00000000..eb1514ea
--- /dev/null
+++ b/win32/opensc-msi/README
@@ -0,0 +1,5 @@
+Tested with WIX version 3.6.0917.0
+
+To create MSI:
+# wix\candle.exe -dSOURCE_DIR= -dPATH_TO_LIBLTD3_DLL= OpenSC.wxs
+# wix\light.exe -sh -ext WixUIExtension OpenSC.wixobj