|
Thank you guys for your help The problem is solved finally
|
|
|
|
|
try ZedGraph. its much more flexible and I have used it for real time updates
http://zedgraph.sourceforge.net
|
|
|
|
|
The Game:
The game consists of randomly generating numbers 1-80 1 at a time until 20 buttons backcolor is changed to a different color.
The Problem:
Currently, the game is picking the numbers way to fast and it appears to be picking them from bottom (button80)to top(button1). The numbers do however seem to be random but I need it to pick the numbers from different parts on the form.
Any help I would greatly appreciate.
|
|
|
|
|
Tailean wrote: Currently, the game is picking the numbers way to fast
Picking a random number is nearly instant. Can you explain what the computer should be waiting for?
Tailean wrote: The numbers do however seem to be random but I need it to pick the numbers from different parts on the form.
Which different parts, and what do they contain?
Can you post the code that you are using to generate the numbers and assing the colors?
Bastard Programmer from Hell
|
|
|
|
|
In Keno, the numbers are selected at random and at a slow speed one by one until 20 numbers are selected.
Also in Keno, there are 80 numbers represented in my program by buttons. Right now it chooses random numbers starting at button80 and working backwards. I need it to pick from a random spot on the form 1 at a time.
Here is the code:
private void button81_Click(object sender, EventArgs e)
{
tokenChecking();
resetColors();
timer1.Enabled = true;
timer1.Tick += new EventHandler(timer2_Tick);
Random random = new Random();
Byte[] randArray = new Byte[20];
random.NextBytes(randArray);
tokenTextBox.Text = "" + tokenTracker;
textBox1.Clear();
for (int i = 0; i <= randArray.Length; i++)
{
returnValue = random.Next(1, 80);
if (returnValue < 0)
{
returnValue = returnValue * -1;
++tracker;
}
if (returnValue == 1)
{
button1.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 2)
{
button2.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 3)
{
button3.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 4)
{
button4.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 5)
{
button5.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 6)
{
button6.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 7)
{
button7.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 8)
{
button8.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 9)
{
button9.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 10)
{
button10.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 11)
{
button11.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 12)
{
button12.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 13)
{
button13.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 14)
{
button14.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 15)
{
button15.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 16)
{
button16.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 17)
{
button17.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 18)
{
button18.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 19)
{
button19.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 20)
{
button20.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 21)
{
button21.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 22)
{
button22.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 23)
{
button23.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 24)
{
button24.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 25)
{
button25.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 26)
{
button26.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 27)
{
button27.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 28)
{
button28.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 29)
{
button29.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 30)
{
button30.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 31)
{
button31.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 32)
{
button32.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 33)
{
button33.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 34)
{
button34.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 35)
{
button35.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 36)
{
button36.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 37)
{
button37.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 38)
{
button38.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 39)
{
button39.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 40)
{
button40.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 41)
{
button41.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 42)
{
button42.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 43)
{
button43.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 44)
{
button44.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 45)
{
button45.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 46)
{
button46.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 47)
{
button47.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 48)
{
button48.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 49)
{
button49.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 50)
{
button50.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 51)
{
button51.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 52)
{
button52.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 53)
{
button53.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 54)
{
button54.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 55)
{
button55.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 56)
{
button56.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 57)
{
button57.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 58)
{
button58.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 59)
{
button59.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 60)
{
button60.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 61)
{
button61.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 62)
{
button62.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 63)
{
button63.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 64)
{
button64.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 65)
{
button65.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 66)
{
button66.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 67)
{
button67.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 68)
{
button68.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 69)
{
button69.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 70)
{
button70.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 71)
{
button71.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 72)
{
button72.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 73)
{
button73.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 74)
{
button74.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 75)
{
button75.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 76)
{
button76.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 77)
{
button77.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 78)
{
button78.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 79)
{
button79.BackColor = Color.Orange;
++tracker;
}
if (returnValue == 80)
{
button80.BackColor = Color.Orange;
++tracker;
}
}
timer1.Stop();
returnValue = 0;
|
|
|
|
|
Change the code to this, click five times;
{
tokenChecking();
resetColors();
timer1.Tick += new EventHandler(timer2_Tick);
timer1.Enabled = true;
MessageBox.Show("Test");
Random rnd = new Random(Environment.TickCount);
Byte[] randArray = new Byte[20];
rnd.NextBytes(randArray);
tokenTextBox.Text = "" + tokenTracker;
textBox1.Clear();
for (int i = 0; i <= randArray.Length; i++)
{
n = rnd.Next(1, 80);
if (n < 0)
{
throw new Exception(
"http://msdn.microsoft.com/en-us/library/2dx6wyd4.aspx");
}
if (n == 0) throw new Exception();
Color someRandomColor = Color.FromArgb(
rnd.Next(0,255),
rnd.Next(0,255),
rnd.Next(0,255));
Controls["button" + n.ToString()].BackColor = someRandomColor;
..to what value has your timer been set? 1000 milliseconds interval?
Bastard Programmer from Hell
|
|
|
|
|
Thank you so much for taking the time to do that. I learnt A LOT from that little bit of info. I am going to mess with my code now =)
|
|
|
|
|
You're welcome
|
|
|
|
|
Hi people I am using 3 panels in a windows form along with 3 buttons. I want to display the panels when I click the buttons respectively. i.e;
When I click button1,panel1 will display and when I click button2,panel2 will display and so on. And if I want to see any panel randomly i should be able to see it.
Please Help people
|
|
|
|
|
Dexter Arora wrote: Please Help people
With what exactly?
Find yourself a good introductory book on programming.
Bastard Programmer from Hell
|
|
|
|
|
I have tried doing that also on all three buttons. keeping a particular panel visible on clicking a particular button its not working.
|
|
|
|
|
What does "it's not working" mean exactly?
Can you paste your code?
Bastard Programmer from Hell
|
|
|
|
|
public partial class Asset_Management : Form
{
public Asset_Management()
{
InitializeComponent();
panelUpdate.Visible = false;
panelReport.Visible = false;
panelDetail.Visible = false;
}
private void Asset_Management_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
panelDetail.Visible = true;
panelReport.Visible = false;
panelUpdate.Visible = false;
}
private void button2_Click(object sender, EventArgs e)
{
panelUpdate.Visible = true;
panelReport.Visible = false;
panelDetail.Visible = false;
}
private void button3_Click(object sender, EventArgs e)
{
panelReport.Visible = true;
panelUpdate.Visible = false;
panelUpdate.Visible = false;
}
|
|
|
|
|
..and all three panels are located on the form?
private void Asset_Management_Load(object sender, EventArgs e)
{
panelUpdate.Parent = this;
panelReport.Parent = this;
panelDetail.Parent = this;
}
private void button1_Click(object sender, EventArgs e)
{
panelDetail.Visible = true;
panelReport.Visible = false;
panelUpdate.Visible = false;
MessageBox.Show("Test");
}
What does "not work" mean? Does anything happen at all if you click the button?
Bastard Programmer from Hell
|
|
|
|
|
Yes all the panels are on 1 form only.
"Not Work" : When I click on the buttons once,they shows the panels accordingly but when I click them again they don`t perform the desired task. i.e; they don`t show the required panel.
|
|
|
|
|
have you considered using JQuery to load all three panels, but show only the that is desired?
|
|
|
|
|
Frankly speaking I am not familiar with JQuery so that`s why I didn`t use that. I tried making the panels as the parent. Its showing the panels acording to the click of the button but not in proper position.
modified 26-Mar-12 13:56pm.
|
|
|
|
|
I wrote a class to read 64 bit registry keys (server) from a 32bit os (workstation) but I cannot get it to read D_Word values, however it will read Reg_Sz values. The D_Word values it returns are gibberish and symbols and I'm just not sure why? I thought it might be because the function that uses RegQueryValueEx is writing the answer to a stringbuilder type and the value of the regword I was testing on was hex, but I couldn't seem to make it work.
Sorry I don't have a better way to post the class without it being so long, I thought there used to be a 'code block' button ... either way thanks for reading.
private void button6_Click(object sender, EventArgs e)
{
string result = _64to32bit.reg64reader("[servername]", "HKEY_LOCAL_MACHINE", @"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "InstallDate");
MessageBox.Show(result);
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using System.Windows.Forms;
namespace Updator
{
class _64to32bit
{
public enum RegSAM
{
QueryValue = 0x0001,
SetValue = 0x0002,
CreateSubKey = 0x0004,
EnumerateSubKeys = 0x0008,
Notify = 0x0010,
CreateLink = 0x0020,
WOW64_32Key = 0x0200,
WOW64_64Key = 0x0100,
WOW64_Res = 0x0300,
Read = 0x00020019,
Write = 0x00020006,
Execute = 0x00020019,
AllAccess = 0x000f003f
}
[DllImport("Advapi32.dll")]
static extern uint RegOpenKeyEx(
UIntPtr hKey,
string lpSubKey,
uint ulOptions,
int samDesired,
out int phkResult);
[DllImport("Advapi32.dll")]
static extern uint RegCloseKey(int hKey);
[DllImport("advapi32.dll", EntryPoint = "RegQueryValueEx")]
public static extern int RegQueryValueEx(
int hKey,
string lpValueName,
int lpReserved,
ref RegistryValueKind lpType,
StringBuilder lpData,
ref uint lpcbData);
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, EntryPoint = "RegQueryValueEx")]
private static extern int RegQueryValueEx(
int hKey,
string lpValueName,
int lpReserved,
ref RegistryValueKind lpType,
[Out] byte[] lpData,
ref uint lpcbData);
[DllImport("advapi32.dll", SetLastError = true)]
static extern uint RegQueryValueEx(
UIntPtr hKey,
string lpValueName,
int lpReserved,
ref RegistryValueKind lpType,
IntPtr lpData,
ref int lpcbData);
[DllImport("advapi32")]
static extern int RegConnectRegistry(string machine, UIntPtr hKey, out
IntPtr pRemKey);
[DllImport("advapi32")]
static extern int RegCloseKey(IntPtr hKey);
[DllImport("advapi32")]
static extern int RegSaveKey(IntPtr hKey, string fileout, IntPtr
secdesc);
const uint HKEY_CLASSES_ROOT = 0x80000000;
const uint HKEY_CURRENT_USER = 0x80000001;
const uint HKEY_LOCAL_MACHINE = 0x80000002;
const uint HKEY_USERS = 0x80000003;
const uint HKEY_CURRENT_CONFIG = 0x80000005;
const uint HKEY_DYN_DATA = 0x80000006;
const uint HKEY_PERFORMANCE_DATA = 0x80000007;
public static string reg64reader(string serverName, string hive, string keyPath, string stringValue)
{
uint hiveConst = HKEY_LOCAL_MACHINE;
switch (hive)
{
case "hkcr":
hiveConst = HKEY_CLASSES_ROOT;
break;
case "hkey_classes_root":
hiveConst = HKEY_CLASSES_ROOT;
break;
case "HKCR":
hiveConst = HKEY_CLASSES_ROOT;
break;
case "HKEY_CLASSES_ROOT":
hiveConst = HKEY_CLASSES_ROOT;
break;
case "hkcu":
hiveConst = HKEY_CURRENT_USER;
break;
case "hkey_current_user":
hiveConst = HKEY_CURRENT_USER;
break;
case "HKCU":
hiveConst = HKEY_CURRENT_USER;
break;
case "HKEY_CURRENT_USER":
hiveConst = HKEY_CURRENT_USER;
break;
case "hklm":
hiveConst = HKEY_LOCAL_MACHINE;
break;
case "hkey_local_machine":
hiveConst = HKEY_LOCAL_MACHINE;
break;
case "HKLM":
hiveConst = HKEY_LOCAL_MACHINE;
break;
case "HKEY_LOCAL_MACHINE":
hiveConst = HKEY_LOCAL_MACHINE;
break;
case "hku":
hiveConst = HKEY_USERS;
break;
case "hkey_users":
hiveConst = HKEY_USERS;
break;
case "HKU":
hiveConst = HKEY_USERS;
break;
case "HKEY_USERS":
hiveConst = HKEY_USERS;
break;
case "hkcc":
hiveConst = HKEY_CURRENT_CONFIG;
break;
case "hkey_current_config":
hiveConst = HKEY_CURRENT_CONFIG;
break;
case "HKCC":
hiveConst = HKEY_CURRENT_CONFIG;
break;
case "HKEY_CURRENT_CONFIG":
hiveConst = HKEY_CURRENT_CONFIG;
break;
case "hkdd":
hiveConst = HKEY_DYN_DATA;
break;
case "hkey_dyn_data":
hiveConst = HKEY_DYN_DATA;
break;
case "HKDD":
hiveConst = HKEY_DYN_DATA;
break;
case "HKEY_DYN_DATA":
hiveConst = HKEY_DYN_DATA;
break;
case "hkpd":
hiveConst = HKEY_PERFORMANCE_DATA;
break;
case "hkey_performance_data":
hiveConst = HKEY_PERFORMANCE_DATA;
break;
case "HKPD":
hiveConst = HKEY_PERFORMANCE_DATA;
break;
case "HKEY_PERFORMANCE_DATA":
hiveConst = HKEY_PERFORMANCE_DATA;
break;
default:
MessageBox.Show("Default");
break;
}
UIntPtr key = new UIntPtr(hiveConst);
IntPtr remKey;
int ret = RegConnectRegistry(serverName, key, out remKey);
UIntPtr remKeyUIntPtr = unchecked((UIntPtr)(long)(ulong)remKey);
string result = GetRegKey64(remKeyUIntPtr, keyPath, RegSAM.WOW64_64Key, stringValue);
RegCloseKey(remKey);
return (result);
}
static public string GetRegKey64(UIntPtr inHive, String inKeyName, RegSAM in32or64key, String inPropertyName)
{
int hkey = 0;
try
{
uint lResult = RegOpenKeyEx(inHive, inKeyName, 0, (int)RegSAM.QueryValue | (int)in32or64key, out hkey);
if (0 != lResult) return null;
RegistryValueKind lpType = 0;
uint lpcbData = 1024;
StringBuilder strBuffer = new StringBuilder(1024);
RegQueryValueEx(hkey, inPropertyName, 0, ref lpType, strBuffer, ref lpcbData);
string value = strBuffer.ToString();
return value;
}
finally
{
if (0 != hkey) RegCloseKey(hkey);
}
}
public static string registryValueKind(string hiveName, string serverName, string entireSubKey, string keyName, string _32or64bit)
{
string returnValue = null;
string VerificationTypeChecked = "";
string VerificationValueChecked = "";
if (serverName == null)
{
if (_32or64bit == "32bit")
{
RegistryKey hive = Registry.LocalMachine;
switch (hiveName)
{
case "hkcr":
hive = Registry.ClassesRoot;
break;
case "hkey_classes_root":
hive = Registry.ClassesRoot;
break;
case "HKCR":
hive = Registry.ClassesRoot;
break;
case "HKEY_CLASSES_ROOT":
hive = Registry.ClassesRoot;
break;
case "hkcu":
hive = Registry.CurrentUser;
break;
case "hkey_current_user":
hive = Registry.CurrentUser;
break;
case "HKCU":
hive = Registry.CurrentUser;
break;
case "HKEY_CURRENT_USER":
hive = Registry.CurrentUser;
break;
case "hklm":
hive = Registry.LocalMachine;
break;
case "hkey_local_machine":
hive = Registry.LocalMachine;
break;
case "HKLM":
hive = Registry.LocalMachine;
break;
case "HKEY_LOCAL_MACHINE":
hive = Registry.LocalMachine;
break;
case "hku":
hive = Registry.Users;
break;
case "hkey_users":
hive = Registry.Users;
break;
case "HKU":
hive = Registry.Users;
break;
case "HKEY_USERS":
hive = Registry.Users;
break;
case "hkcc":
hive = Registry.CurrentConfig;
break;
case "hkey_current_config":
hive = Registry.CurrentConfig;
break;
case "HKCC":
hive = Registry.CurrentConfig;
break;
case "HKEY_CURRENT_CONFIG":
hive = Registry.CurrentConfig;
break;
case "hkdd":
hive = Registry.DynData;
break;
case "hkey_dyn_data":
hive = Registry.DynData;
break;
case "HKDD":
hive = Registry.DynData;
break;
case "HKEY_DYN_DATA":
hive = Registry.DynData;
break;
case "hkpd":
hive = Registry.PerformanceData;
break;
case "hkey_performance_data":
hive = Registry.PerformanceData;
break;
case "HKPD":
hive = Registry.PerformanceData;
break;
case "HKEY_PERFORMANCE_DATA":
hive = Registry.PerformanceData;
break;
default:
MessageBox.Show("Default");
break;
}
RegistryKey rk = hive;
RegistryKey localHive = rk.OpenSubKey(entireSubKey);
RegistryValueKind rvk = (RegistryValueKind)(localHive.GetValueKind(keyName));
switch (rvk)
{
case RegistryValueKind.MultiString:
VerificationTypeChecked = "REG_MULTI_SZ";
break;
case RegistryValueKind.Binary:
VerificationTypeChecked = "REG_BINARY";
break;
case RegistryValueKind.DWord:
VerificationTypeChecked = "REG_DWORD";
break;
case RegistryValueKind.ExpandString:
VerificationTypeChecked = "REG_EXPAND_SZ";
break;
case RegistryValueKind.QWord:
VerificationTypeChecked = "REG_QWORD";
break;
case RegistryValueKind.String:
VerificationTypeChecked = "REG_SZ";
break;
case RegistryValueKind.Unknown:
VerificationTypeChecked = "REG_RESOURCE_LIST";
break;
}
string VerificationValueOriginal = "";
try
{
VerificationValueOriginal = (localHive.OpenSubKey(entireSubKey, true).GetValue(keyName).ToString());
}
catch (Exception)
{
throw;
}
if (VerificationTypeChecked == "REG_MULTI_SZ")
{
object rgv = localHive.GetValue(keyName);
if (rgv.GetType().ToString() == "System.String[]")
{
string[] rgs = (string[])rgv;
if (rgs.Length > 0)
{
for (int k = 0; k < rgs.Length; k++)
{
VerificationValueChecked = VerificationValueChecked + " " + Convert.ToString(rgs[k]);
}
VerificationValueChecked = VerificationValueChecked.Trim();
returnValue = VerificationValueChecked;
}
else
{
VerificationValueChecked = VerificationValueOriginal;
returnValue = VerificationValueChecked;
}
}
else
{
VerificationValueChecked = VerificationValueOriginal;
returnValue = VerificationValueChecked;
}
}
else
{
returnValue = VerificationValueOriginal;
}
return (returnValue);
}
if (_32or64bit == "64bit")
{
MessageBox.Show("Inside registryValueKind and == 64bit");
return ("It is 64bit");
}
}
if (serverName != null)
{
RegistryHive regHive = registryHive(hiveName);
if (_32or64bit == "32bit")
{
RegistryKey remoteHive = RegistryKey.OpenRemoteBaseKey(regHive, serverName);
RegistryValueKind rvk = (RegistryValueKind)(remoteHive.OpenSubKey(entireSubKey).GetValueKind(keyName));
switch (rvk)
{
case RegistryValueKind.MultiString:
VerificationTypeChecked = "REG_MULTI_SZ";
break;
case RegistryValueKind.Binary:
VerificationTypeChecked = "REG_BINARY";
break;
case RegistryValueKind.DWord:
VerificationTypeChecked = "REG_DWORD";
break;
case RegistryValueKind.ExpandString:
VerificationTypeChecked = "REG_EXPAND_SZ";
break;
case RegistryValueKind.QWord:
VerificationTypeChecked = "REG_QWORD";
break;
case RegistryValueKind.String:
VerificationTypeChecked = "REG_SZ";
break;
case RegistryValueKind.Unknown:
VerificationTypeChecked = "REG_RESOURCE_LIST";
break;
}
string VerificationValueOriginal = "";
try
{
VerificationValueOriginal = (remoteHive.OpenSubKey(entireSubKey, true).GetValue(keyName).ToString());
}
catch (Exception)
{
throw;
}
if (VerificationTypeChecked == "REG_MULTI_SZ")
{
object rgv = remoteHive.GetValue(keyName);
if (rgv.GetType().ToString() == "System.String[]")
{
string[] rgs = (string[])rgv;
if (rgs.Length > 0)
{
for (int k = 0; k < rgs.Length; k++)
{
VerificationValueChecked = VerificationValueChecked + " " + Convert.ToString(rgs[k]);
}
VerificationValueChecked = VerificationValueChecked.Trim();
returnValue = VerificationValueChecked;
}
else
{
VerificationValueChecked = VerificationValueOriginal;
returnValue = VerificationValueChecked;
}
}
else
{
VerificationValueChecked = VerificationValueOriginal;
returnValue = VerificationValueChecked;
}
}
else
{
returnValue = VerificationValueOriginal;
}
return (returnValue);
}
if (_32or64bit == "64bit")
{
MessageBox.Show("Inside registryValueKind and == 64bit");
return ("It is 64bit");
}
}
return (returnValue);
}
private static RegistryHive registryHive(string hKey)
{
RegistryHive hive = RegistryHive.LocalMachine;
switch (hKey)
{
case "hkcr":
hive = RegistryHive.ClassesRoot;
break;
case "hkey_classes_root":
hive = RegistryHive.ClassesRoot;
break;
case "HKCR":
hive = RegistryHive.ClassesRoot;
break;
case "HKEY_CLASSES_ROOT":
hive = RegistryHive.ClassesRoot;
break;
case "hkcu":
hive = RegistryHive.CurrentUser;
break;
case "hkey_current_user":
hive = RegistryHive.CurrentUser;
break;
case "HKCU":
hive = RegistryHive.CurrentUser;
break;
case "HKEY_CURRENT_USER":
hive = RegistryHive.CurrentUser;
break;
case "hklm":
hive = RegistryHive.LocalMachine;
break;
case "hkey_local_machine":
hive = RegistryHive.LocalMachine;
break;
case "HKLM":
hive = RegistryHive.LocalMachine;
break;
case "HKEY_LOCAL_MACHINE":
hive = RegistryHive.LocalMachine;
break;
case "hku":
hive = RegistryHive.Users;
break;
case "hkey_users":
hive = RegistryHive.Users;
break;
case "HKU":
hive = RegistryHive.Users;
break;
case "HKEY_USERS":
hive = RegistryHive.Users;
break;
case "hkcc":
hive = RegistryHive.CurrentConfig;
break;
case "hkey_current_config":
hive = RegistryHive.CurrentConfig;
break;
case "HKCC":
hive = RegistryHive.CurrentConfig;
break;
case "HKEY_CURRENT_CONFIG":
hive = RegistryHive.CurrentConfig;
break;
case "hkdd":
hive = RegistryHive.DynData;
break;
case "hkey_dyn_data":
hive = RegistryHive.DynData;
break;
case "HKDD":
hive = RegistryHive.DynData;
break;
case "HKEY_DYN_DATA":
hive = RegistryHive.DynData;
break;
case "hkpd":
hive = RegistryHive.PerformanceData;
break;
case "hkey_performance_data":
hive = RegistryHive.PerformanceData;
break;
case "HKPD":
hive = RegistryHive.PerformanceData;
break;
case "HKEY_PERFORMANCE_DATA":
hive = RegistryHive.PerformanceData;
break;
default:
MessageBox.Show("Default");
break;
}
return (hive);
}
private static RegistryKey registryHiveLocal(string hKey)
{
RegistryKey hive = Registry.LocalMachine;
switch (hKey)
{
case "hkcr":
hive = Registry.ClassesRoot;
break;
case "hkey_classes_root":
hive = Registry.ClassesRoot;
break;
case "HKCR":
hive = Registry.ClassesRoot;
break;
case "HKEY_CLASSES_ROOT":
hive = Registry.ClassesRoot;
break;
case "hkcu":
hive = Registry.CurrentUser;
break;
case "hkey_current_user":
hive = Registry.CurrentUser;
break;
case "HKCU":
hive = Registry.CurrentUser;
break;
case "HKEY_CURRENT_USER":
hive = Registry.CurrentUser;
break;
case "hklm":
hive = Registry.LocalMachine;
break;
case "hkey_local_machine":
hive = Registry.LocalMachine;
break;
case "HKLM":
hive = Registry.LocalMachine;
break;
case "HKEY_LOCAL_MACHINE":
hive = Registry.LocalMachine;
break;
case "hku":
hive = Registry.Users;
break;
case "hkey_users":
hive = Registry.Users;
break;
case "HKU":
hive = Registry.Users;
break;
case "HKEY_USERS":
hive = Registry.Users;
break;
case "hkcc":
hive = Registry.CurrentConfig;
break;
case "hkey_current_config":
hive = Registry.CurrentConfig;
break;
case "HKCC":
hive = Registry.CurrentConfig;
break;
case "HKEY_CURRENT_CONFIG":
hive = Registry.CurrentConfig;
break;
case "hkdd":
hive = Registry.DynData;
break;
case "hkey_dyn_data":
hive = Registry.DynData;
break;
case "HKDD":
hive = Registry.DynData;
break;
case "HKEY_DYN_DATA":
hive = Registry.DynData;
break;
case "hkpd":
hive = Registry.PerformanceData;
break;
case "hkey_performance_data":
hive = Registry.PerformanceData;
break;
case "HKPD":
hive = Registry.PerformanceData;
break;
case "HKEY_PERFORMANCE_DATA":
hive = Registry.PerformanceData;
break;
default:
MessageBox.Show("Default");
break;
}
return (hive);
}
}
}
modified 23-Mar-12 15:35pm.
|
|
|
|
|
turbosupramk3 wrote: I wrote a class to read 64 bit registry keys (server) from a 32bit os (workstation) but I cannot get it to read D_Word values
How large would a DWORD be in a 64-bit environment? And in what datatype would you fit it in a 32-bit environment?
Bastard Programmer from Hell
|
|
|
|
|
Well, you'd think it would be a long ... but I'm really not sure? They have Q_Words which should equate to a double long.
If you test my class, it will read Reg_Sz keys, but not d_words, so it makes sense to me that it'd be a data type issue?
What do you think?
|
|
|
|
|
I think that a dword is (in both cases) a long that maps to Int32. I guess that what you're fetching is an uint64.
Having a QWord doesn't mean that there's also a Q-datatype. We've been manipulating very large numbers in the days before the BigInt that would only fit in a string.
Bastard Programmer from Hell
|
|
|
|
|
Hi, thanks for the reply.
So (when I get back to the office on Monday) if I change the appropriate uInt's to Int32's in the code section below, I should be able to make this work?
UIntPtr key = new UIntPtr(hiveConst);
IntPtr remKey;
int ret = RegConnectRegistry(serverName, key, out remKey);
UIntPtr remKeyUIntPtr = unchecked((UIntPtr)(long)(ulong)remKey);
string result = GetRegKey64(remKeyUIntPtr, keyPath, RegSAM.WOW64_64Key, stringValue);
RegCloseKey(remKey);
return (result);
}
static public string GetRegKey64(UIntPtr inHive, String inKeyName, RegSAM in32or64key, String inPropertyName)
{
int hkey = 0;
try
{
uint lResult = RegOpenKeyEx(inHive, inKeyName, 0, (int)RegSAM.QueryValue | (int)in32or64key, out hkey);
if (0 != lResult) return null;
RegistryValueKind lpType = 0;
uint lpcbData = 1024;
StringBuilder strBuffer = new StringBuilder(1024);
RegQueryValueEx(hkey, inPropertyName, 0, ref lpType, strBuffer, ref lpcbData);
string value = strBuffer.ToString();
return value;
}
|
|
|
|
|
No, that would still result in a overflow, as an int32 cannot hold such a large value.
Can you read the same block of data using some other datatype? A string, an array of bytes?
Bastard Programmer from Hell
|
|
|
|
|
Based on the dll info, I can do the following, although stringbuilder was what I was trying originally and that was what returned gibberish and strange characters.
[DllImport("advapi32.dll", EntryPoint = "RegQueryValueEx")]
public static extern int RegQueryValueEx(
int hKey,
string lpValueName,
int lpReserved,
ref RegistryValueKind lpType,
StringBuilder lpData,
ref uint lpcbData);
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, EntryPoint = "RegQueryValueEx")]
private static extern int RegQueryValueEx(
int hKey,
string lpValueName,
int lpReserved,
ref RegistryValueKind lpType,
[Out] byte[] lpData,
ref uint lpcbData);
|
|
|
|
|
It seems that the 32-bit version of RegQueryValueEx[^] has no idea on larger numbers.
How about simply reading it locally with a .NET app and sending that back?
Bastard Programmer from Hell
|
|
|
|
|