|
6 | 6 | */ |
7 | 7 |
|
8 | 8 | #include "precomp.h" |
| 9 | +#include <lmcons.h> |
| 10 | +#include <lmapibuf.h> |
| 11 | +#include <lmaccess.h> |
| 12 | +#include <secext.h> |
9 | 13 |
|
10 | 14 | WINE_DEFAULT_DEBUG_CHANNEL(shell); |
11 | 15 |
|
@@ -1485,3 +1489,64 @@ SHELL_CreateShell32DefaultExtractIcon(int IconIndex, REFIID riid, LPVOID *ppvOut |
1485 | 1489 | initIcon->SetNormalIcon(swShell32Name, IconIndex); |
1486 | 1490 | return initIcon->QueryInterface(riid, ppvOut); |
1487 | 1491 | } |
| 1492 | + |
| 1493 | +/************************************************************************* |
| 1494 | + * SHGetUserDisplayName [SHELL32.241] |
| 1495 | + * |
| 1496 | + * @see https://undoc.airesoft.co.uk/shell32.dll/SHGetUserDisplayName.php |
| 1497 | + */ |
| 1498 | +EXTERN_C |
| 1499 | +HRESULT WINAPI |
| 1500 | +SHGetUserDisplayName( |
| 1501 | + _Out_writes_to_(*puSize, *puSize) PWSTR pName, |
| 1502 | + _Inout_ PULONG puSize) |
| 1503 | +{ |
| 1504 | + if (!pName || !puSize) |
| 1505 | + return E_INVALIDARG; |
| 1506 | + |
| 1507 | + if (GetUserNameExW(NameDisplay, pName, puSize)) |
| 1508 | + return S_OK; |
| 1509 | + |
| 1510 | + LONG error = GetLastError(); // for ERROR_NONE_MAPPED |
| 1511 | + HRESULT hr = HRESULT_FROM_WIN32(error); |
| 1512 | + |
| 1513 | + WCHAR UserName[MAX_PATH]; |
| 1514 | + DWORD cchUserName = _countof(UserName); |
| 1515 | + if (!GetUserNameW(UserName, &cchUserName)) |
| 1516 | + return HRESULT_FROM_WIN32(GetLastError()); |
| 1517 | + |
| 1518 | + // Was the user name not available in the specified format (NameDisplay)? |
| 1519 | + if (error == ERROR_NONE_MAPPED) |
| 1520 | + { |
| 1521 | + // Try to get the user name by using Network API |
| 1522 | + PUSER_INFO_2 UserInfo; |
| 1523 | + DWORD NetError = NetUserGetInfo(NULL, UserName, 2, (PBYTE*)&UserInfo); |
| 1524 | + if (NetError) |
| 1525 | + { |
| 1526 | + hr = HRESULT_FROM_WIN32(NetError); |
| 1527 | + } |
| 1528 | + else |
| 1529 | + { |
| 1530 | + if (UserInfo->usri2_full_name) |
| 1531 | + { |
| 1532 | + hr = StringCchCopyW(pName, *puSize, UserInfo->usri2_full_name); |
| 1533 | + if (SUCCEEDED(hr)) |
| 1534 | + { |
| 1535 | + // Include the NUL-terminator |
| 1536 | + *puSize = lstrlenW(UserInfo->usri2_full_name) + 1; |
| 1537 | + } |
| 1538 | + } |
| 1539 | + |
| 1540 | + NetApiBufferFree(UserInfo); |
| 1541 | + } |
| 1542 | + } |
| 1543 | + |
| 1544 | + if (FAILED(hr)) |
| 1545 | + { |
| 1546 | + hr = StringCchCopyW(pName, *puSize, UserName); |
| 1547 | + if (SUCCEEDED(hr)) |
| 1548 | + *puSize = cchUserName; |
| 1549 | + } |
| 1550 | + |
| 1551 | + return hr; |
| 1552 | +} |
0 commit comments