added samples
[windows-sources.git] / sdk / samples / WCFSamples / TechnologySamples / Scenario / TrustedFacade / VB / setup.bat
blob95b17d587eb8bc6d998814e8bbaf7c2547e3df00
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 GOTO end
13 :cleancerts
14 REM cleans up certs from previous runs.
15 echo ****************
16 echo Cleanup starting
17 echo ****************
19 echo -------------------------
20 echo del client certs
21 echo -------------------------
22 certmgr.exe -del -r CurrentUser -s TrustedPeople -c -n localhost
24 echo -------------------------
25 echo del service certs
26 echo -------------------------
27 certmgr.exe -del -r LocalMachine -s My -c -n localhost
28 certmgr.exe -put -r LocalMachine -s My -c -n %COMPUTER_NAME% computer.cer
29 IF %ERRORLEVEL% EQU 0 (
30    DEL computer.cer
31    echo ****************
32    echo "You have a certificate with a Subject name matching your Machine name: %COMPUTER_NAME%"
33    echo "If this certificate is from a cross machine run of WCF samples press any key to delete it."
34    echo "Otherwise press Ctrl + C to abort this script."
35    pause
36    certmgr.exe -del -r LocalMachine -s My -c -n %COMPUTER_NAME%
39 :cleanupcompleted
40 echo *****************
41 echo Cleanup completed
42 echo *****************
44 GOTO :EOF
46 :setupservice
48 echo ************
49 echo Server cert setup starting
50 echo %SERVER_NAME%
51 echo ************
52 echo making server cert
53 echo ************
54 makecert.exe -sr LocalMachine -ss MY -a sha1 -n CN=%SERVER_NAME% -sky exchange -pe
56 IF DEFINED EXPORT_SERVICE (
57     echo ************
58     echo exporting service cert to service.cer
59     echo ************
60     certmgr.exe -put -r LocalMachine -s My -c -n %SERVER_NAME% service.cer
61 ) ELSE (
62     echo ************
63     echo copying server cert to client's CurrentUser store
64     echo ************
65     certmgr.exe -add -r LocalMachine -s My -c -n %SERVER_NAME% -r CurrentUser -s TrustedPeople
67 GOTO :EOF
69 :setscriptvariables
70 REM Parses the input to determine if we are setting this up for a single machine, client, or server
71 REM sets the appropriate name variables
72 call :setcomputername
73 IF [%1]==[] CALL :singlemachine
74 IF [%1]==[service] CALL :service
76 GOTO :EOF
78 :singlemachine
79 echo ************
80 echo Running setup script for Single Machine
81 echo ************
82 SET SUPPORTED_MODE=1
83 SET SETUP_SERVICE=1
84 SET SERVER_NAME=localhost
85 GOTO :EOF
87 :service
88 echo ************
89 echo Running setup script for Service
90 echo ************
91 SET SUPPORTED_MODE=1
92 SET SETUP_SERVICE=1
93 SET EXPORT_SERVICE=1
94 SET SERVER_NAME=%COMPUTER_NAME%
95 GOTO :EOF
97 :setcomputername
98 REM Puts the Fully Qualified Name of the Computer into a variable named COMPUTER_NAME
99 for /F "delims=" %%i in ('cscript /nologo GetComputerName.vbs') do set COMPUTER_NAME=%%i
100 GOTO :EOF
102 :displayusage
103 ECHO Correct usage:
104 ECHO     Single Machine - Setup.bat
105 ECHO     Service Machine - Setup.bat service
106 :end