Add /i switch to display error messages
Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
@@ -8,7 +8,7 @@ Binary downloads and change-logs can be found on the [project's release page](ht
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```
|
```
|
||||||
WLANSetEAPUserData <profile> <flags> <user data URI>
|
WLANSetEAPUserData <profile> <flags> <user data URI> [/i]
|
||||||
```
|
```
|
||||||
|
|
||||||
| Parameter | Explanation |
|
| Parameter | Explanation |
|
||||||
@@ -16,6 +16,7 @@ WLANSetEAPUserData <profile> <flags> <user data URI>
|
|||||||
| `profile` | The name of the network profile (typically same as SSID) |
|
| `profile` | The name of the network profile (typically same as SSID) |
|
||||||
| `flags` | Flags to pass to `WlanSetProfileEapXmlUserData()` function call (decimal number: 0=Current User, 1=All Users) |
|
| `flags` | Flags to pass to `WlanSetProfileEapXmlUserData()` function call (decimal number: 0=Current User, 1=All Users) |
|
||||||
| `user data URI` | User data XML URI. Can be a path to an XML file, web URL where user data XML can be loaded from, etc. The XML schema varies according to the configured EAP method provider used by `profile`. For example: Microsoft's EAP-TLS requires the schema described in [EAP-TLS User Properties](https://msdn.microsoft.com/en-us/library/windows/desktop/bb204662.aspx). |
|
| `user data URI` | User data XML URI. Can be a path to an XML file, web URL where user data XML can be loaded from, etc. The XML schema varies according to the configured EAP method provider used by `profile`. For example: Microsoft's EAP-TLS requires the schema described in [EAP-TLS User Properties](https://msdn.microsoft.com/en-us/library/windows/desktop/bb204662.aspx). |
|
||||||
|
| /i | Interactive: Pop-up a message dialog in case of error |
|
||||||
|
|
||||||
|
|
||||||
## Return codes
|
## Return codes
|
||||||
|
@@ -52,23 +52,30 @@ int CALLBACK WinMain(
|
|||||||
UNREFERENCED_PARAMETER(lpCmdLine );
|
UNREFERENCED_PARAMETER(lpCmdLine );
|
||||||
UNREFERENCED_PARAMETER(nCmdShow );
|
UNREFERENCED_PARAMETER(nCmdShow );
|
||||||
|
|
||||||
|
int result = -1;
|
||||||
|
bool interactive = false;
|
||||||
|
|
||||||
|
try {
|
||||||
// Get command line arguments. (As Unicode, please.)
|
// Get command line arguments. (As Unicode, please.)
|
||||||
int nArgs;
|
int nArgs;
|
||||||
unique_ptr<LPWSTR[], LocalFree_delete<LPWSTR[]> > pwcArglist(CommandLineToArgvW(GetCommandLineW(), &nArgs));
|
unique_ptr<LPWSTR[], LocalFree_delete<LPWSTR[]> > pwcArglist(CommandLineToArgvW(GetCommandLineW(), &nArgs));
|
||||||
if (!pwcArglist) {
|
if (!pwcArglist) {
|
||||||
//_ftprintf(stderr, _T("CommandLineToArgvW() failed (error %u).\n"), GetLastError());
|
result = 100;
|
||||||
return 100;
|
throw win_runtime_error("CommandLineToArgvW() failed");
|
||||||
}
|
}
|
||||||
if (nArgs <= 3) {
|
if (nArgs < 4) {
|
||||||
//_ftprintf(stderr, _T("Not enough arguments.\n"));
|
result = 101;
|
||||||
return 101;
|
throw invalid_argument("Not enough arguments.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int i = 4; i < nArgs; i++)
|
||||||
|
if (_wcsicmp(pwcArglist[i], L"/I") == 0) interactive = true;
|
||||||
|
|
||||||
// Initialize COM.
|
// Initialize COM.
|
||||||
com_initializer com_init(NULL);
|
com_initializer com_init(NULL);
|
||||||
if (FAILED(com_init.status())) {
|
if (FAILED(com_init.status())) {
|
||||||
//_ftprintf(stderr, _T("CoInitialize() failed (error 0x%08x).\n"), com_init.status());
|
result = 200;
|
||||||
return 200;
|
throw com_runtime_error(com_init.status(), "CoInitialize() failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load user data XML into memory.
|
// Load user data XML into memory.
|
||||||
@@ -79,8 +86,8 @@ int CALLBACK WinMain(
|
|||||||
_com_ptr_t<_com_IIID<IXMLDOMDocument, &__uuidof(IXMLDOMDocument)> > doc;
|
_com_ptr_t<_com_IIID<IXMLDOMDocument, &__uuidof(IXMLDOMDocument)> > doc;
|
||||||
HRESULT hr = doc.CreateInstance(CLSID_DOMDocument60, NULL, CLSCTX_ALL);
|
HRESULT hr = doc.CreateInstance(CLSID_DOMDocument60, NULL, CLSCTX_ALL);
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
//_ftprintf(stderr, _T("CoCreateInstance(CLSID_DOMDocument2) failed (error 0x%08x).\n"), hr);
|
result = 300;
|
||||||
return 300;
|
throw com_runtime_error(hr, "CoCreateInstance(CLSID_DOMDocument2) failed");
|
||||||
}
|
}
|
||||||
doc->put_async(VARIANT_FALSE);
|
doc->put_async(VARIANT_FALSE);
|
||||||
doc->put_validateOnParse(VARIANT_FALSE);
|
doc->put_validateOnParse(VARIANT_FALSE);
|
||||||
@@ -89,19 +96,19 @@ int CALLBACK WinMain(
|
|||||||
VARIANT_BOOL succeeded = VARIANT_FALSE;
|
VARIANT_BOOL succeeded = VARIANT_FALSE;
|
||||||
hr = doc->load(_variant_t(pwcArglist[3]), &succeeded);
|
hr = doc->load(_variant_t(pwcArglist[3]), &succeeded);
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
//_ftprintf(stderr, _T("IXMLDOMDocument::load(%ls) failed (error 0x%08x).\n"), pwcArglist[3], hr);
|
result = 301;
|
||||||
return 301;
|
throw com_runtime_error(hr, string_printf("IXMLDOMDocument::load(%ls) failed", pwcArglist[3]));
|
||||||
} else if (!succeeded) {
|
} else if (!succeeded) {
|
||||||
//_ftprintf(stderr, _T("IXMLDOMDocument::load(%ls) failed.\n"), pwcArglist[3]);
|
result = 302;
|
||||||
return 302;
|
throw runtime_error(string_printf("IXMLDOMDocument::load(%ls) failed", pwcArglist[3]));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get document XML.
|
// Get document XML.
|
||||||
BSTR bstr;
|
BSTR bstr;
|
||||||
hr = doc->get_xml(&bstr);
|
hr = doc->get_xml(&bstr);
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
//_ftprintf(stderr, _T("IXMLDOMDocument::get_xml() failed (error 0x%08x).\n"), hr);
|
result = 304;
|
||||||
return 304;
|
throw com_runtime_error(hr, "IXMLDOMDocument::get_xml() failed");
|
||||||
}
|
}
|
||||||
user_data.Attach(bstr);
|
user_data.Attach(bstr);
|
||||||
}
|
}
|
||||||
@@ -110,8 +117,8 @@ int CALLBACK WinMain(
|
|||||||
DWORD dwNegotiatedVersion;
|
DWORD dwNegotiatedVersion;
|
||||||
wlan_handle wlan;
|
wlan_handle wlan;
|
||||||
if (!wlan.open(WLAN_API_MAKE_VERSION(2, 0), &dwNegotiatedVersion)) {
|
if (!wlan.open(WLAN_API_MAKE_VERSION(2, 0), &dwNegotiatedVersion)) {
|
||||||
//_ftprintf(stderr, _T("WlanOpenHandle() failed (error %u).\n"), GetLastError());
|
result = 400;
|
||||||
return 400;
|
throw win_runtime_error("WlanOpenHandle() failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get a list of WLAN interfaces.
|
// Get a list of WLAN interfaces.
|
||||||
@@ -120,11 +127,15 @@ int CALLBACK WinMain(
|
|||||||
WLAN_INTERFACE_INFO_LIST *pInterfaceList;
|
WLAN_INTERFACE_INFO_LIST *pInterfaceList;
|
||||||
DWORD dwResult = WlanEnumInterfaces(wlan, NULL, &pInterfaceList);
|
DWORD dwResult = WlanEnumInterfaces(wlan, NULL, &pInterfaceList);
|
||||||
if (dwResult != ERROR_SUCCESS) {
|
if (dwResult != ERROR_SUCCESS) {
|
||||||
//_ftprintf(stderr, _T("WlanEnumInterfaces() failed (error %u).\n"), dwResult);
|
result = 401;
|
||||||
return 401;
|
throw win_runtime_error(dwResult, "WlanEnumInterfaces() failed");
|
||||||
}
|
}
|
||||||
interfaces.reset(pInterfaceList);
|
interfaces.reset(pInterfaceList);
|
||||||
}
|
}
|
||||||
|
if (!interfaces->dwNumberOfItems) {
|
||||||
|
result = 403;
|
||||||
|
throw runtime_error("No ready WLAN interfaces found");
|
||||||
|
}
|
||||||
|
|
||||||
// Iterate over all WLAN interfaces.
|
// Iterate over all WLAN interfaces.
|
||||||
bool success = false;
|
bool success = false;
|
||||||
@@ -145,10 +156,21 @@ int CALLBACK WinMain(
|
|||||||
if (dwResult == ERROR_SUCCESS) {
|
if (dwResult == ERROR_SUCCESS) {
|
||||||
// At least one interface/profile succeeded.
|
// At least one interface/profile succeeded.
|
||||||
success = true;
|
success = true;
|
||||||
} else {
|
} else if (interactive)
|
||||||
//_ftprintf(stderr, _T("WlanSetProfileEapXmlUserData() failed (error %u).\n"), dwResult);
|
MessageBox(NULL, tstring_printf(_T("WlanSetProfileEapXmlUserData() failed: %s"), win_runtime_error(dwResult).msg().c_str()).c_str(), NULL, MB_ICONWARNING | MB_OK);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return success ? 0 : interfaces->dwNumberOfItems ? 402 : 403;
|
return success ? 0 : 402;
|
||||||
|
} catch (com_runtime_error err) {
|
||||||
|
if (interactive)
|
||||||
|
MessageBox(NULL, tstring_printf(_T("%hs: 0x%08x"), err.what(), err.number()).c_str(), NULL, MB_ICONERROR | MB_OK);
|
||||||
|
} catch (win_runtime_error err) {
|
||||||
|
if (interactive)
|
||||||
|
MessageBox(NULL, tstring_printf(_T("%hs: %s"), err.what(), err.msg().c_str()).c_str(), NULL, MB_ICONERROR | MB_OK);
|
||||||
|
} catch (exception err) {
|
||||||
|
if (interactive)
|
||||||
|
MessageBoxA(NULL, err.what(), NULL, MB_ICONERROR | MB_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
Submodule lib/WinStd updated: 5498fb0c15...a5e47313f9
Reference in New Issue
Block a user