forked from frutiger/credutils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delcred.cpp
47 lines (39 loc) · 1.45 KB
/
delcred.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// readcred.cpp
#include <iostream>
#include <string>
#include <windows.h>
#include <wincred.h>
int main(int argc, char *argv[])
{
if (2 > argc) {
std::cerr << "Usage: " << argv[0] << " <credential-name>\n";
return -1; // RETURN
}
int utf8Len = std::char_traits<char>::length(argv[1]);
int utf16Len = ::MultiByteToWideChar(CP_UTF8,
MB_ERR_INVALID_CHARS,
argv[1],
utf8Len,
0,
0);
if (0 == utf16Len) {
std::cerr << "Failed to encode credential name\n";
return -1; // RETURN
}
std::wstring utf16Target;
utf16Target.resize(utf16Len + 1);
::MultiByteToWideChar(CP_UTF8,
MB_ERR_INVALID_CHARS,
argv[1],
utf8Len,
&utf16Target[0],
utf16Target.length());
CREDENTIALW *credential;
if (FALSE == ::CredDeleteW(utf16Target.c_str(),
CRED_TYPE_GENERIC,
0)) {
std::cerr << "Could not delete credential\n";
return -1; // RETURN
}
return 0;
}