|
Yeah, what Ian said.
Also...
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss" don't store dates as strings, use DateTime.
|
|
|
|
|
Hi again PIEBALDconsult,
I had to because I could find no other way to get my date to display as 2011-10-14 22:14:00. It kept reading as 14-10-2011 22:14:00.
I need it to do this for the purpose of sorting by date.
|
|
|
|
|
CCodeNewbie wrote: I need it to do this for the purpose of sorting by date.
No you don't.
CCodeNewbie wrote: display as 2011-10-14 22:14:00
Then format it when you display it, not when you store it.
And/or set your Region and Language settings in Control Panel properly (which is what I do).
|
|
|
|
|
Region and language settings are as they should be.
The front end is a MS Access mdb with long, medium or short date options, none of which put the year first unless I format it using built-in vba code.
I would therefore rather code it at source.
Is there a reason you are against outputting DateTime to string?
|
|
|
|
|
CCodeNewbie wrote: outputting DateTime to string?
No, I (and most experienced practitioners) are against storing DateTimes in strings.
CCodeNewbie wrote: The front end is a MS Access
Yuck.
CCodeNewbie wrote: unless I format it using built-in vba code.
Then do so.
|
|
|
|
|
OK, you win. I'll store the Datetime correctly
|
|
|
|
|
|
As PIEBALD already said:
1.
strings are intended for holding text, i.e. sequences of characters that don't have any particular meaning the computer may be interested in. Dates and times, integer numbers, real numbers, all have their proper types, both in programming languages and in SQL and other databases.
2.
The DateTime types in the database allow for sorting chronologically, as well as for date operations (there are functions to get to date parts: year, month, etc).
3.
formatting data is a job of the front-end program, not the database. A database just holds the data, without worrying aboiut formatting; you don't want to modify your database just because someone wants a different format; and what if different users want different formats? You don't store numbers as strings, for the sake of e.g. forcing leading zeroes; if that is what you need, get your code to deal with it. Similarly, you don't store dates and times as strings, they are inherently numbers, no more, no less.
4.
When writing SQL commands that need literal values, always use parameters, never have literal values in your SQL string itself. (You seem to be doing that right already).
5.
Never deviate from the above, it will bite you very badly.
|
|
|
|
|
|
=3628800
|
|
|
|
|
Does anyone have any code where I can read a 64bit registry key, remotely from a 32bit c sharp (.net 3.5) application?
I've seen RegOpenKeyExW, but that appears to be just for local and I need to do this remotely.
Thank you.
|
|
|
|
|
This[^] contains example on to read 64-bit registry information from a 32-bit application.
The example is for the local machine, but you should be able to convert it to read from remote machines by using RegConnectRegistry[^].
The first link also shows how it can be done with .NET 4.0, which is a lot easier.
Hope this helps.
0100000101101110011001000111001011101001
|
|
|
|
|
Hi André,
Thanks for the reply, I don't see much of a way to convert from local to remote ... do you have a function in your code you can post?
Unfortunately, .net 4 is not something I can use yet.
|
|
|
|
|
Does anyone else have a class that you can read 64bit keys remotely? It has to be possible to be able to do that before .net 4.0 ???
|
|
|
|
|
Here is the closest I could get, I cannot figure out how to convert "int ret" to a "UIntPtr inHive", and so I am not able to get any further or test.
What do you think?
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 _64to32bit3
{
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")]
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;
public static void reg64reader()
{
UIntPtr key = new UIntPtr(HKEY_LOCAL_MACHINE);
IntPtr remKey;
int ret = RegConnectRegistry("SERVERNAME", key, out remKey);
GetRegKey64(ret, @"SOFTWARE\Microsoft\DirectX", RegSAM.WOW64_64Key, "Version");
MessageBox.Show(GetRegKey64(ret, @"SOFTWARE\Microsoft\DirectX", RegSAM.WOW64_64Key, "Version").ToString());
RegCloseKey(remKey);
}
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);
}
}
}
}
|
|
|
|
|
How does this code look to everyone?
private void button6_Click(object sender, EventArgs e)
{
string result = _64to32bit.reg64reader("server name", "hive", @"key path", "key name");
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")]
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;
RegistryKey remoteKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, "ph-mb-05");
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);
}
}
}
}
|
|
|
|
|
Think it would be best if you make a new question of this.
I was able to find some links for you, but for this you need some more experienced help I think.
0100000101101110011001000111001011101001
|
|
|
|
|
Ok, well thank you for your help in this
|
|
|
|
|
The CodeDOM namespace is useful for dynamically generating code and compiling it.
But I need a slightly different thing: I'd like to read existing source code files, find all methods/properties/constructors in it, and add some more logging to the functions. I.e. I'd like to add a call to our logging function automatically as first line to every function, and - if possible - automatically add another call to the logging function before each return statement/end of function. And then save the changed source code file - for "normal" use with Visual Studio for further development.
There's an ICodeParser interface in CodeDOM - but no implementation seems to exist:
CSharpCodeProvider csc = new CSharpCodeProvider(new Dictionary<string, string>() { { "CompilerVersion", "v3.5" } });
ICodeParser parser = csc.CreateParser();
and parser is null.
CSharpCodeProvider csc = new CSharpCodeProvider(new Dictionary<string, string>() { { "CompilerVersion", "v3.5" } });
TextReader reader = new StreamReader(@"C:\Path\To\MySource.cs");
CodeCompileUnit ccu = csc.Parse(reader);
throws an Exception: this function is not supported.
An old article can be found here on code project - but its code fails already when reading following line:
public sealed partial class MyClass : System.Windows.Forms.Form
Does .NET provide some classes for that? Or are there some tools already available? I do not want to write my own source code parser.
|
|
|
|
|
|
Thanks for this nice idea.
When I read about Aspect Oriented Programming some time ago, it looked just like a new fashion. But now it seems to be useful.
|
|
|
|
|
hi folks,
i have a list of bitmap image files, which i want to convert into a single video file. i want to do this using visual studio C sharp. Can someone please help me on this? Any suggestions,sample code, links would be helpful.
Thanks in advance.
hema.
|
|
|
|
|
|
Hi,
I'd like to get access to file icon of any application. The Problem is, I'd like to have the one which has been generated as preview (Like a icon of a pptx (PowerPoint) file which is the first slide or like a video which has the first frame as icon).
Does anyone know how to access these kind of icons?
|
|
|
|
|
Using the Windows API Pack[^], you can do:
Image img = ShellFile.FromFilePath(@"C:\foo.pptx").Thumbnail.BitmapSource;
/ravi
|
|
|
|
|