|
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!!!!
|
|
|
|
|
string fileNamePath = @"C:\backup\2012\our project\FileIO\FileIO\bin\Test\ReadMe.txt";
string myTempDir = Path.GetDirectoryName(fileNamePath);
if (!Directory.Exists(myTempDir))
{
Console.WriteLine("Hi");
}
Works fine for me. Can you post the actual code that you are using?
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
|
|
|
|
|
It's when fileNamepath is @"" that the problem with using Path.GetDirectoryName happens. Maybe I'll catch the exception and if it happened, have them choose the directory or use my default dir.
|
|
|
|
|
You are doing things a little backwards.
Try this instead
if( Directory.Exists( fileNamePath ) )
{
DirectoryInfo di1 = new DirectoryInfo(fileNamePath);
}
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
I did that and didn't have to catch the extra exception! Much cleaner that way.
|
|
|
|
|
Glad I could help.
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
MichCl wrote: Any ideas what the problem could be?
The short answer is poor documentation, i.e. not mentioned on MSDN.
The constructor will reject bad paths and if there is the potential for a problem I think the only solution is to do some validation on the argument. Directory.Exists must be the method of choice here as it seems to be quite resilient and returns false for paths which would cause DirectoryInfo to throw.
Bad paths may result from:
Illegal characters (this one is documented)
new DirectoryInfo(@"*");
Path format not supported. This has it's own undocumented exception which caught me out, once! Why this isn't reported as an ArgumentException is beyond me.
di = new DirectoryInfo(@"\c:\");
and the one you've found
di = new DirectoryInfo(@"");
Alan.
|
|
|
|
|
Maybe I'll just catch the exception and use the default dir in that case or bring up the Directory Browser.
|
|
|
|
|
Yes that would be the most practical solution.
I've just been looking at the FileInfo constructor documentation and to be honest MS could do themselves a favour if they copied some of the info over to the DirectoryInfo page as it mentions empty paths and the NotSupportedException for embedded ':'.
Alan.
|
|
|
|
|
get any API for get count number of hits occurred for a particular keyword date wise from Gnews,facebook and twitter.
|
|
|
|
|
..there's not a unified api available that allows you to search all these sites in a single call. You'll have to make an interface to each site, using the SDK or API's provided by them.
Facebook[^]
Twitter[^]
Google News doesn't provide an API (it's not required). but there are feeds available for non commercial use.
Bastard Programmer from Hell
|
|
|
|
|
I am making a media player. so I need tool bar and seek bar. how I get these. thanks.
|
|
|
|
|
Are you using Win Forms? Just add a toolbar and add buttons to them. What issues are you having?
|
|
|
|
|
thanks.I need seek bar and volume bar as like in new vlc player.
|
|
|
|
|