# HG changeset patch # User Stefan Vogel # Date 1279897835 -7200 # Node ID f476234e681da70e3bff447743716f83455699e3 # Parent 5d7d08fd4c773f78019278d657e46f3bd6353e59 added: #isWin7Like changed:6 methods - getHostName returns the FQDN - Windows7 queries diff -r 5d7d08fd4c77 -r f476234e681d Win32OperatingSystem.st --- a/Win32OperatingSystem.st Fri Jul 23 14:46:52 2010 +0200 +++ b/Win32OperatingSystem.st Fri Jul 23 17:10:35 2010 +0200 @@ -7186,57 +7186,57 @@ ! getDomainName - "return the domain this host is in. + "return the DNS domain this host is in. Notice: - not all systems support this; on some, 'unknown' is returned." - - |name idx hostName k| + not all systems support this; on some, 'unknown' is returned." + + |domainName idx hostName k| DomainName notNil ifTrue:[ - ^ DomainName - ]. - - name := self getEnvironment:'DOMAIN'. - name isNil ifTrue:[ - name := self getEnvironment:'DOMAINNAME'. - ]. - - name isNil ifTrue:[ - "/ sometimes, we can extract the domainName from the hostName ... - hostName := self primGetHostName. - hostName notNil ifTrue:[ - idx := hostName indexOf:$.. - idx ~~ 0 ifTrue:[ - name := hostName copyFrom:idx+1. - ] - ]. - - name isNil ifTrue:[ - "/ ok, search the registry ... - "/ under NT and later, it is found there ... - k := RegistryEntry key:'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters'. - k notNil ifTrue:[ - name := k valueNamed:'Domain'. - k close. - ]. - ]. - - name isNil ifTrue:[ - "/ under Win95/Win98, it is found there ... - k := RegistryEntry key:'HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VxD\MSTCP'. - k notNil ifTrue:[ - name := k valueNamed:'Domain'. - k close. - ] - ]. - - name isNil ifTrue:[ - 'Win32OperatingSystem [warning]: cannot find out domainname' errorPrintCR. - name := 'unknown'. - ] - ]. - DomainName := name. - ^ name + ^ DomainName + ]. + + "/ sometimes, we can extract the domainName from the hostName ... + hostName := self getHostName. + hostName notEmptyOrNil ifTrue:[ + idx := hostName indexOf:$.. + idx ~~ 0 ifTrue:[ + domainName := hostName copyFrom:idx+1. + ] + ]. + + domainName isNil ifTrue:[ + domainName := self getEnvironment:'DOMAIN'. + domainName isNil ifTrue:[ + domainName := self getEnvironment:'DOMAINNAME'. + ]. + + domainName isNil ifTrue:[ + "/ ok, search the registry ... + "/ under NT and later, it is found there ... + k := RegistryEntry key:'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters'. + k notNil ifTrue:[ + domainName := k valueNamed:'Domain'. + k close. + ]. + ]. + + domainName isNil ifTrue:[ + "/ under Win95/Win98, it is found there ... + k := RegistryEntry key:'HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VxD\MSTCP'. + k notNil ifTrue:[ + domainName := k valueNamed:'Domain'. + k close. + ] + ]. + + domainName isNil ifTrue:[ + 'Win32OperatingSystem [warning]: cannot find out domainName' errorPrintCR. + domainName := 'unknown'. + ]. + DomainName := domainName. "cache only, if it is fixed" + ]. + ^ domainName " DomainName := nil. @@ -7294,28 +7294,20 @@ ! getHostName - "return the hostname we are running on - if there is - a HOST environment variable, we are much faster here ... - Notice: - not all systems support this; on some, 'unknown' is returned." - - |name idx| - - HostName notNil ifTrue:[ - ^ HostName - ]. - - name := self primGetHostName. - - "/ on some systems, the hostname already contains the domain. - "/ decompose it here. - idx := name indexOf:$.. - idx ~~ 0 ifTrue:[ - DomainName := name copyFrom:(idx+1). - name := name copyTo:(idx-1). - ]. - HostName := name. - ^ name + "return the hostname we are running on + - if possible, the fully qualified host name." + + |hostName| + +%{ /* STACK: 2048 */ + char buffer[512]; + DWORD buffSize = sizeof(buffer); + + if (GetComputerNameEx(ComputerNameDnsFullyQualified, buffer, &buffSize) == TRUE) { + hostName = __MKSTRING(buffer); + } +%}. + ^ hostName " OperatingSystem getHostName @@ -7776,25 +7768,25 @@ This method is mainly provided to augment error reports with some system information. (in case of system/version specific OS errors, conditional workarounds and patches - may be based upon this info). + may be based upon this info). Your application should NOT depend upon this in any way. The returned info may (or may not) contain: - #system -> some operating system identification (irix, Linux, nt, win32s ...) - #version -> OS version (some os version identification) - #release -> OS release (3.5, 1.2.1 ...) - #node -> some host identification (hostname) - #domain -> domain name (hosts domain) - #machine -> type of machine (i586, mips ...) + #system -> some operating system identification (irix, Linux, nt, win32s ...) + #version -> OS version (some os version identification) + #release -> OS release (3.5, 1.2.1 ...) + #node -> some host identification (hostname) + #domain -> domain name (hosts domain) + #machine -> type of machine (i586, mips ...) win32: - #physicalRam -> total amount of physical memory - #freeRam -> amount of free memory - #swapSize -> size of swapSpace (page file) - #freeSwap -> free bytes in swapSpace - #virtualRam -> total amount of virtual memory - #freeVirtual -> amount of free virtual memory - #memoryLoad -> percentage of memory usage (useless) + #physicalRam -> total amount of physical memory + #freeRam -> amount of free memory + #swapSize -> size of swapSpace (page file) + #freeSwap -> free bytes in swapSpace + #virtualRam -> total amount of virtual memory + #freeVirtual -> amount of free virtual memory + #memoryLoad -> percentage of memory usage (useless) " |sys node rel ver minorVer majorVer mach dom info arch @@ -7820,19 +7812,21 @@ majorVer = __mkSmallInteger(verMajor); if (HIWORD(vsn) & 0x8000) { - s = "win95"; + sys = @symbol(win95); } else { - if ((verMajor > 5) - || ((verMajor == 5) && (verMinor >= 1))) { - s = "xp"; - if (verMajor >= 6) { - s = "vista"; - } - } else { - s = "nt"; - } - } - sys = __MKSTRING(s); + if ((verMajor > 5) + || ((verMajor == 5) && (verMinor >= 1))) { + sys = @symbol(xp); + if (verMajor >= 6) { + sys = @symbol(vista); + if (verMinor >= 1) { + sys = @symbol(win7); + } + } + } else { + sys = @symbol(nt); + } + } len = snprintf(vsnBuffer, sizeof(vsnBuffer), "%d.%d", verMajor, verMinor); rel = __MKSTRING_L(vsnBuffer, len); @@ -7857,166 +7851,155 @@ #endif { #ifdef PROCESSOR_ARCHITECTURE_INTEL - case PROCESSOR_ARCHITECTURE_INTEL: - s = "intel"; - break; + case PROCESSOR_ARCHITECTURE_INTEL: + arch = @symbol(intel); + break; #endif #ifdef PROCESSOR_ARCHITECTURE_MIPS - case PROCESSOR_ARCHITECTURE_MIPS: - s = "mips"; - break; + case PROCESSOR_ARCHITECTURE_MIPS: + arch = @symbol(mips); + break; #endif #ifdef PROCESSOR_ARCHITECTURE_ALPHA - case PROCESSOR_ARCHITECTURE_ALPHA: - s = "alpha"; - break; + case PROCESSOR_ARCHITECTURE_ALPHA: + arch = @symbol(alpha); + break; #endif #ifdef PROCESSOR_ARCHITECTURE_ALPHA64 - case PROCESSOR_ARCHITECTURE_ALPHA64: - s = "alpha64"; - break; + case PROCESSOR_ARCHITECTURE_ALPHA64: + arch = @symbol(alpha64); + break; #endif #ifdef PROCESSOR_ARCHITECTURE_PPC - case PROCESSOR_ARCHITECTURE_PPC: - s = "ppc"; - break; + case PROCESSOR_ARCHITECTURE_PPC: + arch = @symbol(ppc); + break; #endif #ifdef PROCESSOR_ARCHITECTURE_ARM - case PROCESSOR_ARCHITECTURE_ARM: - s = "arm"; - break; + case PROCESSOR_ARCHITECTURE_ARM: + arch = @symbol(arm); + break; #endif #ifdef PROCESSOR_ARCHITECTURE_SHX - case PROCESSOR_ARCHITECTURE_SHX: - s = "shx"; - break; + case PROCESSOR_ARCHITECTURE_SHX: + arch = @symbol(shx); + break; #endif #ifdef PROCESSOR_ARCHITECTURE_IA64 - case PROCESSOR_ARCHITECTURE_IA64: - s = "ia64"; - break; + case PROCESSOR_ARCHITECTURE_IA64: + arch = @symbol(ia64); + break; #endif #ifdef PROCESSOR_ARCHITECTURE_MSIL - case PROCESSOR_ARCHITECTURE_MSIL: - s = "msil"; - break; -#endif - default: - s = "unknown"; - break; - } - arch = __MKSTRING(s); + case PROCESSOR_ARCHITECTURE_MSIL: + arch = @symbol(msil); + break; +#endif + default: + arch = @symbol(unknown); + break; + } switch (sysInfo.dwProcessorType) { #ifdef PROCESSOR_INTEL_386 - case PROCESSOR_INTEL_386: - s = "i386"; - break; + case PROCESSOR_INTEL_386: + mach = @symbol(i386); + break; #endif #ifdef PROCESSOR_INTEL_486 - case PROCESSOR_INTEL_486: - s = "i486"; - break; + case PROCESSOR_INTEL_486: + mach = @symbol(i486); + break; #endif #ifdef PROCESSOR_INTEL_PENTIUM - case PROCESSOR_INTEL_PENTIUM: - s = "i586"; - break; + case PROCESSOR_INTEL_PENTIUM: + mach = @symbol(i586); + break; #endif #ifdef PROCESSOR_INTEL_860 - case PROCESSOR_INTEL_860: - s = "i860"; - break; + case PROCESSOR_INTEL_860: + mach = @symbol(i860); + break; #endif #ifdef PROCESSOR_INTEL_IA64 - case PROCESSOR_INTEL_IA64: - s = "ia64"; - break; + case PROCESSOR_INTEL_IA64: + mach = @symbol(ia64); + break; #endif #ifdef PROCESSOR_MIPS_R2000 - case PROCESSOR_MIPS_R2000: - s = "r2000"; - break; + case PROCESSOR_MIPS_R2000: + mach = @symbol(r2000); + break; #endif #ifdef PROCESSOR_MIPS_R3000 - case PROCESSOR_MIPS_R3000: - s = "r3000"; - break; + case PROCESSOR_MIPS_R3000: + mach = @symbol(r3000); + break; #endif #ifdef PROCESSOR_MIPS_R4000 - case PROCESSOR_MIPS_R4000: - s = "r4000"; - break; + case PROCESSOR_MIPS_R4000: + mach = @symbol(r4000); + break; #endif #ifdef PROCESSOR_ALPHA_21064 - case PROCESSOR_ALPHA_21064: - s = "alpha21064"; - break; + case PROCESSOR_ALPHA_21064: + mach = @symbol(alpha21064); + break; #endif #ifdef PROCESSOR_ARM720 - case PROCESSOR_ARM720: - s = "arm720"; - break; + case PROCESSOR_ARM720: + mach = @symbol(arm720); + break; #endif #ifdef PROCESSOR_ARM820 - case PROCESSOR_ARM820: - s = "arm820"; - break; + case PROCESSOR_ARM820: + mach = @symbol(arm820); + break; #endif #ifdef PROCESSOR_ARM920 - case PROCESSOR_ARM920: - s = "arm920"; - break; + case PROCESSOR_ARM920: + mach = @symbol(arm920); + break; #endif #ifdef PROCESSOR_ARM_7TDMI - case PROCESSOR_ARM_7TDMI: - s = "arm70001"; - break; + case PROCESSOR_ARM_7TDMI: + mach = @symbol(arm70001); + break; #endif #ifdef PROCESSOR_PPC_601 - case PROCESSOR_PPC_601: - s = "ppc601"; - break; + case PROCESSOR_PPC_601: + mach = @symbol(ppc601); + break; #endif #ifdef PROCESSOR_PPC_603 - case PROCESSOR_PPC_603: - s = "ppc603"; - break; + case PROCESSOR_PPC_603: + mach = @symbol(ppc603); + break; #endif #ifdef PROCESSOR_PPC_604 - case PROCESSOR_PPC_604: - s = "ppc604"; - break; + case PROCESSOR_PPC_604: + mach = @symbol(ppc604); + break; #endif #ifdef PROCESSOR_PPC_620 - case PROCESSOR_PPC_620: - s = "ppc620"; - break; -#endif - - default: - sprintf(vsnBuffer, "%d", sysInfo.dwProcessorType); - s = vsnBuffer; - break; - } - mach = __MKSTRING(s); + case PROCESSOR_PPC_620: + mach = @symbol(ppc620); + break; +#endif + + default: + sprintf(vsnBuffer, "%d", sysInfo.dwProcessorType); + mach = __MKSTRING(vsnBuffer); + break; + } numberOfCPUs = __MKUINT(sysInfo.dwNumberOfProcessors); %}. - sys isNil ifTrue:[ - sys := self getSystemType. - ]. node isNil ifTrue:[ - node := self getHostName. + node := self getHostName. ]. dom isNil ifTrue:[ - dom := self getDomainName. - ]. - mach isNil ifTrue:[ - mach := self getCPUType. - ]. - arch isNil ifTrue:[ - arch := 'unknown'. + dom := self getDomainName. ]. info := IdentityDictionary new. @@ -8055,7 +8038,7 @@ here ... (except for slight differences between next/mach and other machs)" - ^ 'win32' + ^ #win32 " OperatingSystem getSystemType @@ -8214,6 +8197,22 @@ " ! +isWin7Like + "return true, if running on a Windows7 like system." + + |sysInfo major| + + sysInfo := self getSystemInfo. + major := sysInfo at:#majorVersion. + + ^ (major == 6 and:[(sysInfo at:#minorVersion) >= 1]) + or:[major > 6] + + " + self isWin7Like + " +! + maxFileNameLength "return the max number of characters in a filename. CAVEAT: @@ -8251,14 +8250,14 @@ osName - | os | - - os := 'Windows ', (#('3.x' '95' 'NT' '2000' 'XP') at: (#('3.0' '4.0' '4.1' '5.0' '5.1') indexOf: (OperatingSystem osVersion))). - - ^os - - "Created: / 18-01-2007 / 17:21:06 / User" - "Modified: / 19-01-2007 / 13:15:59 / User" + ^ 'Windows ', + (#('NT' '2000' 'XP' 'VISTA' '7') + at: (#('4.1' '5.0' '5.1' '6.0' '6.1') indexOf:OperatingSystem osVersion) + ifAbsent:OperatingSystem osVersion). + + " + self osName + " ! osVersion @@ -8291,112 +8290,6 @@ "Modified: 20.6.1997 / 17:37:26 / cg" ! -primGetDomainName -%{ -#if 0 /* not needed */ - HINSTANCE hNetApi32 = LoadLibrary("netapi32.dll"); - DWORD (__stdcall *pfnNetApiBufferFree)(LPVOID Buffer); - DWORD (__stdcall *pfnNetWkstaGetInfo)(LPWSTR servername, DWORD level, void *bufptr); - - if (hNetApi32) { - pfnNetApiBufferFree = (DWORD (__stdcall *)(void *)) GetProcAddress(hNetApi32, "NetApiBufferFree"); - pfnNetWkstaGetInfo = (DWORD (__stdcall *)(LPWSTR, DWORD, void *)) GetProcAddress(hNetApi32, "NetWkstaGetInfo"); - } - - if (hNetApi32 && pfnNetWkstaGetInfo && pfnNetApiBufferFree) { - /* this way is more reliable, in case user has a local account. */ - char dname[256]; - DWORD dnamelen = sizeof(dname); - struct { - DWORD wki100_platform_id; - LPWSTR wki100_computername; - LPWSTR wki100_langroup; - DWORD wki100_ver_major; - DWORD wki100_ver_minor; - } *pwi; - - /* NERR_Success *is* 0*/ - if (0 == pfnNetWkstaGetInfo(NULL, 100, &pwi)) { - if (pwi->wki100_langroup && *(pwi->wki100_langroup)) { - WideCharToMultiByte(CP_ACP, NULL, pwi->wki100_langroup, - -1, (LPSTR)dname, dnamelen, NULL, NULL); - } - else { - WideCharToMultiByte(CP_ACP, NULL, pwi->wki100_computername, - -1, (LPSTR)dname, dnamelen, NULL, NULL); - } - pfnNetApiBufferFree(pwi); - FreeLibrary(hNetApi32); - RETURN (__MKSTRING(dname)); - } - FreeLibrary(hNetApi32); - } else { - /* Win95 doesn't have NetWksta*(), so do it the old way */ - char name[256]; - DWORD size = sizeof(name); - if (hNetApi32) - FreeLibrary(hNetApi32); - if (GetUserName(name,&size)) { - char sid[1024]; - DWORD sidlen = sizeof(sid); - char dname[256]; - DWORD dnamelen = sizeof(dname); - SID_NAME_USE snu; - if (LookupAccountName(NULL, name, (PSID)&sid, &sidlen, - dname, &dnamelen, &snu)) { - RETURN (__MKSTRING(dname)); /* all that for this */ - } - } - } -#endif /* not needed */ -%}. - ^ nil -! - -primGetHostName - "return the hostname we are running on - if there is - a HOST environment variable, we are much faster here ... - Notice: - not all systems support this; on some, 'unknown' is returned." - - |name| - -%{ /* STACK: 2048 */ -#if defined(HAS_GETHOSTNAME) - char buffer[256]; - - if (gethostname(buffer, sizeof(buffer)) == 0) { - name = __MKSTRING(buffer); - } -#else - char buffer[128]; - DWORD buffSize = sizeof(buffer); - - if (GetComputerName(buffer, &buffSize) == TRUE) { - name = __MKSTRING(buffer); - } -#endif -%}. - name isNil ifTrue:[ - name := self getEnvironment:'HOST'. - name isNil ifTrue:[ - name := self getEnvironment:'HOSTNAME'. - name isNil ifTrue:[ - name := self getEnvironment:'COMPUTERNAME'. - name isNil ifTrue:[ - 'Win32OperatingSystem [warning]: cannot find out hostname' errorPrintCR. - name := 'unknown'. - ] - ] - ] - ]. - ^ name - - " - OperatingSystem primGetHostName - " -! - randomBytesInto:bufferOrInteger "If bufferOrInteger is a String or a ByteArray, fill a given buffer with random bytes from the RtlGenRandom function @@ -16299,11 +16192,11 @@ !Win32OperatingSystem class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.404 2010-07-07 14:58:13 cg Exp $' + ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.405 2010-07-23 15:10:35 stefan Exp $' ! version_CVS - ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.404 2010-07-07 14:58:13 cg Exp $' + ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.405 2010-07-23 15:10:35 stefan Exp $' ! ! Win32OperatingSystem initialize!