|
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
|
|
|
|
|
Hmmm, there has to be a better option than that I would think.
I could probably even use some sort of powershell command and open up a powershell workspace (hidden window), but if powershell can do it, I would think c sharp has to be able to do it, since powershell is built on c sharp.
I'm surprised that no one else on the internet has encountered this, as I haven't seen anything.
Is there something I can use that reads the 64 bit hex or binary values? If I can return that data, I should be able to build something that can then interpolate it properly and spit out a value.
|
|
|
|
|
Eddy,
I have figured something out, I use the following, I get the decimal values back in the reverse order to the corresponding value
Any thoughts? I can do an array reversal and then remove anything that equaled 0 and convert to ascii?
byte[] byt = new byte[1024];
RegQueryValueEx(hkey, inPropertyName, 0, ref lpType, byt, ref lpcbData);
foreach (byte b in byt)
{
MessageBox.Show(b.ToString());
}
|
|
|
|
|
How about something like this?
byte[] bytes = Convert.FromBase64String(base64String); GZipStream stream.. stream.Write(bytes,0,bytes.length);
|
|
|
|
|
The data is not in base64-encoding, and it's not a pkzip-archive.
How would you do it in PowerShell? Perhaps we can translate that code to C#?
Bastard Programmer from Hell
|
|
|
|
|
Thanks for sparking some thought and putting me in the right direction.
Here is what I ended up doing (some constants and pin invokes are needed from the first post), you can then call the method and get the return value of a hex or dec number, the registry key in the first code section below will call a 64 bit key that is on every 2008 server and allow for testing with this from a 32 bit OS.
GetRegKey64DWord has the actual parsing code. This is an "unclean" version of the code, as I just got it working, hopefully I'll have a full class soon.
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);
}
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 = GetRegKey64DWord(remKeyUIntPtr, keyPath, RegSAM.WOW64_64Key, stringValue);
RegCloseKey(remKey);
return (result);
}
static public string GetRegKey64DWord(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();
byte[] byt = new byte[1024];
RegQueryValueEx(hkey, inPropertyName, 0, ref lpType, byt, ref lpcbData);
Array.Reverse(byt, 0, byt.Length);
byte[] truncated = new byte[1024];
int i = 0;
foreach (byte b in byt)
{
if (b != 0)
{
truncated[i] = b;
i = i + 1;
}
}
string hex = BitConverter.ToString(truncated);
int index = hex.IndexOf("00");
hex = hex.Remove(index);
hex = hex.Replace("-", "");
int decValue = int.Parse(hex, System.Globalization.NumberStyles.HexNumber);
return (hex + " " + decValue);
}
finally
{
if (0 != hkey) RegCloseKey(hkey);
}
}
|
|
|
|
|
Hello,
when I move the mouse into a pane containig a bitmap (an image), I get a dark grey cross as mouse cursor.
This seems to be the default in C# with .Net 4.0.
Is there a possibility to change the color of this cross e. g. to a bright yellow, because in many cases the dark grey cursor cross is hard to see.
I tried the Cursor.LineColor property, but this did not work. The cursor is still grey.
I also tried to create a custom cursor (created as bitmap and changed to a .cur file). But I was not successful using Visual Studio C# 2010 Express. The provided examples show things I cannot find in the Express version of VS.
E. g. "Project->Add New Item->General->Cursor File" to add a Cursor File as a ressource.
There is no "General" in VS Express.
Any hint how to do the color change is highly appreciated.
Many thanks in advance
Wolfgang
|
|
|
|
|
It's not a dark grey cross, the cross is the monochrome inverse of the color below it - so a white area shows as black, and a black area shows white. It's pretty much the clearest way to show it - any specific color could get lost if the background is the same color.
You can do it in code though. Have a look at this tutorial: http://www.switchonthecode.com/tutorials/csharp-tutorial-how-to-use-custom-cursors[^] - It's a little advanced, but if you just follow the instructions to the letter it should let you do what you want.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Since the user can change it cursor theme, you have to aware that a custom cursor might not fit with the current user theme...
As far as I know the cross cursor is generally black and .NET only uses standard cursors...
Philippe Mori
|
|
|
|
|
Many thanks for the quick responses.
You are right, the color of the cursor is changing, but in my images there is a kind of blueish purple, which seems to have no real contrast complementary color, so the cursor is dark grey and really hard to see.
If I move it to an other background it gets red and that is OK!
Many thanks again.
wolfgang
|
|
|
|
|
Hi all. I have a read/write project. In this part, I'm getting ready to read from the file, but before I do that, I check to make sure the fileNamePath exists, and if it doesn't I use my default path to get the filename from. So, I'm passing a fileNamePath to my method and I want to check if the directory exists before I use it.
My fileNamePath for this test is defined as an empty string, @"", so it doesn't exist. When I create my DirectoryInfo with the path, it's throwing the System.ArgumentException. This is how I create it:
DirectoryInfo di1 = new DirectoryInfo(fileNamePath);//throws exception
After this, I would do this:
if(di1.Exists) //but it doesn't get this far.
Any ideas what the problem could be? I just need to detect that the directory doesn't exist so I can use my default dir. I've tried
myTempDir = Path.GetDirectoryName(fileNamePath);
if(Directory.Exists(myTempDir)
but that had issues too.
Thanks!!
|
|
|
|
|
Use Directory.Exists("") instead.
Reread your message.
MichCl wrote: new DirectoryInfo(fileNamePath);//throws exception
Yes it will. The path doesn't exist so you can't very well get any directory info for it.
MichCl wrote: if(Directory.Exists(myTempDir)
Why would this have issues?
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
modified 23-Mar-12 11:15am.
|
|
|
|
|
When I tried using that (I am typically handling a full file/name path, such as "C:\backup\2012\our project\FileIO\FileIO\bin\Test\ReadMe.txt", at this point) it's not getting past the part where I extract the directory from the path before I check Directory.Exists with the empty string:
myTempDir = Path.GetDirectoryName(fileNamePath);
Any thoughts on this?
Thanks!!!!
|
|
|
|
|