added samples
[windows-sources.git] / sdk / samples / WCFSamples / TechnologySamples / Basic / Binding / WS / MessageSecurity / Certificate / CS / setup.bat
blobba28304dce6f38774a7b6d8f02b1a61b8112c634
1 echo off
2 setlocal
3 echo ************
4 echo cert setup starting
5 echo ************
7 call :setscriptvariables %1
8 IF NOT DEFINED SUPPORTED_MODE call :displayusage
9 IF DEFINED SUPPORTED_MODE call :cleancerts
10 IF DEFINED SETUP_SERVICE call :setupservice
11 IF DEFINED SETUP_SERVICE call :setcertpermissions
12 IF DEFINED SETUP_CLIENT call :setupclient
13 GOTO end
15 :cleancerts
16 REM cleans up certs from previous runs.
17 echo ****************
18 echo Cleanup starting
19 echo ****************
21 echo -------------------------
22 echo del client certs
23 echo -------------------------
24 certmgr.exe -del -r CurrentUser -s My -c -n %CLIENT_NAME%
25 certmgr.exe -del -r CurrentUser -s TrustedPeople -c -n localhost
27 echo -------------------------
28 echo del service certs
29 echo -------------------------
30 certmgr.exe -del -r LocalMachine -s My -c -n localhost
31 certmgr.exe -del -r LocalMachine -s TrustedPeople -c -n %CLIENT_NAME%
32 certmgr.exe -put -r LocalMachine -s My -c -n %COMPUTER_NAME% computer.cer
33 IF %ERRORLEVEL% EQU 0 (
34    DEL computer.cer
35    echo ****************
36    echo "You have a certificate with a Subject name matching your Machine name: %COMPUTER_NAME%"
37    echo "If this certificate is from a cross machine run of WCF samples press any key to delete it."
38    echo "Otherwise press Ctrl + C to abort this script."
39    pause
40    certmgr.exe -del -r LocalMachine -s My -c -n %COMPUTER_NAME%
43 :cleanupcompleted
44 echo *****************
45 echo Cleanup completed
46 echo *****************
48 GOTO :EOF
50 :setupclient
52 echo ************
53 echo making client cert
54 echo ************
55 makecert.exe -sr CurrentUser -ss MY -a sha1 -n CN=%CLIENT_NAME% -sky exchange -pe
57 IF DEFINED EXPORT_CLIENT (
58     echo ************
59     echo exporting client cert to client.cer
60     echo ************
61     certmgr.exe -put -r CurrentUser -s My -c -n %CLIENT_NAME% client.cer
62 ) ELSE (
63     echo ************
64     echo copying client cert to server's LocalMachine store
65     echo ************
66     certmgr.exe -add -r CurrentUser -s My -c -n %CLIENT_NAME% -r LocalMachine -s TrustedPeople
68 GOTO :EOF
70 :setupservice
72 echo ************
73 echo Server cert setup starting
74 echo %SERVER_NAME%
75 echo ************
76 echo making server cert
77 echo ************
78 makecert.exe -sr LocalMachine -ss MY -a sha1 -n CN=%SERVER_NAME% -sky exchange -pe
80 IF DEFINED EXPORT_SERVICE (
81     echo ************
82     echo exporting service cert to service.cer
83     echo ************
84     certmgr.exe -put -r LocalMachine -s My -c -n %SERVER_NAME% service.cer
85 ) ELSE (
86     echo ************
87     echo copying server cert to client's CurrentUser store
88     echo ************
89     certmgr.exe -add -r LocalMachine -s My -c -n %SERVER_NAME% -r CurrentUser -s TrustedPeople
91 GOTO :EOF
93 :setcertpermissions
95 echo ************
96 echo setting privileges on server certificates
97 echo ************
98 for /F "delims=" %%i in ('"%ProgramFiles%\ServiceModelSampleTools\FindPrivateKey.exe" My LocalMachine -n CN^=%SERVER_NAME% -a') do set PRIVATE_KEY_FILE=%%i
99 set WP_ACCOUNT=NT AUTHORITY\NETWORK SERVICE
100 (ver | findstr /C:"5.1") && set WP_ACCOUNT=%COMPUTERNAME%\ASPNET
101 echo Y|cacls.exe "%PRIVATE_KEY_FILE%" /E /G "%WP_ACCOUNT%":R
102 iisreset
104 GOTO :EOF
106 :setscriptvariables
107 REM Parses the input to determine if we are setting this up for a single machine, client, or server
108 REM sets the appropriate name variables
109 call :setcomputername
110 IF [%1]==[] CALL :singlemachine
111 IF [%1]==[service] CALL :service
112 IF [%1]==[client] CALL :client
114 set CLIENT_NAME=client.com
116 GOTO :EOF
118 :singlemachine
119 echo ************
120 echo Running setup script for Single Machine
121 echo ************
122 SET SUPPORTED_MODE=1
123 SET SETUP_CLIENT=1
124 SET SETUP_SERVICE=1
125 SET SERVER_NAME=localhost
126 GOTO :EOF
128 :service
129 echo ************
130 echo Running setup script for Service
131 echo ************
132 SET SUPPORTED_MODE=1
133 SET SETUP_SERVICE=1
134 SET EXPORT_SERVICE=1
135 SET SERVER_NAME=%COMPUTER_NAME%
136 GOTO :EOF
138 :client
139 echo ************
140 echo Running setup script for Client
141 echo ************
142 SET SUPPORTED_MODE=1
143 SET SETUP_CLIENT=1
144 SET EXPORT_CLIENT=1
145 GOTO :EOF
147 :setcomputername
148 REM Puts the Fully Qualified Name of the Computer into a variable named COMPUTER_NAME
149 for /F "delims=" %%i in ('cscript /nologo GetComputerName.vbs') do set COMPUTER_NAME=%%i
150 GOTO :EOF
152 :displayusage
153 ECHO Correct usage:
154 ECHO     Single Machine - Setup.bat
155 ECHO     Client Machine - Setup.bat client
156 ECHO     Service Machine - Setup.bat service
157 :end