-
- newState.PrivilegeCount = 1;
- newState.Privileges[0].Luid = luid;
- newState.Privileges[0].Attributes = (enable ? SE_PRIVILEGE_ENABLED : 0);
- ret = AdjustTokenPrivileges(hToken, FALSE, &newState, 0, NULL, NULL);
- CloseHandle(hToken);
-out:
- if (!ret) {
- fprintf(stderr, "WARNING: Failed to %s privilege %s\n",
- enable ? "enable" : "disable", privilege);
- fprintf(stderr,
- "WARNING: The program will continue, "
- "but if permission issues are\n"
- "encountered, you may need to run "
- "this program as the administrator\n");
+ int len = MultiByteToWideChar(CP_ACP,
+ MB_ERR_INVALID_CHARS,
+ mbs,
+ mbs_nbytes,
+ NULL,
+ 0);
+ if (len <= 0)
+ goto out_invalid;
+ wchar_t *wcs = malloc(len * sizeof(wchar_t));
+ if (!wcs) {
+ fwprintf(stderr, L"ERROR: out of memory!\n");
+ return NULL;