本文整理汇总了C++中GetComputerName函数的典型用法代码示例。如果您正苦于以下问题:C++ GetComputerName函数的具体用法?C++ GetComputerName怎么用?C++ GetComputerName使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetComputerName函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: printf
/*
Returns the NAME of _this_ computer.
*/
void CLANDiscovery::Computer(
char* &sz
)
{
#ifdef _DEBUG
printf("\nCLANDiscovery::Computer sz=%p\n",sz);
#endif
//
delete[] sz;
sz=NULL;
//
char szcomputername[MAX_COMPUTERNAME_LENGTH + 1];
unsigned long cnlength=sizeof(szcomputername);
//
#ifdef _UNICODE
wchar_t wszcomputername[MAX_COMPUTERNAME_LENGTH + 1];
GetComputerName(wszcomputername,&cnlength);
wcstombs(szcomputername,wszcomputername,MAX_COMPUTERNAME_LENGTH);
#else
GetComputerName(szcomputername,&cnlength);
#endif
#ifdef _DEBUG
printf("computer=%s\n",szcomputername);
#endif
//
sz=new char[cnlength+1];
if(sz==NULL)
{
log.AddLog(
_T(__FILE__),
__LINE__,
L"CLANDiscovery::Computer",
L"Memory allocation of %d bytes failed.",
cnlength+1);
return;
}
//
strcpy(sz,szcomputername);
#ifdef _DEBUG
printf("sz=%s\n",sz);
#endif
}
示例2: Sleep
// Compname nick function
char *rndnick(char *strbuf)
{
int i;
LPTSTR lpszCompName="PC";
DWORD cchBuff = 256;
BOOL NameGood = FALSE;
Sleep(13); // make sure it's random
srand(GetTickCount());
if(!GetComputerName(lpszCompName, &cchBuff))
lpszCompName="PC";
for (i=65;i<91;i++)
if (lpszCompName[0] == i)
NameGood = TRUE;
for (i=97;i<123;i++)
if (lpszCompName[0] == i)
NameGood = TRUE;
if (!NameGood)
lpszCompName="PC";
sprintf(strbuf, "%s", lpszCompName);
for (i=1;i <= maxrand;i++)
sprintf(strbuf, "%s%i", strbuf, rand()%10);
return (strbuf);
}
示例3: ZeroMemory
void CShowActiveDirUsers::GetLocalComputerName(LPTSTR szComputerName)
{
DWORD size = MAX_COMPUTERNAME_LENGTH + 1;
ZeroMemory(szComputerName, size);
GetComputerName(szComputerName, &size);
}
示例4: CLEAROUT
STDMETHODIMP TCUtilImpl::CreateObject(BSTR bstrProgID, BSTR bstrComputer,
IUnknown** ppUnk)
{
// Initialize the [out] parameter
CLEAROUT(ppUnk, (IUnknown*)NULL);
// Convert the specified ProgID to a CLSID
CLSID clsid;
if (!BSTRLen(bstrProgID))
return E_INVALIDARG;
RETURN_FAILED(CLSIDFromProgID(bstrProgID, &clsid));
// Initialize the COSERVERINFO and MULTI_QI structures
COSERVERINFO csi = {0, bstrComputer, NULL, 0};
MULTI_QI mqi[] =
{
{&IID_IUnknown , NULL, S_OK},
{&IID_IDispatch , NULL, S_OK},
{&IID_IConnectionPointContainer, NULL, S_OK},
};
const static ULONG cMQI = sizeofArray(mqi);
// Determine if the specified computer name is definitely local
bool bLocalForSure = true;
if (BSTRLen(bstrComputer))
{
TCHAR szLocal[MAX_COMPUTERNAME_LENGTH + 1];
DWORD cchLocal = sizeofArray(szLocal);
GetComputerName(szLocal, &cchLocal);
USES_CONVERSION;
bLocalForSure = !_tcsicmp(szLocal, OLE2CT(bstrComputer));
}
DWORD dwClsCtx = bLocalForSure ? CLSCTX_SERVER : CLSCTX_REMOTE_SERVER;
// Attempt to create the instance
HRESULT hr = CoCreateInstanceEx(clsid, NULL, dwClsCtx, &csi, cMQI, mqi);
if (FAILED(hr))
{
_TRACE_BEGIN
_TRACE_PART1("TCCreateObject failed: hr=0x%08X", hr);
_TRACE_PART1(", dwClsCtx=%hs", (CLSCTX_SERVER == dwClsCtx) ?
"CLSCTX_SERVER" : "CLSCTX_REMOTE_SERVER");
_TRACE_PART1(", ProgID=\"%ls\"", bstrProgID);
_TRACE_PART1(", Computer= \"%ls\"\n", bstrComputer ?
bstrComputer : L"");
_TRACE_END
return hr;
}
// Copy the IUnknown interface pointer to the [out] parameter
*ppUnk = mqi[0].pItf;
// Release each interface not being returned
for (ULONG i = 1; i < cMQI; ++i)
if (mqi[i].pItf)
mqi[i].pItf->Release();
// Return the result of the QI for IUnknown
return mqi[0].hr;
}
示例5: GetComputerName
void CTestLongNameOpen::setUpSuite()
{
// Does test share already exist?
TCHAR szUNCName[MAX_PATH] = {0};
unsigned long ulUNCPathSize = MAX_PATH;
GetComputerName(szUNCName, &ulUNCPathSize);
sLongUNC_Name.Format(sLongUNC_Name.c_str(), szUNCName);
CStdString sUNCShareName;
sUNCShareName.Format(UNC_SERVER_PART.c_str(), szUNCName);
if (!ShareExistsAndIsWriteable(sUNCShareName))
{
// You can't create shares on subst drives in XP using this method ...
// That's why it skips some tests on XP
NetworkShareHelper nsh;
m_bTestShareExists = (0 != nsh.ShareTestFolder(GET_TEST_FILE_PATH(_T(""))));
if(!m_bTestShareExists)
return;
}
m_bTestShareExists = (_taccess(sUNCShareName, 00) != -1);
CStdString sMsg;
sMsg.Format(_T("This machine must have a shared folder called 'TestShare' located at '%s'"), GET_TEST_FILE_PATH(_T("")).c_str());
assertMessageSuite(m_bTestShareExists, sMsg);
assertFileExists(sUNCTestDoc);
CopyFile(sUNCTestDoc, sLongUNC_Name, false);
assertMessageSuite(CGeneral::FileExists(sLongUNC_Name), _T("Didn't managed to copy the test file - do you have a \\testshare network share on this machine? Is it writeable?"));
}
示例6: SkipTestException
void CTestLongNameOpen::TestExtractServerNameRootDir()
{
if (!m_bTestShareExists)
throw SkipTestException(_T("The TestShare does not exist. Please create a share called TestShare"));
Gen::CFilePath wrd;
TCHAR pszShortname[MAX_PATH] = {0};
DWORD dwSize = GetShortPathName(sLongUNC_Name, pszShortname, MAX_PATH);
if(dwSize == 0)
{
assertTest(_T("Failed to extract short name") == false);
}
CStdString stServerPart;
int iRet = wrd.ExtractServerNameRootDir(pszShortname, stServerPart);
if(iRet > 0 )
{
TCHAR szUNCName[MAX_PATH] = {0};
unsigned long ulUNCPathSize = MAX_PATH;
GetComputerName(szUNCName, &ulUNCPathSize);
CStdString sUNCShareName;
sUNCShareName.Format(UNC_SERVER_PART.c_str(), szUNCName);
assertTest(stServerPart.CompareNoCase(sUNCShareName) == 0);
}
else
{
assertTest(_T("Failed to detect UNC path") == false);
}
}
示例7: get_hostname
char * get_hostname(void) {
char * computerName = (char *)palloc(sizeof(char) * (MAX_COMPUTERNAME_LENGTH + 1));
DWORD size = MAX_COMPUTERNAME_LENGTH + 1;
GetComputerName(computerName, &size);
return computerName;
}
示例8: get_os_info
bool get_os_info(os_info_t * const oi)
{
HKEY hkey;
DWORD key_type = REG_SZ;
DWORD key_size;
LONG result;
key_size = sizeof(oi->computer_name);
GetComputerName(oi->computer_name, &key_size);
result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_READ, &hkey);
if (result != ERROR_SUCCESS) {
perror("RegOpenKeyEx");
return false;
}
key_size = sizeof(oi->product_name);
RegQueryValueEx(hkey, "ProductName", 0, &key_type, (LPBYTE)oi->product_name, &key_size);
key_size = sizeof(oi->build);
RegQueryValueEx(hkey, "BuildLabEx", 0, &key_type, (LPBYTE)oi->build, &key_size);
key_size = sizeof(oi->version);
RegQueryValueEx(hkey, "CurrentVersion", 0, &key_type, (LPBYTE)oi->version, &key_size);
key_size = sizeof(oi->edition);
RegQueryValueEx(hkey, "EditionID", 0, &key_type, (LPBYTE)oi->edition, &key_size);
RegCloseKey(hkey);
return true;
}
示例9: request_core_machine_id
DWORD request_core_machine_id(Remote* pRemote, Packet* pPacket)
{
DWORD res = ERROR_SUCCESS;
Packet* pResponse = packet_create_response(pPacket);
if (pResponse)
{
wchar_t buffer[MAX_PATH];
if (GetSystemDirectory(buffer, MAX_PATH) != 0)
{
wchar_t computerName[MAX_PATH];
DWORD computerNameSize = MAX_PATH;
DWORD serialNumber;
wchar_t* backslash = wcschr(buffer, L'\\');
*(backslash + 1) = L'\0';
GetVolumeInformation(buffer, NULL, 0, &serialNumber, NULL, 0, NULL, 0);
GetComputerName(computerName, &computerNameSize);
_snwprintf_s(buffer, MAX_PATH, MAX_PATH - 1, L"%04x-%04x:%s", HIWORD(serialNumber), LOWORD(serialNumber), computerName);
packet_add_tlv_wstring(pResponse, TLV_TYPE_MACHINE_ID, buffer);
dprintf("[CORE] sending machine id: %S", buffer);
}
packet_transmit_response(res, pRemote, pResponse);
}
return ERROR_SUCCESS;
}
示例10: fillDefaultTags
void Scene::fillDefaultTags(){
char hostname[256];
#ifndef __MINGW64__
int ret=gethostname(hostname,255);
tags["user"]=getenv("USER")+string("@")+string(ret==0?hostname:"[hostname lookup failed]");
#else
// http://msdn.microsoft.com/en-us/library/ms724295%28v=vs.85%29.aspx
DWORD len=255;
int ret=GetComputerName(hostname,&len);
tags["user"]=getenv("USERNAME")+string("@")+string(ret!=0?hostname:"[hostname lookup failed]");
#endif
tags["isoTime"]=boost::posix_time::to_iso_string(boost::posix_time::second_clock::local_time());
string id=boost::posix_time::to_iso_string(boost::posix_time::second_clock::local_time())+"p"+lexical_cast<string>(
#ifndef __MINGW64__
getpid()
#else
GetCurrentProcessId()
#endif
);
tags["id"]=id;
// no title, use empty
tags["title"]="";
tags["idt"]=tags["tid"]=id;
//tags["d.id"]=tags["id.d"]=tags["d_id"]=tags["id_d"]=id;
// tags.push_back("revision="+py::extract<string>(py::import("woo.config").attr("revision"))());;
#ifdef WOO_LOOP_MUTEX_HELP
// initialize that somewhere
engineLoopMutexWaiting=false;
#endif
}
示例11: sizeof
CString CBot::SysInfo()
{ CString sSysInfo;
#ifdef WIN32
int total=GetTickCount()/1000;
MEMORYSTATUS memstat; OSVERSIONINFO verinfo;
char szBuffer[MAX_COMPUTERNAME_LENGTH + 1];
DWORD dwNameSize = MAX_COMPUTERNAME_LENGTH + 1;
char *szCompname;
TCHAR szUserName[21];
DWORD dwUserSize = sizeof(szUserName);
GlobalMemoryStatus(&memstat); verinfo.dwOSVersionInfoSize=sizeof(OSVERSIONINFO); GetVersionEx(&verinfo); char *os; char os2[140];
if(verinfo.dwMajorVersion==4 && verinfo.dwMinorVersion==0)
{ if(verinfo.dwPlatformId==VER_PLATFORM_WIN32_WINDOWS) os="95";
if(verinfo.dwPlatformId==VER_PLATFORM_WIN32_NT) os="NT"; }
else if(verinfo.dwMajorVersion==4 && verinfo.dwMinorVersion==10) os="98";
else if(verinfo.dwMajorVersion==4 && verinfo.dwMinorVersion==90) os="ME";
else if(verinfo.dwMajorVersion==5 && verinfo.dwMinorVersion==0) os="2000";
else if(verinfo.dwMajorVersion==5 && verinfo.dwMinorVersion==1) os="XP";
else if(verinfo.dwMajorVersion==5 && verinfo.dwMinorVersion==2) os="2003";
else os="???";
if(verinfo.dwPlatformId==VER_PLATFORM_WIN32_NT && verinfo.szCSDVersion[0]!='\0')
{ sprintf(os2, "%s [%s]", os, verinfo.szCSDVersion); os=os2; }
GetComputerName(szBuffer, &dwNameSize);
szCompname = szBuffer;
GetUserName(szUserName, &dwUserSize);
// *** PhaTTy <MOD> Changed ram: to ##MB/##MB , added box: , added user: </MOD>
sSysInfo.Format("cpu: %dMHz ram: %dMB/%dMB os: %s (%d.%d, build %d) uptime: %dd %dh %dm box: %s user: %s freespace: %s",
cpuspeed(), memstat.dwAvailPhys/1046528, memstat.dwTotalPhys/1046528, os, verinfo.dwMajorVersion, verinfo.dwMinorVersion, verinfo.dwBuildNumber, total/86400, (total%86400)/3600, ((total%86400)%3600)/60, szCompname, szUserName , GetFreeDiskSpace().CStr());
#else
FILE *fp=fopen("/proc/uptime", "r");
float f1, f2;
if(!fp) return CString("Error: Can't open /proc/uptime!");
if(fscanf(fp, "%f %f", &f1, &f2)<2) return CString("Error: Invalid or changed /proc/uptime format!");
fclose(fp);
int days, hours, minutes;
days=((abs((int)f1)/60)/60)/24;
hours=((abs((int)f1)/60)/60)%24;
minutes=(abs((int)f1)/60)%60;
int iDistro=GetDistro(); char *szVersion; char *szKVersion;
bool bGotVer=GetVersion(&szVersion, iDistro);
bool bGotKVer=GetKVersion(&szKVersion, iDistro);
if(!bGotVer) szVersion="Unknown\n"; if(!bGotKVer) szKVersion="Unknown\n";
sSysInfo.Format("cpu: %dMHz. os: %s. kernel: %s. uptime: %dd %dh %dm", cpuspeed(), szVersion, szKVersion, days, hours, minutes);
if(bGotVer) free(szVersion); if(bGotKVer) free(szKVersion);
#endif
return sSysInfo; }
示例12: get_random_info
void get_random_info(unsigned char seed[16])
{
MD5_CTX c;
typedef struct {
MEMORYSTATUS m;
SYSTEM_INFO s;
FILETIME t;
LARGE_INTEGER pc;
DWORD tc;
DWORD l;
char hostname[MAX_COMPUTERNAME_LENGTH + 1];
} randomness;
randomness r;
/* Initialize memory area so that valgrind does not complain */
memset(&r, 0, sizeof r);
/* memory usage stats */
GlobalMemoryStatus( &r.m );
/* random system stats */
GetSystemInfo( &r.s );
/* 100ns resolution (nominally) time of day */
GetSystemTimeAsFileTime( &r.t );
/* high resolution performance counter */
QueryPerformanceCounter( &r.pc );
/* milliseconds since last boot */
r.tc = GetTickCount();
r.l = MAX_COMPUTERNAME_LENGTH + 1;
GetComputerName( r.hostname, &r.l );
/* MD5 it */
MD5Init(&c);
MD5Update(&c, (unsigned char *)(&r), sizeof r);
MD5Final(seed, &c);
};
示例13: w32_gethostname
static int
w32_gethostname (char *name, size_t len)
{
/* We could try the WinSock API gethostname, but that will
fail if WSAStartup function has has not been called. We don't
really need a name that will be understood by socket API, so avoid
unnecessary dependence on WinSock libraries by using
GetComputerName instead. */
/* On Win9x GetComputerName fails if the input size is less
than MAX_COMPUTERNAME_LENGTH + 1. */
char buffer[MAX_COMPUTERNAME_LENGTH + 1];
DWORD size = sizeof (buffer);
if (!GetComputerName (buffer, &size))
return -1;
if ((size = strlen (buffer) + 1) > len)
{
errno = EINVAL;
/* Truncate as per POSIX spec. We do not NUL-terminate. */
size = len;
}
memcpy (name, buffer, (size_t) size);
return 0;
}
示例14: SVMlibParse
void WINAPI SVMlibParse(int* argc,char **argv,HostData *actHost) {
char *Port=0,*Display=0;
ConfContext *Context=0;
if(!actHost->ProcData || !actHost->ProcData->Context) {
Context = (ConfContext*)EProcs.GetContext(actHost,sizeof(ConfContext));
initContext(Context);
} else Context = (ConfContext*)actHost->ProcData->Context;
Context->StartServer = IsArgPresent(argc,argv,"-mpe");
if(Context->StartServer) {
DWORD size = 256;
GetComputerName(Context->Display,&size);
}
if(IsArgPresent(argc,argv,"-alog"))
Context->LogFormat = 2;
if(IsArgPresent(argc,argv,"-clog"))
Context->LogFormat = 1;
if(IsArgPresent(argc,argv,"-slog"))
Context->LogFormat = 0;
GetStringArg(argc,argv,"-display",&Display);
GetStringArg(argc,argv,"-port",&Port);
if(Port)
strcpy(Context->Port,Port);
if(Display)
strcpy(Context->Display,Display);
}
示例15: sizeof
// ----------------------------------------------------------------------------
//
void DMXStudio::showIpAddress()
{
char cpuName [128] ;
DWORD dwSize = sizeof(cpuName);
WSADATA wsaData;
int iResult;
if ( GetComputerName( cpuName, &dwSize) == 0 )
return;
// Initialize Winsock
iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (iResult == 0) {
PADDRINFOA pAddrInfo;
iResult = getaddrinfo( cpuName, "http", NULL, &pAddrInfo );
if ( iResult == 0 ) {
for ( PADDRINFOA pAddr=pAddrInfo; pAddr != NULL; pAddr=pAddr->ai_next ) {
if ( AF_INET == pAddr->ai_family ) {
struct sockaddr_in *sockaddr_ipv4;
sockaddr_ipv4 = (struct sockaddr_in *) pAddr->ai_addr;
log_status( "%s IP address %s", cpuName, inet_ntoa(sockaddr_ipv4->sin_addr) );
}
}
freeaddrinfo( pAddrInfo );
}
}
WSACleanup();
}