Browse Source

Make sure make_cert.bat is executed with admin rights

Otherwise, OpenSSL complains with the message "unable to write 'random state' "
Philipp Hasper 8 years ago
parent
commit
debeb8b7fc
1 changed files with 33 additions and 0 deletions
  1. 33 0
      resources/cert/make_cert.bat

+ 33 - 0
resources/cert/make_cert.bat

@@ -1,3 +1,36 @@
+@echo off
+REM We need admin rights, otherwise the random state cannot be written
+REM Thanks to http://stackoverflow.com/a/10052222/1531708
+
+:: BatchGotAdmin
+:-------------------------------------
+REM  --> Check for permissions
+    IF "%PROCESSOR_ARCHITECTURE%" EQU "amd64" (
+>nul 2>&1 "%SYSTEMROOT%\SysWOW64\cacls.exe" "%SYSTEMROOT%\SysWOW64\config\system"
+) ELSE (
+>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
+)
+
+REM --> If error flag set, we do not have admin.
+if '%errorlevel%' NEQ '0' (
+    echo Requesting administrative privileges...
+    goto UACPrompt
+) else ( goto gotAdmin )
+
+:UACPrompt
+    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
+    set params = %*:"=""
+    echo UAC.ShellExecute "cmd.exe", "/c ""%~s0"" %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"
+
+    "%temp%\getadmin.vbs"
+    del "%temp%\getadmin.vbs"
+    exit /B
+
+:gotAdmin
+    pushd "%CD%"
+    CD /D "%~dp0"
+:-------------------------------------- 
+
 del server.*
 
 c:\OpenSSL-Win32\bin\openssl.exe genrsa -des3 -out server.key 4096