Untitled
unknown
plain_text
8 months ago
1.5 kB
1
Indexable
Never
#include <windows.h> #include <iostream> #include <comdef.h> #include <activeds.h> int main() { HRESULT hr = S_OK; IADsUser *pUser = NULL; IDirectoryObject *pDirObj = NULL; VARIANT var; // Initialize COM hr = CoInitialize(NULL); if (FAILED(hr)) { std::cerr << "COM initialization failed: " << _com_error(hr).ErrorMessage() << std::endl; return hr; } // Bind to the user object hr = ADsGetObject(L"LDAP://CN=User,CN=Users,DC=domain,DC=com", IID_IDirectoryObject, (void**)&pDirObj); if (FAILED(hr)) { std::cerr << "Failed to bind to user object: " << _com_error(hr).ErrorMessage() << std::endl; CoUninitialize(); return hr; } // Query for the IADsUser interface hr = pDirObj->QueryInterface(IID_IADsUser, (void**)&pUser); pDirObj->Release(); // Release the IDirectoryObject interface if (FAILED(hr)) { std::cerr << "Failed to get IADsUser interface: " << _com_error(hr).ErrorMessage() << std::endl; CoUninitialize(); return hr; } // Disable the user VariantInit(&var); V_VT(&var) = VT_BOOL; V_BOOL(&var) = VARIANT_TRUE; // Set to TRUE to disable the account hr = pUser->put_AccountDisabled(var); if (FAILED(hr)) { std::cerr << "Failed to disable user: " << _com_error(hr).ErrorMessage() << std::endl; } else { std::cout << "User disabled successfully." << std::endl; } // Release resources pUser->Release(); CoUninitialize(); return hr; }
Leave a Comment