谁能帮我把VB6.0代码转换成c#代码
Set oRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\./root/default:StdRegProv")Call oRegistry.EnumKey(&H80000002, "System\CurrentControlSet\Enum\Display\", SubKeys1)
For Each SubKey1 In SubKeys1
Call oRegistry.EnumKey(&H80000002, "System\CurrentControlSet\Enum\Display\" & SubKey1 & "\", SubKeys2)
For Each SubKey2 In SubKeys2
Call oRegistry.GetMultiStringValue(&H80000002, "System\CurrentControlSet\Enum\Display\" & SubKey1 & "\" & SubKey2 & "\", "HardwareID", svalue)
For tmpctr = 0 To UBound(svalue)
If LCase(Left(svalue(tmpctr), 8)) = "monitor\" Then
Call oRegistry.EnumKey(&H80000002, "System\CurrentControlSet\Enum\Display\" & SubKey1 & "\" & SubKey2 & "\", SubKeys3)
For Each SubKey3 In SubKeys3
If SubKey3 = "Control" Then
Call oRegistry.GetBinaryValue(&H80000002, "System\CurrentControlSet\Enum\Display\" & SubKey1 & "\" & SubKey2 & "\" & "Device Parameters\", "EDID", MonitorParameter)
If VarType(MonitorParameter) <> 8204 Then
VsMonitor = "EDID Not Available"
Else
For Each bytevalue In MonitorParameter
VsMonitor = VsMonitor & Chr(bytevalue)
Next
End If
ReDim Preserve strarrRawEDID(intMonitorCount)
strarrRawEDID(intMonitorCount) = VsMonitor
intMonitorCount = intMonitorCount + 1
End If
Next
End If
Next
Next
Next --------------------编程问答-------------------- 这个真没法转、你只能用C#去实现相同的功能 --------------------编程问答-------------------- 你为什么不去问问写这代码的人的基本思路,然后再用自己的语言加以总结? --------------------编程问答-------------------- 我自转换成c# 啦,但是有两个键值的值取不到,单VB6.0就取不到,就很纳闷。。
c# 代码
ManagementClass mClass = new ManagementClass(@"\\" + "Pc-201008100839" + @"\root\DEFAULT:StdRegProv");
object[] method_args = new object[] { 0x80000002, @"System\CurrentControlSet\Enum\Display\",null };
mClass.InvokeMethod("EnumKey", method_args);
SubKeys1 = (string[])method_args[2];
foreach (var SubKey1 in SubKeys1)
{
object[] method_args1 = new object[] { 0x80000002, @"System\CurrentControlSet\Enum\Display\" + SubKey1+@"\", null};
mClass.InvokeMethod("EnumKey", method_args1);
SubKeys2 = (string[])method_args1[2];
foreach (var SubKey2 in SubKeys2)
{
ManagementBaseObject inParams = mClass.GetMethodParameters("GetStringValue");
inParams["hDefKey"] = 0x80000002;
inParams["sSubKeyName"] = @"System\CurrentControlSet\Enum\Display\" + SubKey1 + @"\" + SubKey2 + @"\";
inParams["sValueName"] = "HardwareID";
ManagementBaseObject curRes = mClass.InvokeMethod("GetStringValue", inParams, null);
svalue = curRes["sValue"].ToString(); 这个取不到值
object[] method_args2 = new object[] { 0x80000002, @"System\CurrentControlSet\Enum\Display\" + SubKey1 + @"\" + SubKey2 + @"\", null };
mClass.InvokeMethod("EnumKey", method_args2);
SubKeys3 = (string[])method_args2[2];
foreach (var SubKey3 in SubKeys3)
{
if (SubKey3 == "Control")
{
ManagementBaseObject inParams1 = mClass.GetMethodParameters("GetStringValue");
inParams1["hDefKey"] = 0x80000002;
inParams1["sSubKeyName"] = @"System\CurrentControlSet\Enum\Display\" + SubKey1 + @"\" + SubKey2 + @"\"+@"Device Parameters\";
inParams1["sValueName"] = "EDID";
ManagementBaseObject curRes1 = mClass.InvokeMethod("GetStringValue", inParams1, null);
svalue = curRes1["sValue"].ToString(); 这个取不到值
if (curRes1["sValue"] == null)
{
if(MonitorParameter!="8024")
{
VsMonitor = "EDID Not Available";
}
else
{
foreach(var bytevalue in MonitorParameter)
{
VsMonitor = VsMonitor + bytevalue.ToString();
}
}
}
strarrRawEDID[intMonitorCount] = VsMonitor;
intMonitorCount = intMonitorCount + 1;
}
}
}
} --------------------编程问答-------------------- 打错了。VB6.0就取得到 --------------------编程问答-------------------- 对啊,了解下逻辑,自己去写相同的功能呗
你找转换,是为了自己省事吧?
补充:.NET技术 , C#