Merge pull request #6 from VojtechStep/windows-init-fail
Windows init fail
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -16,6 +16,9 @@ Desktop.ini
|
|||||||
**/.idea/workspace.xml
|
**/.idea/workspace.xml
|
||||||
**/.idea/tasks.xml
|
**/.idea/tasks.xml
|
||||||
|
|
||||||
|
# VSCode
|
||||||
|
.vscode/
|
||||||
|
|
||||||
dist/
|
dist/
|
||||||
|
|
||||||
lib-cov
|
lib-cov
|
||||||
|
|||||||
@@ -28,10 +28,48 @@ PCSCLite::PCSCLite(): m_card_context(0),
|
|||||||
assert(uv_mutex_init(&m_mutex) == 0);
|
assert(uv_mutex_init(&m_mutex) == 0);
|
||||||
assert(uv_cond_init(&m_cond) == 0);
|
assert(uv_cond_init(&m_cond) == 0);
|
||||||
|
|
||||||
LONG result = SCardEstablishContext(SCARD_SCOPE_SYSTEM,
|
#ifdef _WIN32
|
||||||
NULL,
|
HKEY hKey;
|
||||||
NULL,
|
DWORD startStatus, datacb = sizeof(DWORD);
|
||||||
&m_card_context);
|
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) {
|
if (result != SCARD_S_SUCCESS) {
|
||||||
Nan::ThrowError(error_msg("SCardEstablishContext", result).c_str());
|
Nan::ThrowError(error_msg("SCardEstablishContext", result).c_str());
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user