[Closed] Reading/Checking the CPU ID
Hello again.
I wonder if there’s a way to read the CPU ID of a computer in Maxscript, through MaxScript or dotnet or…
I would like my scripts to run only in my company computers. You know what I mean!
I have found this C# code, but I don’t know how to introduce it in a MaxScript code (in fact, I don’t know if it works):
string cpuInfo = string.Empty;
ManagementClass mc = new ManagementClass("win32_processor");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if (cpuInfo == "")
{
//Get only the first CPU's ID
cpuInfo = mo.Properties["processorID"].Value.ToString();
break;
}
}
return cpuInfo;
No, no, sorry for my English.
I mean in the PC under windows we have in the office.
It’s just to avoid using scripts outside.
Ok, sorry again.
I’ve found several threads in this forum with same question and the answer.
I’ve got a problem in XP64 Windows system.
after loading the dll (dotnet.loadAssembly @“System.Management.dll”), the code fails in the instruction:
mc = dotNetObject “System.Management.ManagementClass” “Win32_Processor”
– Error occurred in anonymous codeblock; position: 118; line: 2
– Runtime error: dotNet runtime exception: Can’t find the specified module. (Exception from HRESULT: 0x8007007E)
I have tried to iterate through:
mkk = dotNetObject “System.Management.ManagementObjectSearcher” “Select * from Win32_Processor”
mkkk = mkk.get
but I can’t find anything.
In Windows7 systems it works fine. Any suggestion?
I can’t find the way for XP64.
Anyone has had and resolved this problem?
It seems more of an .NET framework issue. What is the version installed in XP64? Can you install PowerShell and try running this on it (it just to check if the WMI interface for .NET is working): Get-WmiObject Win32_Processor
It should return something like this:
PS C:\WINDOWS\system32> Get-WmiObject Win32_Processor
Caption : Intel64 Family 6 Model 60 Stepping 3
DeviceID : CPU0
Manufacturer : GenuineIntel
MaxClockSpeed : 2401
Name : Intel(R) Core(TM) i7-4700HQ CPU @ 2.40GHz
SocketDesignation : SOCKET 0
Thanks for your help, Daniel.
I’ve have read a little about PowerShell in the Microsoft Web.
It’s out of my capabilities to install it in my computer. It gives me terror to install these kinds of programs.
The fact is:
dotNetObject “System.Management.ManagementClass” “Win32_Processor” throws an error, but:
dotNetClass “System.Management.ManagementClass” works fine.
All this works fine too:
mkk1 = dotNetClass “System.Management.ManagementObjectSearcher”
mkk2 = dotNetClass “System.Management.ManagementObject”
mkk3 = dotNetObject “System.Management.ManagementObjectSearcher” “Select * from Win32_BaseBoard”
But I don’t find how to iterate through anything to find out something (while enumerator.MoveNext() do ).
Can’t you use the MAC address for this? It has been used for years and there are several examples in this forum.
But keep in mind that there is no safe way to protect a MXS within MXS.
Being said that, if you don’t want your scripts to run in a computer outside your company, make sure the guys don’t take it out of the company.
fn CreateManagementOpsAssembly =
(
source = ""
source += "using System;
"
source += "using System.Collections.Generic;
"
source += "using System.Management;
"
source += "namespace Management
"
source += "{
"
source += " public class ManagementOps
"
source += " {
"
source += " public String GetProcessorID()
"
source += " {
"
source += " ManagementClass mc = new ManagementClass(\"win32_processor\");
"
source += " ManagementObjectCollection moc = mc.GetInstances();
"
source += " foreach (ManagementObject mo in moc)
"
source += " {
"
source += " return mo.Properties[\"ProcessorId\"].Value.ToString();
"
source += " }
"
source += " return \"\";
"
source += " }
"
source += " public String[] GetProcessorProperties()
"
source += " {
"
source += " ManagementClass mc = new ManagementClass(\"win32_processor\");
"
source += " ManagementObjectCollection moc = mc.GetInstances();
"
source += " foreach (ManagementObject mo in moc)
"
source += " {
"
source += " List<String> names = new List<String>();
"
source += " foreach (PropertyData p in mo.Properties)
"
source += " {
"
source += " names.Add(p.Name);
"
source += " }
"
source += " return names.ToArray();
"
source += " }
"
source += " return new String[0];
"
source += " }
"
source += " public String[] GetProcessorPropertyQualifiers(String name)
"
source += " {
"
source += " ManagementClass mc = new ManagementClass(\"win32_processor\");
"
source += " ManagementObjectCollection moc = mc.GetInstances();
"
source += " try
"
source += " {
"
source += " foreach (ManagementObject mo in moc)
"
source += " {
"
source += " PropertyData property = mo.Properties[name];
"
source += " List<String> names = new List<String>();
"
source += " foreach (QualifierData q in property.Qualifiers)
"
source += " {
"
source += " names.Add(q.Name);
"
source += " }
"
source += " return names.ToArray();
"
source += " }
"
source += " }
"
source += " catch { }
"
source += " return new String[0];
"
source += " }
"
source += " public String GetProcessorProperty(String name)
"
source += " {
"
source += " ManagementClass mc = new ManagementClass(\"win32_processor\");
"
source += " ManagementObjectCollection moc = mc.GetInstances();
"
source += " try
"
source += " {
"
source += " foreach (ManagementObject mo in moc)
"
source += " {
"
source += " return mo.Properties[name].Value.ToString();
"
source += " }
"
source += " }
"
source += " catch { }
"
source += " return \"\";
"
source += " }
"
source += " }
"
source += "}
"
csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"
compilerParams.ReferencedAssemblies.AddRange #("System.dll", "System.Management.dll")
compilerParams.GenerateInMemory = on
compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(source)
assembly = compilerResults.CompiledAssembly
assembly.CreateInstance "Management.ManagementOps"
)
global ManagementOps = CreateManagementOpsAssembly()
/*
ManagementOps.GetProcessorID()
print (ManagementOps.GetProcessorProperties())
ManagementOps.GetProcessorPropertyQualifiers "ProcessorId"
ManagementOps.GetProcessorProperty "ProcessorId"
*/