|
It's best to define them in a static class and use the const modifier, somethink like this:
public static class Constants
{
public const int MyInt = 48000;
Standards are great! Everybody should have one!
|
|
|
|
|
Wow, thanks for the quick replies guys.
I better go read up on static classes ^^
Cheers 
|
|
|
|
|
I forgot to mention, not all of these will be constants, many of them will be modified during runtime, can i still use a static class for that?
|
|
|
|
|
|
yes, but if you want to change them they cant be const .
|
|
|
|
|
Surely you can, but I'm no friend of static what-so-ever because most of the times usage of statics lead to a poorly designed project (but that depends on what you want to do, of course).
Issues of statics:
- Robustness against multi threading
- tight coupling of components or monolithic design (instead of loose coupling)
- all problems that singletons have
However, this is just a design consideration, not a technical problem
-^-^-^-^-^-
no risk no funk ................... please vote ------>
|
|
|
|
|
Also you may consider using property to make it neat.
modified 17-Jul-19 21:02pm.
|
|
|
|
|
Hi!
How do we retrieve all the installed softwares in WMI? All means all the softwares being installed in the computer. I used win32_Product yet it only retrieves those microsoft softwares and it even displays everything added to that software like an update.
The following are the needed information:
Softwarename
InstallDate
SotwarePath
AllotedLocationType
RegistryPath
ExecutableFilename
LastUsed
TotalUsageDurationMins
IsUninstalled
IsHotfix
IsServicePack
isUnauthorized
Please help.
Thanks.
-- modified at 7:18 Thursday 16th August, 2007
|
|
|
|
|
You can enumerate keys for path...
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
..and then look for DisplayName, UninstallString and other values as suited.
If you get to know a better way out please do let me know as well
Cheers
H.
|
|
|
|
|
Have a look at my response[^]. At the bottom of it is the WMI query against the Win32_Product class that you can use, it's much simpler than enumerating over the registry keys.
|
|
|
|
|
Using WMI isn't the simplest thing to do from managed code. If you search Google, you'll find a lot of information. Here is sample code from a message[^] in the microsft.public.dotnet.framework.wmi newsgroup:
const uint HKEY_LOCAL_MACHINE = unchecked((uint)0x80000002);
ManagementClass wmiRegistry = new ManagementClass("root/default", "StdRegProv", null);
string keyPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
object[] methodArgs = new object[] {HKEY_LOCAL_MACHINE, keyPath, null};
uint returnValue = (uint)wmiRegistry.InvokeMethod("EnumKey", methodArgs);
Console.WriteLine("Executing EnumKey() returns: {0}", returnValue);
if (null != methodArgs[2])
{
string[] subKeys = methodArgs[2] as String[];
if (subKeys == null) return;
ManagementBaseObject inParam = wmiRegistry.GetMethodParameters("GetStringValue");
inParam["hDefKey"] = HKEY_LOCAL_MACHINE;
string keyName = "";
foreach(string subKey in subKeys)
{
keyPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + subKey;
keyName = "DisplayName";
inParam["sSubKeyName"] = keyPath;
inParam["sValueName"] = keyName;
ManagementBaseObject outParam = wmiRegistry.InvokeMethod("GetStringValue", inParam, null);
if ((uint)outParam["ReturnValue"] == 0)
Console.WriteLine(outParam["sValue"]);
}
} This is essentially just enumerating over the HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\ registry key, so you can use the normal .NET registry classes to do the same thing without WMI.
Using the Win32_Product class, you would want to do something like this:
ManagementObjectSearcher products = new ManagementObjectSearcher("SELECT * FROM Win32_Product");
foreach (ManagementObject product in products.Get())
{
Console.WriteLine("Software name: {0}", product.Name);
Console.WriteLine("Install date: {0}", product.InstallDate);
...
} The properties you list aren't all included in the Win32_Product[^] class, so you will probably need to do additional queries against other objects to get all of the information.
|
|
|
|
|
how about if we will display the installdate and installlocation using the latter code? or using the registry?
if inParam["sValueName"] = keyName is used to get the Displayname, how about the rest of the values? like installdate, softwarepath and the rest of the values?
|
|
|
|
|
toink toink wrote: how about if we will display the installdate and installlocation using the latter code? or using the registry?
What code are you referring to here?
toink toink wrote: if inParam["sValueName"] = keyName is used to get the Displayname, how about the rest of the values? like installdate, softwarepath and the rest of the values?
It sounds like you would probably do better to use this
ManagementObjectSearcher products = new ManagementObjectSearcher("SELECT * FROM Win32_Product");
foreach (ManagementObject product in products.Get())
{
Console.WriteLine("Software name: {0}", product.Name);
Console.WriteLine("Install date: {0}", product.InstallDate);
...
}
|
|
|
|
|
Hi,
I have a DataGridView control with one column as ComboBox control.
I want to raise the event "SelectedValueChanged" of combo box.
How to do this. Please help.
Thanks & Regards,
nas
|
|
|
|
|
read an article on deploying events in C# applications over MSDN or search google.
write this line in your constructor.
dataGridView1.SelectedValueChanged+=<then press="" the="" tab="" key="" twice="" you'll="" get="" right="" thing="" in="" here="">then you start coding in the function made for the event handler
Rocky
|
|
|
|
|
Hi Rocky,
Thanks for reply.
Actually in DataGridView we can make any Column-Type as controls (Button,ComboBox, CheckBox...).
So i have selected one column of DGV as ComboBox. But this ComboBox differs from the normal ComboBox control.
By coding i want to access the ComboBox control of the DGV. 
|
|
|
|
|
OK
I know ur talking abt the datagridviewcombobox control right? try using the event 'CellValueChanged' on the dGV and in that you can get the column as
if(e.columnIndex == yourdgvcomboboxname.ColumnIndex)
{
//perform you task
}
and c if this things works for u or not incaseif it does give this msg and full rating
|
|
|
|
|
hello,
i am doing a project by C# language and using visual studio2005.Net.
Now i need a C# code which reads excel file and save all datas to corresponding SQL Server data base.
plz help me i will be grateful to u.
Shafik
|
|
|
|
|
You can read data from excel file by OLE DB provider and then save the data to database using ADO.NET
|
|
|
|
|
Dear sir,
would u tell me details...
|
|
|
|
|
This question has been asked and answered numerous times on this forum already.
Please check existing posts before submitting a question...
Paul
|
|
|
|
|
Here you go: excel using ole db[^]
If you need more information search for the keywords. You can find examples both on codeproject and google
|
|
|
|
|
I need some code or direction to write code the code to add my application at startup.
There are some software to add the application at startup by i need my own codding.
|
|
|
|
|
Have a look at Managing start-up section at http://www.codeproject.com/csharp/Trayminimizer.asp
|
|
|
|
|
You can add path of your app to these registry keys, and those will be executed at computer startup...
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx
Cheers,
h.
|
|
|
|