Hallo und Guten Abend
Mit folgendem Programm möchte ich unter Windows NT oder 2000
den Computernamen und Usernamen ermitteln.
Den Computernamen erhalte ich, aber beim Aufruf von GetUserName erhalte ich immer Fehler 122
Programmiert mit Visual C++ 6.0
wer weiss Rat
Gruß und Danke
G.F.
#s „stdafx.h“
#include
#include
#include
#include
#define BUFSIZE 8192
int main(int argc, char* argv[])
{
LPTSTR lpszSystemInfo; // pointer to system information string
DWORD cchBuff = BUFSIZE; // size of computer or user name
TCHAR tchBuffer[BUFSIZE]; // buffer for string
DWORD fehler;
lpszSystemInfo = tchBuffer;
// Get and display the name of the computer.
if( GetComputerName(lpszSystemInfo, &cchBuff) )
printf("Computer name: %s ", lpszSystemInfo);
if( GetUserName(lpszSystemInfo, &cchBuff) )
printf("User name: %s ", lpszSystemInfo);
else
{
fehler = GetLastError();
printf(„Fehler : %d\n“,fehler);
}
return 0;
}