static HRESULT get_owner( VARIANT *user, VARIANT *domain, VARIANT *retval ) { DWORD len; UINT error = 8; len = 0; GetUserNameW( NULL, &len ); if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) goto done; if (!(V_BSTR( user ) = SysAllocStringLen( NULL, len - 1 ))) goto done; if (!GetUserNameW( V_BSTR( user ), &len )) goto done; V_VT( user ) = VT_BSTR; len = 0; GetComputerNameW( NULL, &len ); if (GetLastError() != ERROR_BUFFER_OVERFLOW) goto done; if (!(V_BSTR( domain ) = SysAllocStringLen( NULL, len - 1 ))) goto done; if (!GetComputerNameW( V_BSTR( domain ), &len )) goto done; V_VT( domain ) = VT_BSTR; error = 0; done: if (error) { VariantClear( user ); VariantClear( domain ); } set_variant( VT_UI4, error, NULL, retval ); return S_OK; }
static void test_GetComputerName(void) { DWORD size; BOOL ret; LPSTR name; LPWSTR nameW; DWORD error; int name_len; size = 0; ret = GetComputerNameA((LPSTR)0xdeadbeef, &size); error = GetLastError(); ok(!ret && error == ERROR_BUFFER_OVERFLOW, "GetComputerNameA should have failed with ERROR_BUFFER_OVERFLOW instead of %d\n", error); /* Only Vista returns the computer name length as documented in the MSDN */ if (size != 0) { size++; /* nul terminating character */ name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(name[0])); ok(name != NULL, "HeapAlloc failed with error %d\n", GetLastError()); ret = GetComputerNameA(name, &size); ok(ret, "GetComputerNameA failed with error %d\n", GetLastError()); HeapFree(GetProcessHeap(), 0, name); } size = MAX_COMPUTERNAME_LENGTH + 1; name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(name[0])); ok(name != NULL, "HeapAlloc failed with error %d\n", GetLastError()); ret = GetComputerNameA(name, &size); ok(ret, "GetComputerNameA failed with error %d\n", GetLastError()); trace("computer name is \"%s\"\n", name); name_len = strlen(name); ok(size == name_len, "size should be same as length, name_len=%d, size=%d\n", name_len, size); HeapFree(GetProcessHeap(), 0, name); size = 0; SetLastError(0xdeadbeef); ret = GetComputerNameW((LPWSTR)0xdeadbeef, &size); error = GetLastError(); if (error == ERROR_CALL_NOT_IMPLEMENTED) win_skip("GetComputerNameW is not implemented\n"); else { ok(!ret && error == ERROR_BUFFER_OVERFLOW, "GetComputerNameW should have failed with ERROR_BUFFER_OVERFLOW instead of %d\n", error); size++; /* nul terminating character */ nameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(nameW[0])); ok(nameW != NULL, "HeapAlloc failed with error %d\n", GetLastError()); ret = GetComputerNameW(nameW, &size); ok(ret, "GetComputerNameW failed with error %d\n", GetLastError()); HeapFree(GetProcessHeap(), 0, nameW); } }
bool CRootNode::SetupNode() { // Load the bitmap we'll be using as the root image HBITMAP hRootImage; hRootImage = LoadBitmapW(g_hThisInstance, MAKEINTRESOURCEW(IDB_ROOT_IMAGE)); if (hRootImage == NULL) return FALSE; // Add this bitmap to the device image list. This is a bit hacky, but it's safe m_ClassImage = ImageList_Add(m_ImageListData->ImageList, hRootImage, NULL); DeleteObject(hRootImage); // Get the root instance CONFIGRET cr; cr = CM_Locate_DevNodeW(&m_DevInst, NULL, CM_LOCATE_DEVNODE_NORMAL); if (cr != CR_SUCCESS) { return false; } // The root name is the computer name DWORD Size = DISPLAY_NAME_LEN; GetComputerNameW(m_DisplayName, &Size); return true; }
VOID LogfReportEvent(USHORT wType, USHORT wCategory, ULONG dwEventId, USHORT wNumStrings, PWSTR pStrings, ULONG dwDataSize, PVOID pRawData) { NTSTATUS Status; UNICODE_STRING SourceName, ComputerName; PEVENTLOGRECORD LogBuffer; LARGE_INTEGER SystemTime; ULONG Time; SIZE_T RecSize; DWORD dwComputerNameLength; WCHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 1]; if (!EventLogSource) return; RtlInitUnicodeString(&SourceName, EventLogSource->szName); dwComputerNameLength = ARRAYSIZE(szComputerName); if (!GetComputerNameW(szComputerName, &dwComputerNameLength)) szComputerName[0] = L'\0'; RtlInitUnicodeString(&ComputerName, szComputerName); NtQuerySystemTime(&SystemTime); RtlTimeToSecondsSince1970(&SystemTime, &Time); LogBuffer = LogfAllocAndBuildNewRecord(&RecSize, Time, wType, wCategory, dwEventId, &SourceName, &ComputerName, 0, NULL, wNumStrings, pStrings, dwDataSize, pRawData); if (LogBuffer == NULL) { DPRINT1("LogfAllocAndBuildNewRecord failed!\n"); return; } Status = LogfWriteRecord(EventLogSource->LogFile, LogBuffer, RecSize); if (!NT_SUCCESS(Status)) { DPRINT1("ERROR writing to event log `%S' (Status 0x%08lx)\n", EventLogSource->LogFile->LogName, Status); } LogfFreeRecord(LogBuffer); }
static VOID SetDomainComboBox( HWND hwndDomainComboBox, PGINA_CONTEXT pgContext) { WCHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 1]; DWORD dwComputerNameLength; LONG lIndex = 0; LONG lFindIndex; SendMessageW(hwndDomainComboBox, CB_RESETCONTENT, 0, 0); dwComputerNameLength = sizeof(szComputerName) / sizeof(WCHAR); if (GetComputerNameW(szComputerName, &dwComputerNameLength)) { lIndex = SendMessageW(hwndDomainComboBox, CB_ADDSTRING, 0, (LPARAM)szComputerName); } if (wcslen(pgContext->Domain) != 0) { lFindIndex = SendMessageW(hwndDomainComboBox, CB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)pgContext->Domain); if (lFindIndex == CB_ERR) { lIndex = SendMessageW(hwndDomainComboBox, CB_ADDSTRING, 0, (LPARAM)pgContext->Domain); } else { lIndex = lFindIndex; } } SendMessageW(hwndDomainComboBox, CB_SETCURSEL, lIndex, 0); }
static HRESULT WINAPI MSTASK_ITaskScheduler_SetTargetComputer( ITaskScheduler* iface, LPCWSTR pwszComputer) { TaskSchedulerImpl *This = impl_from_ITaskScheduler(iface); WCHAR buffer[MAX_COMPUTERNAME_LENGTH + 3]; /* extra space for two '\' and a zero */ DWORD len = MAX_COMPUTERNAME_LENGTH + 1; /* extra space for a zero */ TRACE("(%p)->(%s)\n", This, debugstr_w(pwszComputer)); /* NULL is an alias for the local computer */ if (!pwszComputer) return S_OK; buffer[0] = '\\'; buffer[1] = '\\'; if (GetComputerNameW(buffer + 2, &len)) { if (!lstrcmpiW(buffer, pwszComputer) || /* full unc name */ !lstrcmpiW(buffer + 2, pwszComputer)) /* name without backslash */ return S_OK; } FIXME("remote computer %s not supported\n", debugstr_w(pwszComputer)); return HRESULT_FROM_WIN32(ERROR_BAD_NETPATH); }
static HRESULT WINAPI MSTASK_ITaskScheduler_GetTargetComputer( ITaskScheduler* iface, LPWSTR *ppwszComputer) { TaskSchedulerImpl *This = impl_from_ITaskScheduler(iface); LPWSTR buffer; DWORD len = MAX_COMPUTERNAME_LENGTH + 1; /* extra space for the zero */ TRACE("(%p)->(%p)\n", This, ppwszComputer); if (!ppwszComputer) return E_INVALIDARG; /* extra space for two '\' and a zero */ buffer = CoTaskMemAlloc((MAX_COMPUTERNAME_LENGTH + 3) * sizeof(WCHAR)); if (buffer) { buffer[0] = '\\'; buffer[1] = '\\'; if (GetComputerNameW(buffer + 2, &len)) { *ppwszComputer = buffer; return S_OK; } CoTaskMemFree(buffer); } *ppwszComputer = NULL; return HRESULT_FROM_WIN32(GetLastError()); }
/*********************************************************************** * GetComputerNameA (KERNEL32.@) */ BOOL WINAPI GetComputerNameA(LPSTR name, LPDWORD size) { WCHAR nameW[ MAX_COMPUTERNAME_LENGTH + 1 ]; DWORD sizeW = MAX_COMPUTERNAME_LENGTH + 1; unsigned int len; BOOL ret; if ( !GetComputerNameW (nameW, &sizeW) ) return FALSE; len = WideCharToMultiByte ( CP_ACP, 0, nameW, -1, NULL, 0, NULL, 0 ); /* for compatibility with Win9x */ __TRY { if ( *size < len ) { *size = len; SetLastError( ERROR_BUFFER_OVERFLOW ); ret = FALSE; } else { WideCharToMultiByte ( CP_ACP, 0, nameW, -1, name, len, NULL, 0 ); *size = len - 1; ret = TRUE; } } __EXCEPT_PAGE_FAULT { SetLastError( ERROR_INVALID_PARAMETER ); ret = FALSE; } __ENDTRY return ret; }
DWORD AuditUserA( LPCSTR lpUser, LPCSTR lpPasswd ) { DWORD dwRetCode; WCHAR szwComputer[CNLEN+1]; WCHAR szwComputerName[CNLEN+3]; DWORD cbComputer; WCHAR szwUser[UNLEN]; WCHAR szwOldPasswd[PWLEN]; WCHAR szwNewPasswd[PWLEN]; if( lpUser == NULL || lpPasswd == NULL ) return ERROR_INVALID_PARAMETER; cbComputer = CNLEN+1; GetComputerNameW( szwComputer, &cbComputer ); cbComputer = CNLEN+3; MakeComputerNameW( szwComputer, szwComputerName, &cbComputer ); mbstowcs( szwUser, lpUser, UNLEN ); mbstowcs( szwOldPasswd, lpPasswd, PWLEN ); mbstowcs( szwNewPasswd, lpPasswd, UNLEN ); dwRetCode = NetUserChangePassword( szwComputerName, szwUser, szwOldPasswd, szwNewPasswd ); return dwRetCode; }
/// Gets the hostname of the current machine. /// /// @param hostname Buffer to store the hostname. /// @param size Size of `hostname`. void os_get_hostname(char *hostname, size_t size) { #ifdef HAVE_SYS_UTSNAME_H struct utsname vutsname; if (uname(&vutsname) < 0) { *hostname = '\0'; } else { xstrlcpy(hostname, vutsname.nodename, size); } #elif defined(WIN32) wchar_t host_utf16[MAX_COMPUTERNAME_LENGTH + 1]; DWORD host_wsize = sizeof(host_utf16) / sizeof(host_utf16[0]); if (GetComputerNameW(host_utf16, &host_wsize) == 0) { *hostname = '\0'; DWORD err = GetLastError(); EMSG2("GetComputerNameW failed: %d", err); return; } host_utf16[host_wsize] = '\0'; char *host_utf8; int conversion_result = utf16_to_utf8(host_utf16, &host_utf8); if (conversion_result != 0) { EMSG2("utf16_to_utf8 failed: %d", conversion_result); return; } xstrlcpy(hostname, host_utf8, size); xfree(host_utf8); #else EMSG("os_get_hostname failed: missing uname()"); *hostname = '\0'; #endif }
wstring query_hostname() { unsigned long bufLen = MAX_COMPUTERNAME_LENGTH + 1; wchar_t buf[bufLen]; memset(buf, 0, sizeof(wchar_t) * bufLen); GetComputerNameW(buf, &bufLen); return wstring(buf); }
std::string gethostname() { DWORD dwBufferSize = MAX_COMPUTERNAME_LENGTH + 1; WCHAR chrComputerName[MAX_COMPUTERNAME_LENGTH + 1]; if (GetComputerNameW(chrComputerName, &dwBufferSize)) { return boost::filesystem::path((WCHAR *)chrComputerName, qi::unicodeFacet()).string(qi::unicodeFacet()); } return std::string(); }
std::string EnvironmentImpl::nodeNameImpl() { wchar_t name[MAX_COMPUTERNAME_LENGTH + 1]; DWORD size = MAX_COMPUTERNAME_LENGTH + 1; if (GetComputerNameW(name, &size) == 0) throw SystemException("Cannot get computer name"); std::string result; UnicodeConverter::toUTF8(name, result); return result; }
static DWORD WINAPI mstsc_ProtocolIOThread ( LPVOID lpArgument ) { RDPCLIENT * This = static_cast<RDPCLIENT *>(lpArgument); WCHAR hostname[MAX_COMPUTERNAME_LENGTH + 1]; DWORD dw = ARRAYSIZE(hostname); GetComputerNameW(hostname, &dw); uint32 flags = RDP_LOGON_NORMAL | RDP_LOGON_COMPRESSION | RDP_LOGON_COMPRESSION2; rdp_connect(This, "10.0.0.3", flags, L"Administrator", L"", L"", L"", L"", hostname, ""); //rdp_connect(This, "192.168.7.232", flags, "", "", "", ""); hdcBuffer = CreateCompatibleDC(NULL); BITMAPINFO bmi; bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader); bmi.bmiHeader.biWidth = This->width; bmi.bmiHeader.biHeight = This->height; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biBitCount = This->server_depth; bmi.bmiHeader.biCompression = BI_RGB; bmi.bmiHeader.biSizeImage = 0; bmi.bmiHeader.biXPelsPerMeter = 0; bmi.bmiHeader.biYPelsPerMeter = 0; bmi.bmiHeader.biClrUsed = 0; // TODO! palette displays bmi.bmiHeader.biClrImportant = 0; // TODO! palette displays hbmBuffer = CreateDIBSection(hdcBuffer, &bmi, DIB_RGB_COLORS, &pBuffer, NULL, 0); SelectObject(hdcBuffer, hbmBuffer); #if 0 rcClip.left = 0; rcClip.top = 0; rcClip.right = This->width + 1; rcClip.bottom = This->height + 1; #endif BOOL deactivated; uint32 ext_disc_reason; rdp_main_loop(This, &deactivated, &ext_disc_reason); // TODO: handle redirection // EVENT: OnDisconnect SendMessage(hwnd, WM_CLOSE, 0, 0); return 0; }
/************************************************************ * NetServerGetInfo (NETAPI32.@) */ NET_API_STATUS WINAPI NetServerGetInfo(LMSTR servername, DWORD level, LPBYTE* bufptr) { NET_API_STATUS ret; TRACE("%s %d %p\n", debugstr_w( servername ), level, bufptr ); if (servername) { if (!NETAPI_IsLocalComputer(servername)) { FIXME("remote computers not supported\n"); return ERROR_INVALID_LEVEL; } } if (!bufptr) return ERROR_INVALID_PARAMETER; switch (level) { case 100: case 101: { DWORD computerNameLen, size; WCHAR computerName[MAX_COMPUTERNAME_LENGTH + 1]; computerNameLen = MAX_COMPUTERNAME_LENGTH + 1; GetComputerNameW(computerName, &computerNameLen); computerNameLen++; /* include NULL terminator */ size = sizeof(SERVER_INFO_101) + computerNameLen * sizeof(WCHAR); ret = NetApiBufferAllocate(size, (LPVOID *)bufptr); if (ret == NERR_Success) { /* INFO_100 structure is a subset of INFO_101 */ PSERVER_INFO_101 info = (PSERVER_INFO_101)*bufptr; OSVERSIONINFOW verInfo; info->sv101_platform_id = PLATFORM_ID_NT; info->sv101_name = (LMSTR)(*bufptr + sizeof(SERVER_INFO_101)); memcpy(info->sv101_name, computerName, computerNameLen * sizeof(WCHAR)); verInfo.dwOSVersionInfoSize = sizeof(verInfo); GetVersionExW(&verInfo); info->sv101_version_major = verInfo.dwMajorVersion; info->sv101_version_minor = verInfo.dwMinorVersion; /* Use generic type as no wine equivalent of DC / Server */ info->sv101_type = SV_TYPE_NT; info->sv101_comment = NULL; } break; } default: FIXME("level %d unimplemented\n", level); ret = ERROR_INVALID_LEVEL; } return ret; }
static BOOL is_local_machine( const WCHAR *server ) { static const WCHAR dotW[] = {'.',0}; WCHAR buffer[MAX_COMPUTERNAME_LENGTH + 1]; DWORD len = sizeof(buffer) / sizeof(buffer[0]); if (!server || !strcmpW( server, dotW )) return TRUE; if (GetComputerNameW( buffer, &len ) && !strcmpiW( server, buffer )) return TRUE; return FALSE; }
/*********************************************************************** * GetComputerNameExW (KERNEL32.@) */ BOOL WINAPI GetComputerNameExW( COMPUTER_NAME_FORMAT type, LPWSTR name, LPDWORD size ) { char buf[256]; int len = sizeof(buf) - 1, ret; TRACE("%d, %p, %p\n", type, name, size); switch( type ) { case ComputerNameNetBIOS: case ComputerNamePhysicalNetBIOS: ret = GetComputerNameW (name, size); if (!ret && GetLastError() == ERROR_BUFFER_OVERFLOW) SetLastError( ERROR_MORE_DATA ); return ret; case ComputerNameDnsHostname: case ComputerNamePhysicalDnsHostname: ret = dns_hostname (buf, &len); break; case ComputerNameDnsDomain: case ComputerNamePhysicalDnsDomain: ret = dns_domainname (buf, &len); break; case ComputerNameDnsFullyQualified: case ComputerNamePhysicalDnsFullyQualified: ret = dns_fqdn (buf, &len); break; default: SetLastError (ERROR_INVALID_PARAMETER); return FALSE; } if ( ret ) { unsigned int lenW; TRACE ("-> %s (%d)\n", debugstr_a (buf), len); lenW = MultiByteToWideChar( CP_ACP, 0, buf, len, NULL, 0 ); if ( *size < lenW + 1 ) { *size = lenW + 1; SetLastError( ERROR_MORE_DATA ); ret = FALSE; } else { MultiByteToWideChar( CP_ACP, 0, buf, len, name, lenW ); name[lenW] = 0; *size = lenW; ret = TRUE; } } return ret; }
VOID LogfReportEvent(WORD wType, WORD wCategory, DWORD dwEventId, WORD wNumStrings, WCHAR *lpStrings, DWORD dwDataSize, LPVOID lpRawData) { WCHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 1]; DWORD dwComputerNameLength = MAX_COMPUTERNAME_LENGTH + 1; PEVENTSOURCE pEventSource = NULL; PBYTE logBuffer; DWORD lastRec; DWORD recSize; DWORD dwError; if (!GetComputerNameW(szComputerName, &dwComputerNameLength)) { szComputerName[0] = 0; } pEventSource = GetEventSourceByName(L"EventLog"); if (pEventSource == NULL) { return; } lastRec = LogfGetCurrentRecord(pEventSource->LogFile); logBuffer = LogfAllocAndBuildNewRecord(&recSize, lastRec, wType, wCategory, dwEventId, pEventSource->szName, (LPCWSTR)szComputerName, 0, NULL, wNumStrings, lpStrings, dwDataSize, lpRawData); dwError = LogfWriteData(pEventSource->LogFile, recSize, logBuffer); if (!dwError) { DPRINT1("ERROR WRITING TO EventLog %S\n", pEventSource->LogFile->FileName); } LogfFreeRecord(logBuffer); }
WideString DeviceInfo::GetName() { //http://msdn.microsoft.com/en-us/library/windows/desktop/ms724295(v=vs.85).aspx char16 compName[MAX_COMPUTERNAME_LENGTH + 1]; uint32 length = MAX_COMPUTERNAME_LENGTH + 1; bool nameRecieved = GetComputerNameW(compName, (LPDWORD) &length) != FALSE; if(nameRecieved) { return WideString(compName, length); } return WideString (); }
static BOOL LsapIsLocalComputer(PLSA_UNICODE_STRING ServerName) { DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1; BOOL Result; LPWSTR buf; if (ServerName == NULL || ServerName->Length == 0 || ServerName->Buffer == NULL) return TRUE; buf = HeapAlloc(GetProcessHeap(), 0, dwSize * sizeof(WCHAR)); Result = GetComputerNameW(buf, &dwSize); if (Result && (ServerName->Buffer[0] == '\\') && (ServerName->Buffer[1] == '\\')) ServerName += 2; Result = Result && !lstrcmpW(ServerName->Buffer, buf); HeapFree(GetProcessHeap(), 0, buf); return Result; }
static LPWSTR GetPathRoot(HWND hwndTV, HTREEITEM hItem, BOOL bFull) { LPCWSTR parts[2] = {0,0}; WCHAR text[260]; HKEY hRootKey = NULL; if (!hItem) hItem = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_CARET, 0); HeapFree(GetProcessHeap(), 0, GetItemPath(hwndTV, hItem, &hRootKey)); if (!bFull && !hRootKey) return NULL; if (hRootKey) parts[1] = GetRootKeyName(hRootKey); if (bFull) { DWORD dwSize = sizeof(text)/sizeof(WCHAR); GetComputerNameW(text, &dwSize); parts[0] = text; } return CombinePaths(parts, 2); }
QString SystemInfo::getComputerName(){ qDebug()<<"--SystemInfo::getComputerName()"; QString computerName = ""; DWORD size = MAX_COMPUTERNAME_LENGTH + 1; LPWSTR name = new wchar_t[size]; if(GetComputerNameW(name, &size)){ computerName = QString::fromWCharArray(name); }else{ QMessageBox::critical(this, tr("Error"), tr("Can not get computer name! Error: %1").arg(GetLastError())); } delete [] name; return computerName.toLower(); }
static HRESULT WINAPI TaskService_Connect(ITaskService *iface, VARIANT server, VARIANT user, VARIANT domain, VARIANT password) { TaskService *task_svc = impl_from_ITaskService(iface); WCHAR comp_name[MAX_COMPUTERNAME_LENGTH + 1]; DWORD len; TRACE("%p,%s,%s,%s,%s\n", iface, debugstr_variant(&server), debugstr_variant(&user), debugstr_variant(&domain), debugstr_variant(&password)); if (!is_variant_null(&user) || !is_variant_null(&domain) || !is_variant_null(&password)) FIXME("user/domain/password are ignored\n"); len = sizeof(comp_name)/sizeof(comp_name[0]); if (!GetComputerNameW(comp_name, &len)) return HRESULT_FROM_WIN32(GetLastError()); if (!is_variant_null(&server)) { const WCHAR *server_name; if (V_VT(&server) != VT_BSTR) { FIXME("server variant type %d is not supported\n", V_VT(&server)); return HRESULT_FROM_WIN32(ERROR_BAD_NETPATH); } /* skip UNC prefix if any */ server_name = V_BSTR(&server); if (server_name[0] == '\\' && server_name[1] == '\\') server_name += 2; if (strcmpiW(server_name, comp_name)) { FIXME("connection to remote server %s is not supported\n", debugstr_w(V_BSTR(&server))); return HRESULT_FROM_WIN32(ERROR_BAD_NETPATH); } } strcpyW(task_svc->comp_name, comp_name); task_svc->connected = TRUE; return S_OK; }
static int init_wksta_tests(void) { DWORD dwSize; BOOL rc; user_name[0] = 0; dwSize = sizeof(user_name)/sizeof(user_name[0]); rc=GetUserNameW(user_name, &dwSize); if (rc==FALSE && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED) { win_skip("GetUserNameW is not implemented\n"); return 0; } ok(rc, "User Name Retrieved\n"); computer_name[0] = 0; dwSize = sizeof(computer_name)/sizeof(computer_name[0]); ok(GetComputerNameW(computer_name, &dwSize), "Computer Name Retrieved\n"); return 1; }
VOID ShowHeader(VOID) { WCHAR szComputerName[MAX_STRING_SIZE]; DWORD comp_size = MAX_STRING_SIZE; /* Get the name of the computer for us and change the value of comp_name */ GetComputerNameW(szComputerName, &comp_size); /* TODO: Remove this section of code when program becomes stable enough for production use. */ ConPuts(StdOut, L"\n*WARNING*: This program is incomplete and may not work properly.\n"); /* Print the header information */ ConPuts(StdOut, L"\n"); ConResPuts(StdOut, IDS_APP_HEADER); ConPuts(StdOut, L"\n"); ConResPuts(StdOut, IDS_APP_LICENSE); ConResPrintf(StdOut, IDS_APP_CURR_COMPUTER, szComputerName); }
static int init_access_tests(void) { DWORD dwSize; BOOL rc; user_name[0] = 0; dwSize = sizeof(user_name)/sizeof(WCHAR); rc=GetUserNameW(user_name, &dwSize); if (rc==FALSE && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED) { skip("GetUserNameW is not available.\n"); return 0; } ok(rc, "User Name Retrieved\n"); computer_name[0] = 0; dwSize = sizeof(computer_name)/sizeof(WCHAR); ok(GetComputerNameW(computer_name, &dwSize), "Computer Name Retrieved\n"); return 1; }
int wmain(int agrc, wchar_t **argv[]) { WCHAR* computerName[3267]; DWORD charCount[3267]; if (!GetComputerNameW(&computerName, &charCount)) { printf("Could not read computer name, exiting.\n"); getchar(); exit(-1); } if (!wcsicmp(computerName, argv[1])) { printf("Proceed!\n"); } else { wprintf(L"Hostname: %s", computerName); } getchar(); return 0; }
DWORD AuditUserW( LPWSTR lpUser, LPWSTR lpPasswd ) { DWORD dwRetCode; WCHAR szwComputer[CNLEN+1]; WCHAR szwComputerName[CNLEN+3]; DWORD cbComputer; if( lpUser == NULL || lpPasswd == NULL ) return ERROR_INVALID_PARAMETER; cbComputer = CNLEN+1; GetComputerNameW( szwComputer, &cbComputer ); cbComputer = CNLEN+3; MakeComputerNameW( szwComputer, szwComputerName, &cbComputer ); dwRetCode = NetUserChangePassword( szwComputerName, lpUser, lpPasswd, lpPasswd ); return dwRetCode; }
static void create_volatile_environment_registry_key(void) { static const WCHAR VolatileEnvW[] = {'V','o','l','a','t','i','l','e',' ','E','n','v','i','r','o','n','m','e','n','t',0}; static const WCHAR AppDataW[] = {'A','P','P','D','A','T','A',0}; static const WCHAR ClientNameW[] = {'C','L','I','E','N','T','N','A','M','E',0}; static const WCHAR HomeDriveW[] = {'H','O','M','E','D','R','I','V','E',0}; static const WCHAR HomePathW[] = {'H','O','M','E','P','A','T','H',0}; static const WCHAR HomeShareW[] = {'H','O','M','E','S','H','A','R','E',0}; static const WCHAR LocalAppDataW[] = {'L','O','C','A','L','A','P','P','D','A','T','A',0}; static const WCHAR LogonServerW[] = {'L','O','G','O','N','S','E','R','V','E','R',0}; static const WCHAR SessionNameW[] = {'S','E','S','S','I','O','N','N','A','M','E',0}; static const WCHAR UserNameW[] = {'U','S','E','R','N','A','M','E',0}; static const WCHAR UserDomainW[] = {'U','S','E','R','D','O','M','A','I','N',0}; static const WCHAR UserProfileW[] = {'U','S','E','R','P','R','O','F','I','L','E',0}; static const WCHAR ConsoleW[] = {'C','o','n','s','o','l','e',0}; static const WCHAR EmptyW[] = {0}; WCHAR path[MAX_PATH]; WCHAR computername[MAX_COMPUTERNAME_LENGTH + 1 + 2]; DWORD size; HKEY hkey; HRESULT hr; if (RegCreateKeyExW( HKEY_CURRENT_USER, VolatileEnvW, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, NULL )) return; hr = SHGetFolderPathW( NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, path ); if (SUCCEEDED(hr)) set_reg_value( hkey, AppDataW, path ); set_reg_value( hkey, ClientNameW, ConsoleW ); /* Write the profile path's drive letter and directory components into * HOMEDRIVE and HOMEPATH respectively. */ hr = SHGetFolderPathW( NULL, CSIDL_PROFILE, NULL, SHGFP_TYPE_CURRENT, path ); if (SUCCEEDED(hr)) { set_reg_value( hkey, UserProfileW, path ); set_reg_value( hkey, HomePathW, path + 2 ); path[2] = '\0'; set_reg_value( hkey, HomeDriveW, path ); } size = sizeof(path)/sizeof(path[0]); if (GetUserNameW( path, &size )) set_reg_value( hkey, UserNameW, path ); set_reg_value( hkey, HomeShareW, EmptyW ); hr = SHGetFolderPathW( NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, path ); if (SUCCEEDED(hr)) set_reg_value( hkey, LocalAppDataW, path ); size = (sizeof(computername)/sizeof(WCHAR)) - 2; if (GetComputerNameW(&computername[2], &size)) { set_reg_value( hkey, UserDomainW, &computername[2] ); computername[0] = computername[1] = '\\'; set_reg_value( hkey, LogonServerW, computername ); } set_reg_value( hkey, SessionNameW, ConsoleW ); RegCloseKey( hkey ); }
/* base::Sys.info */ SEXP do_sysinfo(SEXP call, SEXP op, SEXP args, SEXP rho) { SEXP ans, ansnames; OSVERSIONINFOEX osvi; char ver[256], buf[1000]; wchar_t name[MAX_COMPUTERNAME_LENGTH + 1], user[UNLEN+1]; DWORD namelen = MAX_COMPUTERNAME_LENGTH + 1, userlen = UNLEN+1; checkArity(op, args); PROTECT(ans = allocVector(STRSXP, 8)); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); if(!GetVersionEx((OSVERSIONINFO *)&osvi)) error(_("unsupported version of Windows")); SET_STRING_ELT(ans, 0, mkChar("Windows")); /* Here for unknown future versions */ snprintf(ver, 256, "%d.%d", (int)osvi.dwMajorVersion, (int)osvi.dwMinorVersion); if((int)osvi.dwMajorVersion >= 5) { PGNSI pGNSI; SYSTEM_INFO si; if(osvi.dwMajorVersion == 6) { if(osvi.wProductType == VER_NT_WORKSTATION) { if(osvi.dwMinorVersion == 0) strcpy(ver, "Vista"); else strcpy(ver, "7"); } else strcpy(ver, "Server 2008"); } if(osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0) strcpy(ver, "2000"); if(osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1) strcpy(ver, "XP"); if(osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2) { if(osvi.wProductType == VER_NT_WORKSTATION) strcpy(ver, "XP Professional"); else strcpy(ver, "Server 2003"); } /* GetNativeSystemInfo is XP or later */ pGNSI = (PGNSI) GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetNativeSystemInfo"); if(NULL != pGNSI) pGNSI(&si); else GetSystemInfo(&si); if(si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) strcat(ver, " x64"); } SET_STRING_ELT(ans, 1, mkChar(ver)); if((int)osvi.dwMajorVersion >= 5) { if(osvi.wServicePackMajor > 0) snprintf(ver, 256, "build %d, Service Pack %d", LOWORD(osvi.dwBuildNumber), (int) osvi.wServicePackMajor); else snprintf(ver, 256, "build %d", LOWORD(osvi.dwBuildNumber)); } else snprintf(ver, 256, "build %d, %s", LOWORD(osvi.dwBuildNumber), osvi.szCSDVersion); SET_STRING_ELT(ans, 2, mkChar(ver)); GetComputerNameW(name, &namelen); wcstoutf8(buf, name, 1000); SET_STRING_ELT(ans, 3, mkCharCE(buf, CE_UTF8)); #ifdef WIN64 SET_STRING_ELT(ans, 4, mkChar("x86-64")); #else SET_STRING_ELT(ans, 4, mkChar("x86")); #endif GetUserNameW(user, &userlen); wcstoutf8(buf, user, 1000); SET_STRING_ELT(ans, 5, mkCharCE(buf, CE_UTF8)); SET_STRING_ELT(ans, 6, STRING_ELT(ans, 5)); SET_STRING_ELT(ans, 7, STRING_ELT(ans, 5)); PROTECT(ansnames = allocVector(STRSXP, 8)); SET_STRING_ELT(ansnames, 0, mkChar("sysname")); SET_STRING_ELT(ansnames, 1, mkChar("release")); SET_STRING_ELT(ansnames, 2, mkChar("version")); SET_STRING_ELT(ansnames, 3, mkChar("nodename")); SET_STRING_ELT(ansnames, 4, mkChar("machine")); SET_STRING_ELT(ansnames, 5, mkChar("login")); SET_STRING_ELT(ansnames, 6, mkChar("user")); SET_STRING_ELT(ansnames, 7, mkChar("effective_user")); setAttrib(ans, R_NamesSymbol, ansnames); UNPROTECT(2); return ans; }