From 0653bdb37690322846f0a4a070ef3a039ab578ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20=C5=A0t=C4=9Bpan=C4=8D=C3=ADk?= Date: Sun, 19 Feb 2017 11:18:03 +0100 Subject: [PATCH 1/2] Added .vscode/ to .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 571050d..339cf07 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,9 @@ Desktop.ini **/.idea/workspace.xml **/.idea/tasks.xml +# VSCode +.vscode/ + dist/ lib-cov From 9f871e90966d852e440ff62025ca4c70f72c8667 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20=C5=A0t=C4=9Bpan=C4=8D=C3=ADk?= Date: Sun, 19 Feb 2017 14:46:39 +0100 Subject: [PATCH 2/2] If the SCardSvr service is disabled on startup, set it's start type to automatic --- src/pcsclite.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/src/pcsclite.cpp b/src/pcsclite.cpp index f745f76..def8ffa 100644 --- a/src/pcsclite.cpp +++ b/src/pcsclite.cpp @@ -28,10 +28,48 @@ PCSCLite::PCSCLite(): m_card_context(0), assert(uv_mutex_init(&m_mutex) == 0); assert(uv_cond_init(&m_cond) == 0); - LONG result = SCardEstablishContext(SCARD_SCOPE_SYSTEM, - NULL, - NULL, - &m_card_context); +#ifdef _WIN32 + HKEY hKey; + DWORD startStatus, datacb = sizeof(DWORD); + LONG _res; + _res = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "System\\CurrentControlSet\\Services\\SCardSvr", 0, KEY_READ, &hKey); + if (_res != ERROR_SUCCESS) { + printf("Reg Open Key exited with %d\n", _res); + goto postServiceCheck; + } + _res = RegQueryValueEx(hKey, "Start", NULL, NULL, (LPBYTE)&startStatus, &datacb); + if (_res != ERROR_SUCCESS) { + printf("Reg Query Value exited with %d\n", _res); + goto postServiceCheck; + } + if (startStatus != 2) { + SHELLEXECUTEINFO seInfo = {0}; + seInfo.cbSize = sizeof(SHELLEXECUTEINFO); + seInfo.fMask = SEE_MASK_NOCLOSEPROCESS; + seInfo.hwnd = NULL; + seInfo.lpVerb = "runas"; + seInfo.lpFile = "sc.exe"; + seInfo.lpParameters = "config SCardSvr start=auto"; + seInfo.lpDirectory = NULL; + seInfo.nShow = SW_SHOWNORMAL; + seInfo.hInstApp = NULL; + if (!ShellExecuteEx(&seInfo)) { + printf("Shell Execute failed with %d\n", GetLastError()); + goto postServiceCheck; + } + WaitForSingleObject(seInfo.hProcess, INFINITE); + CloseHandle(seInfo.hProcess); + } +#endif // _WIN32 + +postServiceCheck: + LONG result; + do { + result = SCardEstablishContext(SCARD_SCOPE_SYSTEM, + NULL, + NULL, + &m_card_context); + } while(result == SCARD_E_NO_SERVICE || result == SCARD_E_SERVICE_STOPPED); if (result != SCARD_S_SUCCESS) { Nan::ThrowError(error_msg("SCardEstablishContext", result).c_str()); } else {