Win32OperatingSystem.st
changeset 12961 f476234e681d
parent 12934 bc516945ce4d
child 12969 999e457ed11e
equal deleted inserted replaced
12960:5d7d08fd4c77 12961:f476234e681d
  7184 
  7184 
  7185     "Created: 2.5.1997 / 11:42:29 / cg"
  7185     "Created: 2.5.1997 / 11:42:29 / cg"
  7186 !
  7186 !
  7187 
  7187 
  7188 getDomainName
  7188 getDomainName
  7189     "return the domain this host is in.
  7189     "return the DNS domain this host is in.
  7190      Notice:
  7190      Notice:
  7191 	not all systems support this; on some, 'unknown' is returned."
  7191         not all systems support this; on some, 'unknown' is returned."
  7192 
  7192 
  7193     |name idx hostName k|
  7193     |domainName idx hostName k|
  7194 
  7194 
  7195     DomainName notNil ifTrue:[
  7195     DomainName notNil ifTrue:[
  7196 	^ DomainName
  7196         ^ DomainName
  7197     ].
  7197     ].
  7198 
  7198 
  7199     name := self getEnvironment:'DOMAIN'.
  7199     "/ sometimes, we can extract the domainName from the hostName ...
  7200     name isNil ifTrue:[
  7200     hostName := self getHostName.
  7201 	name := self getEnvironment:'DOMAINNAME'.
  7201     hostName notEmptyOrNil ifTrue:[
       
  7202         idx := hostName indexOf:$..
       
  7203         idx ~~ 0 ifTrue:[
       
  7204             domainName := hostName copyFrom:idx+1.
       
  7205         ]
  7202     ].
  7206     ].
  7203 
  7207 
  7204     name isNil ifTrue:[
  7208     domainName isNil ifTrue:[
  7205 	"/ sometimes, we can extract the domainName from the hostName ...
  7209         domainName := self getEnvironment:'DOMAIN'.
  7206 	hostName := self primGetHostName.
  7210         domainName isNil ifTrue:[
  7207 	hostName notNil ifTrue:[
  7211             domainName := self getEnvironment:'DOMAINNAME'.
  7208 	    idx := hostName indexOf:$..
  7212         ].
  7209 	    idx ~~ 0 ifTrue:[
  7213 
  7210 		name := hostName copyFrom:idx+1.
  7214         domainName isNil ifTrue:[
  7211 	    ]
  7215             "/ ok, search the registry ...
  7212 	].
  7216             "/ under NT and later, it is found there ...
  7213 
  7217             k := RegistryEntry key:'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters'.
  7214 	name isNil ifTrue:[
  7218             k notNil ifTrue:[
  7215 	    "/ ok, search the registry ...
  7219                 domainName := k valueNamed:'Domain'.
  7216 	    "/ under NT and later, it is found there ...
  7220                 k close.
  7217 	    k := RegistryEntry key:'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters'.
  7221             ].
  7218 	    k notNil ifTrue:[
  7222         ].
  7219 		name := k valueNamed:'Domain'.
  7223 
  7220 		k close.
  7224         domainName isNil ifTrue:[
  7221 	    ].
  7225             "/ under Win95/Win98, it is found there ...
  7222 	].
  7226             k := RegistryEntry key:'HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VxD\MSTCP'.
  7223 
  7227             k notNil ifTrue:[
  7224 	name isNil ifTrue:[
  7228                 domainName := k valueNamed:'Domain'.
  7225 	    "/ under Win95/Win98, it is found there ...
  7229                 k close.
  7226 	    k := RegistryEntry key:'HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VxD\MSTCP'.
  7230             ]
  7227 	    k notNil ifTrue:[
  7231         ].
  7228 		name := k valueNamed:'Domain'.
  7232 
  7229 		k close.
  7233         domainName isNil ifTrue:[
  7230 	    ]
  7234             'Win32OperatingSystem [warning]: cannot find out domainName' errorPrintCR.
  7231 	].
  7235             domainName := 'unknown'.
  7232 
  7236         ].
  7233 	name isNil ifTrue:[
  7237         DomainName := domainName.     "cache only, if it is fixed"
  7234 	    'Win32OperatingSystem [warning]: cannot find out domainname' errorPrintCR.
       
  7235 	    name := 'unknown'.
       
  7236 	]
       
  7237     ].
  7238     ].
  7238     DomainName := name.
  7239     ^ domainName
  7239     ^ name
       
  7240 
  7240 
  7241     "
  7241     "
  7242      DomainName := nil.
  7242      DomainName := nil.
  7243      OperatingSystem getDomainName
  7243      OperatingSystem getDomainName
  7244      OperatingSystem getHostName
  7244      OperatingSystem getHostName
  7292 
  7292 
  7293     "Modified: / 09-01-2007 / 20:14:35 / cg"
  7293     "Modified: / 09-01-2007 / 20:14:35 / cg"
  7294 !
  7294 !
  7295 
  7295 
  7296 getHostName
  7296 getHostName
  7297     "return the hostname we are running on - if there is
  7297     "return the hostname we are running on
  7298      a HOST environment variable, we are much faster here ...
  7298       - if possible, the fully qualified host name."
  7299      Notice:
  7299 
  7300 	not all systems support this; on some, 'unknown' is returned."
  7300     |hostName|
  7301 
  7301 
  7302     |name idx|
  7302 %{  /* STACK: 2048 */
  7303 
  7303     char buffer[512];
  7304     HostName notNil ifTrue:[
  7304     DWORD buffSize = sizeof(buffer);
  7305 	^ HostName
  7305 
  7306     ].
  7306     if (GetComputerNameEx(ComputerNameDnsFullyQualified, buffer, &buffSize) == TRUE) {
  7307 
  7307         hostName = __MKSTRING(buffer);
  7308     name := self primGetHostName.
  7308     }
  7309 
  7309 %}.
  7310     "/ on some systems, the hostname already contains the domain.
  7310     ^ hostName
  7311     "/ decompose it here.
       
  7312     idx := name indexOf:$..
       
  7313     idx ~~ 0 ifTrue:[
       
  7314 	DomainName := name copyFrom:(idx+1).
       
  7315 	name := name copyTo:(idx-1).
       
  7316     ].
       
  7317     HostName := name.
       
  7318     ^ name
       
  7319 
  7311 
  7320     "
  7312     "
  7321      OperatingSystem getHostName
  7313      OperatingSystem getHostName
  7322     "
  7314     "
  7323 !
  7315 !
  7774        OS, for example, linux returns 'ix86', while WIN32 returns 'x86'.
  7766        OS, for example, linux returns 'ix86', while WIN32 returns 'x86'.
  7775 
  7767 
  7776        This method is mainly provided to augment error reports with some system
  7768        This method is mainly provided to augment error reports with some system
  7777        information.
  7769        information.
  7778        (in case of system/version specific OS errors, conditional workarounds and patches
  7770        (in case of system/version specific OS errors, conditional workarounds and patches
  7779 	may be based upon this info).
  7771         may be based upon this info).
  7780        Your application should NOT depend upon this in any way.
  7772        Your application should NOT depend upon this in any way.
  7781 
  7773 
  7782      The returned info may (or may not) contain:
  7774      The returned info may (or may not) contain:
  7783 	#system -> some operating system identification (irix, Linux, nt, win32s ...)
  7775         #system -> some operating system identification (irix, Linux, nt, win32s ...)
  7784 	#version -> OS version (some os version identification)
  7776         #version -> OS version (some os version identification)
  7785 	#release -> OS release (3.5, 1.2.1 ...)
  7777         #release -> OS release (3.5, 1.2.1 ...)
  7786 	#node   -> some host identification (hostname)
  7778         #node   -> some host identification (hostname)
  7787 	#domain  -> domain name (hosts domain)
  7779         #domain  -> domain name (hosts domain)
  7788 	#machine -> type of machine (i586, mips ...)
  7780         #machine -> type of machine (i586, mips ...)
  7789 
  7781 
  7790      win32:
  7782      win32:
  7791 	#physicalRam -> total amount of physical memory
  7783         #physicalRam -> total amount of physical memory
  7792 	#freeRam -> amount of free memory
  7784         #freeRam -> amount of free memory
  7793 	#swapSize -> size of swapSpace (page file)
  7785         #swapSize -> size of swapSpace (page file)
  7794 	#freeSwap -> free bytes in swapSpace
  7786         #freeSwap -> free bytes in swapSpace
  7795 	#virtualRam -> total amount of virtual memory
  7787         #virtualRam -> total amount of virtual memory
  7796 	#freeVirtual -> amount of free virtual memory
  7788         #freeVirtual -> amount of free virtual memory
  7797 	#memoryLoad -> percentage of memory usage (useless)
  7789         #memoryLoad -> percentage of memory usage (useless)
  7798     "
  7790     "
  7799 
  7791 
  7800     |sys node rel ver minorVer majorVer mach dom info arch
  7792     |sys node rel ver minorVer majorVer mach dom info arch
  7801      physicalRam freeRam swapSize freeSwap
  7793      physicalRam freeRam swapSize freeSwap
  7802      virtualRam freeVirtual memoryLoad numberOfCPUs|
  7794      virtualRam freeVirtual memoryLoad numberOfCPUs|
  7818 
  7810 
  7819     minorVer = __mkSmallInteger(verMinor);
  7811     minorVer = __mkSmallInteger(verMinor);
  7820     majorVer = __mkSmallInteger(verMajor);
  7812     majorVer = __mkSmallInteger(verMajor);
  7821 
  7813 
  7822     if (HIWORD(vsn) & 0x8000) {
  7814     if (HIWORD(vsn) & 0x8000) {
  7823 	s = "win95";
  7815         sys = @symbol(win95);
  7824     } else {
  7816     } else {
  7825 	if ((verMajor > 5)
  7817         if ((verMajor > 5)
  7826 	 || ((verMajor == 5) && (verMinor >= 1))) {
  7818          || ((verMajor == 5) && (verMinor >= 1))) {
  7827 	    s = "xp";
  7819             sys = @symbol(xp);
  7828 	    if (verMajor >= 6) {
  7820             if (verMajor >= 6) {
  7829 		s = "vista";
  7821                 sys = @symbol(vista);
  7830 	    }
  7822                 if (verMinor >= 1) {
  7831 	} else {
  7823                     sys = @symbol(win7);
  7832 	    s = "nt";
  7824                 }
  7833 	}
  7825             }
  7834     }
  7826         } else {
  7835     sys = __MKSTRING(s);
  7827             sys = @symbol(nt);
       
  7828         }
       
  7829     }
  7836     len = snprintf(vsnBuffer, sizeof(vsnBuffer), "%d.%d", verMajor, verMinor);
  7830     len = snprintf(vsnBuffer, sizeof(vsnBuffer), "%d.%d", verMajor, verMinor);
  7837     rel = __MKSTRING_L(vsnBuffer, len);
  7831     rel = __MKSTRING_L(vsnBuffer, len);
  7838 
  7832 
  7839     GetSystemInfo(&sysInfo);
  7833     GetSystemInfo(&sysInfo);
  7840     memStatus.dwLength = sizeof(memStatus);
  7834     memStatus.dwLength = sizeof(memStatus);
  7855     /* MSC, BorlandC4 ... */
  7849     /* MSC, BorlandC4 ... */
  7856     switch (sysInfo.wProcessorArchitecture)
  7850     switch (sysInfo.wProcessorArchitecture)
  7857 #endif
  7851 #endif
  7858     {
  7852     {
  7859 #ifdef PROCESSOR_ARCHITECTURE_INTEL
  7853 #ifdef PROCESSOR_ARCHITECTURE_INTEL
  7860 	case PROCESSOR_ARCHITECTURE_INTEL:
  7854         case PROCESSOR_ARCHITECTURE_INTEL:
  7861 	    s = "intel";
  7855             arch = @symbol(intel);
  7862 	    break;
  7856             break;
  7863 #endif
  7857 #endif
  7864 #ifdef PROCESSOR_ARCHITECTURE_MIPS
  7858 #ifdef PROCESSOR_ARCHITECTURE_MIPS
  7865 	case PROCESSOR_ARCHITECTURE_MIPS:
  7859         case PROCESSOR_ARCHITECTURE_MIPS:
  7866 	    s = "mips";
  7860             arch = @symbol(mips);
  7867 	    break;
  7861             break;
  7868 #endif
  7862 #endif
  7869 #ifdef PROCESSOR_ARCHITECTURE_ALPHA
  7863 #ifdef PROCESSOR_ARCHITECTURE_ALPHA
  7870 	case PROCESSOR_ARCHITECTURE_ALPHA:
  7864         case PROCESSOR_ARCHITECTURE_ALPHA:
  7871 	    s = "alpha";
  7865             arch = @symbol(alpha);
  7872 	    break;
  7866             break;
  7873 #endif
  7867 #endif
  7874 #ifdef PROCESSOR_ARCHITECTURE_ALPHA64
  7868 #ifdef PROCESSOR_ARCHITECTURE_ALPHA64
  7875 	case PROCESSOR_ARCHITECTURE_ALPHA64:
  7869         case PROCESSOR_ARCHITECTURE_ALPHA64:
  7876 	    s = "alpha64";
  7870             arch = @symbol(alpha64);
  7877 	    break;
  7871             break;
  7878 #endif
  7872 #endif
  7879 #ifdef PROCESSOR_ARCHITECTURE_PPC
  7873 #ifdef PROCESSOR_ARCHITECTURE_PPC
  7880 	case PROCESSOR_ARCHITECTURE_PPC:
  7874         case PROCESSOR_ARCHITECTURE_PPC:
  7881 	    s = "ppc";
  7875             arch = @symbol(ppc);
  7882 	    break;
  7876             break;
  7883 #endif
  7877 #endif
  7884 #ifdef PROCESSOR_ARCHITECTURE_ARM
  7878 #ifdef PROCESSOR_ARCHITECTURE_ARM
  7885 	case PROCESSOR_ARCHITECTURE_ARM:
  7879         case PROCESSOR_ARCHITECTURE_ARM:
  7886 	    s = "arm";
  7880             arch = @symbol(arm);
  7887 	    break;
  7881             break;
  7888 #endif
  7882 #endif
  7889 #ifdef PROCESSOR_ARCHITECTURE_SHX
  7883 #ifdef PROCESSOR_ARCHITECTURE_SHX
  7890 	case PROCESSOR_ARCHITECTURE_SHX:
  7884         case PROCESSOR_ARCHITECTURE_SHX:
  7891 	    s = "shx";
  7885             arch = @symbol(shx);
  7892 	    break;
  7886             break;
  7893 #endif
  7887 #endif
  7894 #ifdef PROCESSOR_ARCHITECTURE_IA64
  7888 #ifdef PROCESSOR_ARCHITECTURE_IA64
  7895 	case PROCESSOR_ARCHITECTURE_IA64:
  7889         case PROCESSOR_ARCHITECTURE_IA64:
  7896 	    s = "ia64";
  7890             arch = @symbol(ia64);
  7897 	    break;
  7891             break;
  7898 #endif
  7892 #endif
  7899 #ifdef PROCESSOR_ARCHITECTURE_MSIL
  7893 #ifdef PROCESSOR_ARCHITECTURE_MSIL
  7900 	case PROCESSOR_ARCHITECTURE_MSIL:
  7894         case PROCESSOR_ARCHITECTURE_MSIL:
  7901 	    s = "msil";
  7895             arch = @symbol(msil);
  7902 	    break;
  7896             break;
  7903 #endif
  7897 #endif
  7904 	default:
  7898         default:
  7905 	    s = "unknown";
  7899             arch = @symbol(unknown);
  7906 	    break;
  7900             break;
  7907     }
  7901     }
  7908     arch = __MKSTRING(s);
       
  7909 
  7902 
  7910     switch (sysInfo.dwProcessorType) {
  7903     switch (sysInfo.dwProcessorType) {
  7911 #ifdef PROCESSOR_INTEL_386
  7904 #ifdef PROCESSOR_INTEL_386
  7912 	case PROCESSOR_INTEL_386:
  7905         case PROCESSOR_INTEL_386:
  7913 	    s = "i386";
  7906             mach = @symbol(i386);
  7914 	    break;
  7907             break;
  7915 #endif
  7908 #endif
  7916 #ifdef PROCESSOR_INTEL_486
  7909 #ifdef PROCESSOR_INTEL_486
  7917 	case PROCESSOR_INTEL_486:
  7910         case PROCESSOR_INTEL_486:
  7918 	    s = "i486";
  7911             mach = @symbol(i486);
  7919 	    break;
  7912             break;
  7920 #endif
  7913 #endif
  7921 #ifdef PROCESSOR_INTEL_PENTIUM
  7914 #ifdef PROCESSOR_INTEL_PENTIUM
  7922 	case PROCESSOR_INTEL_PENTIUM:
  7915         case PROCESSOR_INTEL_PENTIUM:
  7923 	    s = "i586";
  7916             mach = @symbol(i586);
  7924 	    break;
  7917             break;
  7925 #endif
  7918 #endif
  7926 #ifdef PROCESSOR_INTEL_860
  7919 #ifdef PROCESSOR_INTEL_860
  7927 	case PROCESSOR_INTEL_860:
  7920         case PROCESSOR_INTEL_860:
  7928 	    s = "i860";
  7921             mach = @symbol(i860);
  7929 	    break;
  7922             break;
  7930 #endif
  7923 #endif
  7931 #ifdef PROCESSOR_INTEL_IA64
  7924 #ifdef PROCESSOR_INTEL_IA64
  7932 	case PROCESSOR_INTEL_IA64:
  7925         case PROCESSOR_INTEL_IA64:
  7933 	    s = "ia64";
  7926             mach = @symbol(ia64);
  7934 	    break;
  7927             break;
  7935 #endif
  7928 #endif
  7936 #ifdef PROCESSOR_MIPS_R2000
  7929 #ifdef PROCESSOR_MIPS_R2000
  7937 	case PROCESSOR_MIPS_R2000:
  7930         case PROCESSOR_MIPS_R2000:
  7938 	    s = "r2000";
  7931             mach = @symbol(r2000);
  7939 	    break;
  7932             break;
  7940 #endif
  7933 #endif
  7941 #ifdef PROCESSOR_MIPS_R3000
  7934 #ifdef PROCESSOR_MIPS_R3000
  7942 	case PROCESSOR_MIPS_R3000:
  7935         case PROCESSOR_MIPS_R3000:
  7943 	    s = "r3000";
  7936             mach = @symbol(r3000);
  7944 	    break;
  7937             break;
  7945 #endif
  7938 #endif
  7946 #ifdef PROCESSOR_MIPS_R4000
  7939 #ifdef PROCESSOR_MIPS_R4000
  7947 	case PROCESSOR_MIPS_R4000:
  7940         case PROCESSOR_MIPS_R4000:
  7948 	    s = "r4000";
  7941             mach = @symbol(r4000);
  7949 	    break;
  7942             break;
  7950 #endif
  7943 #endif
  7951 #ifdef PROCESSOR_ALPHA_21064
  7944 #ifdef PROCESSOR_ALPHA_21064
  7952 	case PROCESSOR_ALPHA_21064:
  7945         case PROCESSOR_ALPHA_21064:
  7953 	    s = "alpha21064";
  7946             mach = @symbol(alpha21064);
  7954 	    break;
  7947             break;
  7955 #endif
  7948 #endif
  7956 #ifdef PROCESSOR_ARM720
  7949 #ifdef PROCESSOR_ARM720
  7957 	case PROCESSOR_ARM720:
  7950         case PROCESSOR_ARM720:
  7958 	    s = "arm720";
  7951             mach = @symbol(arm720);
  7959 	    break;
  7952             break;
  7960 #endif
  7953 #endif
  7961 #ifdef PROCESSOR_ARM820
  7954 #ifdef PROCESSOR_ARM820
  7962 	case PROCESSOR_ARM820:
  7955         case PROCESSOR_ARM820:
  7963 	    s = "arm820";
  7956             mach = @symbol(arm820);
  7964 	    break;
  7957             break;
  7965 #endif
  7958 #endif
  7966 #ifdef PROCESSOR_ARM920
  7959 #ifdef PROCESSOR_ARM920
  7967 	case PROCESSOR_ARM920:
  7960         case PROCESSOR_ARM920:
  7968 	    s = "arm920";
  7961             mach = @symbol(arm920);
  7969 	    break;
  7962             break;
  7970 #endif
  7963 #endif
  7971 #ifdef PROCESSOR_ARM_7TDMI
  7964 #ifdef PROCESSOR_ARM_7TDMI
  7972 	case PROCESSOR_ARM_7TDMI:
  7965         case PROCESSOR_ARM_7TDMI:
  7973 	    s = "arm70001";
  7966             mach = @symbol(arm70001);
  7974 	    break;
  7967             break;
  7975 #endif
  7968 #endif
  7976 #ifdef PROCESSOR_PPC_601
  7969 #ifdef PROCESSOR_PPC_601
  7977 	case PROCESSOR_PPC_601:
  7970         case PROCESSOR_PPC_601:
  7978 	    s = "ppc601";
  7971             mach = @symbol(ppc601);
  7979 	    break;
  7972             break;
  7980 #endif
  7973 #endif
  7981 #ifdef PROCESSOR_PPC_603
  7974 #ifdef PROCESSOR_PPC_603
  7982 	case PROCESSOR_PPC_603:
  7975         case PROCESSOR_PPC_603:
  7983 	    s = "ppc603";
  7976             mach = @symbol(ppc603);
  7984 	    break;
  7977             break;
  7985 #endif
  7978 #endif
  7986 #ifdef PROCESSOR_PPC_604
  7979 #ifdef PROCESSOR_PPC_604
  7987 	case PROCESSOR_PPC_604:
  7980         case PROCESSOR_PPC_604:
  7988 	    s = "ppc604";
  7981             mach = @symbol(ppc604);
  7989 	    break;
  7982             break;
  7990 #endif
  7983 #endif
  7991 #ifdef PROCESSOR_PPC_620
  7984 #ifdef PROCESSOR_PPC_620
  7992 	case PROCESSOR_PPC_620:
  7985         case PROCESSOR_PPC_620:
  7993 	    s = "ppc620";
  7986             mach = @symbol(ppc620);
  7994 	    break;
  7987             break;
  7995 #endif
  7988 #endif
  7996 
  7989 
  7997 	default:
  7990         default:
  7998 	    sprintf(vsnBuffer, "%d", sysInfo.dwProcessorType);
  7991             sprintf(vsnBuffer, "%d", sysInfo.dwProcessorType);
  7999 	    s = vsnBuffer;
  7992             mach =  __MKSTRING(vsnBuffer);
  8000 	    break;
  7993             break;
  8001     }
  7994     }
  8002     mach = __MKSTRING(s);
       
  8003 
  7995 
  8004     numberOfCPUs = __MKUINT(sysInfo.dwNumberOfProcessors);
  7996     numberOfCPUs = __MKUINT(sysInfo.dwNumberOfProcessors);
  8005 %}.
  7997 %}.
  8006     sys isNil ifTrue:[
       
  8007 	sys := self getSystemType.
       
  8008     ].
       
  8009     node isNil ifTrue:[
  7998     node isNil ifTrue:[
  8010 	node := self getHostName.
  7999         node := self getHostName.
  8011     ].
  8000     ].
  8012     dom isNil ifTrue:[
  8001     dom isNil ifTrue:[
  8013 	dom := self getDomainName.
  8002         dom := self getDomainName.
  8014     ].
       
  8015     mach isNil ifTrue:[
       
  8016 	mach := self getCPUType.
       
  8017     ].
       
  8018     arch isNil ifTrue:[
       
  8019 	arch := 'unknown'.
       
  8020     ].
  8003     ].
  8021 
  8004 
  8022     info := IdentityDictionary new.
  8005     info := IdentityDictionary new.
  8023     info at:#system put:sys.
  8006     info at:#system put:sys.
  8024     info at:#node put:node.
  8007     info at:#node put:node.
  8053      is slightly different for some systems (i.e. iris vs. irix).
  8036      is slightly different for some systems (i.e. iris vs. irix).
  8054      Dont depend on this - use getOSType. I dont really see a point
  8037      Dont depend on this - use getOSType. I dont really see a point
  8055      here ...
  8038      here ...
  8056      (except for slight differences between next/mach and other machs)"
  8039      (except for slight differences between next/mach and other machs)"
  8057 
  8040 
  8058     ^ 'win32'
  8041     ^ #win32
  8059 
  8042 
  8060     "
  8043     "
  8061      OperatingSystem getSystemType
  8044      OperatingSystem getSystemType
  8062     "
  8045     "
  8063 !
  8046 !
  8209 
  8192 
  8210     ^ (self getSystemInfo at:#majorVersion) >= 6
  8193     ^ (self getSystemInfo at:#majorVersion) >= 6
  8211 
  8194 
  8212     "
  8195     "
  8213      self isVistaLike
  8196      self isVistaLike
       
  8197     "
       
  8198 !
       
  8199 
       
  8200 isWin7Like
       
  8201     "return true, if running on a Windows7 like system."
       
  8202 
       
  8203     |sysInfo major|
       
  8204 
       
  8205     sysInfo := self getSystemInfo.
       
  8206     major := sysInfo at:#majorVersion.
       
  8207 
       
  8208     ^ (major == 6 and:[(sysInfo at:#minorVersion) >= 1])
       
  8209       or:[major > 6]
       
  8210 
       
  8211     "
       
  8212      self isWin7Like
  8214     "
  8213     "
  8215 !
  8214 !
  8216 
  8215 
  8217 maxFileNameLength
  8216 maxFileNameLength
  8218     "return the max number of characters in a filename.
  8217     "return the max number of characters in a filename.
  8249     "
  8248     "
  8250 !
  8249 !
  8251 
  8250 
  8252 osName
  8251 osName
  8253 
  8252 
  8254     | os |
  8253     ^ 'Windows ', 
  8255 
  8254         (#('NT' '2000' 'XP' 'VISTA' '7') 
  8256     os := 'Windows ', (#('3.x' '95' 'NT' '2000' 'XP') at: (#('3.0' '4.0' '4.1' '5.0' '5.1') indexOf: (OperatingSystem osVersion))).
  8255             at: (#('4.1' '5.0' '5.1' '6.0' '6.1') indexOf:OperatingSystem osVersion) 
  8257 
  8256             ifAbsent:OperatingSystem osVersion).
  8258     ^os
  8257 
  8259 
  8258     "
  8260     "Created: / 18-01-2007 / 17:21:06 / User"
  8259       self osName
  8261     "Modified: / 19-01-2007 / 13:15:59 / User"
  8260     "
  8262 !
  8261 !
  8263 
  8262 
  8264 osVersion
  8263 osVersion
  8265 
  8264 
  8266     ^OperatingSystem getSystemInfo at:#release
  8265     ^OperatingSystem getSystemInfo at:#release
  8287     "
  8286     "
  8288      OperatingSystem platformName
  8287      OperatingSystem platformName
  8289     "
  8288     "
  8290 
  8289 
  8291     "Modified: 20.6.1997 / 17:37:26 / cg"
  8290     "Modified: 20.6.1997 / 17:37:26 / cg"
  8292 !
       
  8293 
       
  8294 primGetDomainName
       
  8295 %{
       
  8296 #if 0   /* not needed */
       
  8297     HINSTANCE hNetApi32 = LoadLibrary("netapi32.dll");
       
  8298     DWORD (__stdcall *pfnNetApiBufferFree)(LPVOID Buffer);
       
  8299     DWORD (__stdcall *pfnNetWkstaGetInfo)(LPWSTR servername, DWORD level, void *bufptr);
       
  8300 
       
  8301     if (hNetApi32) {
       
  8302 	pfnNetApiBufferFree = (DWORD (__stdcall *)(void *)) GetProcAddress(hNetApi32, "NetApiBufferFree");
       
  8303 	pfnNetWkstaGetInfo = (DWORD (__stdcall *)(LPWSTR, DWORD, void *)) GetProcAddress(hNetApi32, "NetWkstaGetInfo");
       
  8304     }
       
  8305 
       
  8306     if (hNetApi32 && pfnNetWkstaGetInfo && pfnNetApiBufferFree) {
       
  8307 	/* this way is more reliable, in case user has a local account. */
       
  8308 	char dname[256];
       
  8309 	DWORD dnamelen = sizeof(dname);
       
  8310 	struct {
       
  8311 	    DWORD   wki100_platform_id;
       
  8312 	    LPWSTR  wki100_computername;
       
  8313 	    LPWSTR  wki100_langroup;
       
  8314 	    DWORD   wki100_ver_major;
       
  8315 	    DWORD   wki100_ver_minor;
       
  8316 	} *pwi;
       
  8317 
       
  8318 	/* NERR_Success *is* 0*/
       
  8319 	if (0 == pfnNetWkstaGetInfo(NULL, 100, &pwi)) {
       
  8320 	    if (pwi->wki100_langroup && *(pwi->wki100_langroup)) {
       
  8321 		WideCharToMultiByte(CP_ACP, NULL, pwi->wki100_langroup,
       
  8322 				    -1, (LPSTR)dname, dnamelen, NULL, NULL);
       
  8323 	    }
       
  8324 	    else {
       
  8325 		WideCharToMultiByte(CP_ACP, NULL, pwi->wki100_computername,
       
  8326 				    -1, (LPSTR)dname, dnamelen, NULL, NULL);
       
  8327 	    }
       
  8328 	    pfnNetApiBufferFree(pwi);
       
  8329 	    FreeLibrary(hNetApi32);
       
  8330 	    RETURN (__MKSTRING(dname));
       
  8331 	}
       
  8332 	FreeLibrary(hNetApi32);
       
  8333     } else {
       
  8334 	/* Win95 doesn't have NetWksta*(), so do it the old way */
       
  8335 	char name[256];
       
  8336 	DWORD size = sizeof(name);
       
  8337 	if (hNetApi32)
       
  8338 	    FreeLibrary(hNetApi32);
       
  8339 	if (GetUserName(name,&size)) {
       
  8340 	    char sid[1024];
       
  8341 	    DWORD sidlen = sizeof(sid);
       
  8342 	    char dname[256];
       
  8343 	    DWORD dnamelen = sizeof(dname);
       
  8344 	    SID_NAME_USE snu;
       
  8345 	    if (LookupAccountName(NULL, name, (PSID)&sid, &sidlen,
       
  8346 				  dname, &dnamelen, &snu)) {
       
  8347 		RETURN (__MKSTRING(dname));             /* all that for this */
       
  8348 	    }
       
  8349 	}
       
  8350     }
       
  8351 #endif /* not needed */
       
  8352 %}.
       
  8353     ^ nil
       
  8354 !
       
  8355 
       
  8356 primGetHostName
       
  8357     "return the hostname we are running on - if there is
       
  8358      a HOST environment variable, we are much faster here ...
       
  8359      Notice:
       
  8360 	not all systems support this; on some, 'unknown' is returned."
       
  8361 
       
  8362     |name|
       
  8363 
       
  8364 %{  /* STACK: 2048 */
       
  8365 #if defined(HAS_GETHOSTNAME)
       
  8366     char buffer[256];
       
  8367 
       
  8368     if (gethostname(buffer, sizeof(buffer)) == 0) {
       
  8369 	name = __MKSTRING(buffer);
       
  8370     }
       
  8371 #else
       
  8372     char buffer[128];
       
  8373     DWORD buffSize = sizeof(buffer);
       
  8374 
       
  8375     if (GetComputerName(buffer, &buffSize) == TRUE) {
       
  8376 	name = __MKSTRING(buffer);
       
  8377     }
       
  8378 #endif
       
  8379 %}.
       
  8380     name isNil ifTrue:[
       
  8381 	name := self getEnvironment:'HOST'.
       
  8382 	name isNil ifTrue:[
       
  8383 	    name := self getEnvironment:'HOSTNAME'.
       
  8384 	    name isNil ifTrue:[
       
  8385 		name := self getEnvironment:'COMPUTERNAME'.
       
  8386 		name isNil ifTrue:[
       
  8387 		    'Win32OperatingSystem [warning]: cannot find out hostname' errorPrintCR.
       
  8388 		    name := 'unknown'.
       
  8389 		]
       
  8390 	    ]
       
  8391 	]
       
  8392     ].
       
  8393     ^ name
       
  8394 
       
  8395     "
       
  8396      OperatingSystem primGetHostName
       
  8397     "
       
  8398 !
  8291 !
  8399 
  8292 
  8400 randomBytesInto:bufferOrInteger
  8293 randomBytesInto:bufferOrInteger
  8401     "If bufferOrInteger is a String or a ByteArray,
  8294     "If bufferOrInteger is a String or a ByteArray,
  8402 	fill a given buffer with random bytes from the RtlGenRandom function
  8295 	fill a given buffer with random bytes from the RtlGenRandom function
 16297 ! !
 16190 ! !
 16298 
 16191 
 16299 !Win32OperatingSystem class methodsFor:'documentation'!
 16192 !Win32OperatingSystem class methodsFor:'documentation'!
 16300 
 16193 
 16301 version
 16194 version
 16302     ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.404 2010-07-07 14:58:13 cg Exp $'
 16195     ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.405 2010-07-23 15:10:35 stefan Exp $'
 16303 !
 16196 !
 16304 
 16197 
 16305 version_CVS
 16198 version_CVS
 16306     ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.404 2010-07-07 14:58:13 cg Exp $'
 16199     ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.405 2010-07-23 15:10:35 stefan Exp $'
 16307 ! !
 16200 ! !
 16308 
 16201 
 16309 Win32OperatingSystem initialize!
 16202 Win32OperatingSystem initialize!
 16310 Win32OperatingSystem::PerformanceData initialize!
 16203 Win32OperatingSystem::PerformanceData initialize!
 16311 Win32OperatingSystem::RegistryEntry initialize!
 16204 Win32OperatingSystem::RegistryEntry initialize!