added samples
[windows-sources.git] / sdk / samples / WCFSamples / TechnologySamples / Basic / Service / Security / Identity / VB / setup.bat
blob4e39fe275308bc8fbaec6bf3f4e09ea5d2ebe883
1 echo off
3 setlocal
4 echo ************
5 echo cert setup starting
6 echo ************
8 call :setscriptvariables %1
9 IF NOT DEFINED SUPPORTED_MODE call :displayusage
10 IF DEFINED SETUP_SERVICE call :setupservice
11 GOTO end
13 :setupservice
15 set PFX_FILE=identity.pfx
16 set PFX_PASSWORD=xyz
17 set LocalMachine_My=0
18 set CN=identity
19 set SERIAL=30 3e 60 f8 cb 96 95 81 48 33 6f da f2 09 0b b7
21 REM Determine which certificates are installed on the machine.
22 for /f "delims=" %%l in ('certmgr.exe -all -s -r LocalMachine My') do (
24        if /i "%%l" == "   %SERIAL%" (
25            set LocalMachine_My=1
26        )
30 if %LocalMachine_My% == 1 (
31         goto copycert
34 REM If this is Windows XP show help text indicating the certificate needs to be imported manually.
35         set XP=0
36         (ver | findstr /C:"5.1") && set XP=1
37         if "%XP%"=="1" (
38                 goto displaywinxpusage
39         )
41 REM Import server certificates on Windows 2003 - certutil is only on Windows 2003
42 if NOT %LocalMachine_My% == 1 (
43         echo ************
44         echo Server cert setup starting
45         echo Installing %SERVER_NAME% certificate into the LocalMachine/My store
46         echo ************
47         echo Importing %PFX_FILE% to LocalMachine/My store ...
48         echo ************
49         certutil -importpfx -p %PFX_PASSWORD% %PFX_FILE%
52 :copycert
54 IF DEFINED EXPORT_SERVICE GOTO exportservice
56 echo ************
57 echo copying server cert to client's CurrentUser store
58 echo ************
59 certmgr.exe -add -r LocalMachine -s My -c -n %SERVER_NAME% -r CurrentUser -s TrustedPeople
60 GOTO :EOF
62 set XP=0
63 (ver | findstr /C:"5.1") && set XP=1
64 if NOT "%XP%"=="1" (
65         goto end
68 REM Show instructions for adding server certificates
69 :displaywinxpusage
70     echo.
71     echo ********************************
72     echo MANUAL SET UP INSTRUCTIONS:
73     echo ********************************
74     echo Use the MMC Console Certificates Snap-in to install the 
75     echo required server certificates into the 
76     echo LocalMachine/My ^(Personal^) certificate store.
77     echo.
78     echo The password for the PFX files is "%PFX_PASSWORD%".
79     echo.
80     echo Then run this script again copy the server certificate
81     echo to the currentuser trusted people store.
82     echo.
83     echo SEE ALSO:
84     echo See this sample's ReadMe topic in the documentation for detailed instructions.
85     echo.
86     pause
87 GOTO :EOF
89 :cleancerts
90 REM cleans up certs from previous runs.
91 echo ****************
92 echo Cleanup starting
93 echo ****************
95 echo -------------------------
96 echo del client certs
97 echo -------------------------
98 certmgr.exe -del -r CurrentUser -s TrustedPeople -c -n localhost
99 certmgr.exe -del -r CurrentUser -s TrustedPeople -c -n %SERVER_NAME%
101 echo -------------------------
102 echo del service certs
103 echo -------------------------
104 certmgr.exe -del -r LocalMachine -s My -c -n localhost
105 certmgr.exe -del -r LocalMachine -s My -c -n %SERVER_NAME%
107 :cleanupcompleted
108 echo *****************
109 echo Cleanup completed
110 echo *****************
111 GOTO :EOF
113 :exportservice
115 echo ************
116 echo exporting service cert to service.cer
117 echo ************
118 certmgr.exe -put -r LocalMachine -s My -c -n identity.com service.cer
119 GOTO :EOF
121 :setscriptvariables
122 REM Parses the input to determine if we are setting this up for a single machine, client, or server
123 REM sets the appropriate name variables
124 IF [%1]==[] CALL :singlemachine
125 IF [%1]==[service] CALL :service
126 GOTO :EOF
128 :cleancerts
129 REM cleans up certs from previous runs.
130 echo ****************
131 echo Cleanup starting
132 echo ****************
134 echo -------------------------
135 echo del client certs
136 echo -------------------------
137 certmgr.exe -del -r CurrentUser -s TrustedPeople -c -n localhost
138 certmgr.exe -del -r CurrentUser -s TrustedPeople -c -n %SERVER_NAME%
140 echo -------------------------
141 echo del service certs
142 echo -------------------------
143 certmgr.exe -del -r LocalMachine -s My -c -n localhost
144 certmgr.exe -del -r LocalMachine -s My -c -n %SERVER_NAME%
146 :cleanupcompleted
147 echo *****************
148 echo Cleanup completed
149 echo *****************
150 GOTO :EOF
153 :singlemachine
154 echo ************
155 echo Running setup script for Single Machine
156 echo ************
157 SET SUPPORTED_MODE=1
158 SET SETUP_SERVICE=1
159 SET SERVER_NAME=identity.com
160 GOTO :EOF
162 :service
163 echo ************
164 echo Running setup script for Service
165 echo ************
166 SET SUPPORTED_MODE=1
167 SET SETUP_SERVICE=1
168 SET EXPORT_SERVICE=1
169 SET SERVER_NAME=identity.com
170 GOTO :EOF
172 :displayusage
173 ECHO Correct usage:
174 ECHO     Single Machine - Setup.bat
175 ECHO     Service Machine - Setup.bat service
177 :end