Sunday, 27 November 2016

C++ Get Username PC

// Borland C++ 5.0: bcc32.cpp getusername.cpp
// Visual C++ 5.0: cl getusername.cpp advapi32.lib
//
// This sample program is hereby placed in the public domain.

#include
#include

int main()
{
    char acUserName[100];
    DWORD nUserName = sizeof(acUserName);
    if (GetUserName(acUserName, &nUserName)) {
        cout << "Bekabe | Username komputer: " << acUserName << "." << endl;
    }
    else {
        cerr << "Bekabe | Gagal melihat username, error pada: " <<
                GetLastError() << "." << endl;
    }

    return 0;
}

No comments: