|
After a little searching you don't have to, from Jeff's blog entry[^].
I put together the following class:
public class BuildInformation
{
private static readonly DateTime BuildOrigin = new DateTime(1970, 1, 1, 0, 0, 0);
private const int peHeaderOffset = 60;
private const int linkerTimestampOffset = 8;
private DateTime _BuildDate;
public DateTime BuildDate
{
get { return this._BuildDate; }
set { this._BuildDate = value; }
}
private Version _Version;
public Version Version
{
get { return this._Version; }
set { this._Version = value; }
}
private static DateTime GetBuildDate(string path)
{
byte[] b = new byte[2048];
using (FileStream fs = File.OpenRead(path))
{
fs.Read(b, 0, 2048);
fs.Close();
}
int i = BitConverter.ToInt32(b, peHeaderOffset);
int secondsSince1970 = BitConverter.ToInt32(b, i + linkerTimestampOffset);
DateTime dt = BuildOrigin.AddSeconds(secondsSince1970);
dt = dt.AddHours(TimeZone.CurrentTimeZone.GetUtcOffset(dt).Hours);
return dt;
}
public static BuildInformation Read(string path)
{
DateTime buildDate = GetBuildDate(path);
Version version = Assembly.LoadFrom(path).GetName().Version;
return new BuildInformation(buildDate, version);
}
private BuildInformation(DateTime buildDate, Version version)
{
this.BuildDate = buildDate;
this.Version = version;
}
}
Hope that helps, things could be tidied up a bit for example using an AppDomain to unload the assembly once it's been loaded etc but this should suffice for most cases.
I doubt it. If it isn't intuitive then we need to fix it. - Chris Maunder
|
|
|
|
|
Thanks I'll review it and soon provide a little something which we can use to update our PADs with latest Version and Date.
Looking for help on my OpenSource Media Player LetsYo
|
|
|
|
|
hi friends,
1- I want to have my current desktop wallpaper as an image and start processing it like a simple image importing through 'PictureBox'. how is that?
2- and how can i have the address of the current wallpaper in the hard drive?
modified on Saturday, June 7, 2008 8:05 AM
|
|
|
|
|
If your on Windows XP then the wallpaper is always here "C:\Documents and Settings\*user*\Local Settings\Application Data\Microsoft\Wallpaper1.bmp" " and is always a bitmap file.
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
i didn't know that. thanks a lot.
|
|
|
|
|
Hi friends
can any body tell me why we use attribute on Classes or Function
Like this
[attribute]
Class test
{
}
or
[attribute]
function abc
{
}
thanx for advance
wasim khan
|
|
|
|
|
|
Hi friends i want that when ever some body click the the close button of my form it should be minimize to System tray. i done all the work but i can not know how to handle the close (X) button so that user click it thee form should be minimize not closed.
wasim khan
|
|
|
|
|
in the FormClosing event use
e.Cancel = true;
this.WindowState = FormWindowState.Minimized; Don't forget to give your users another way to close the form though! Maybe set a flag (bool allowClose ) that is checked in this event so it's only minimized if the flag is false.
if (!allowClose)
{
e.Cancel = true;
this.WindowState = FormWindowState.Minimized;
}
Dave
|
|
|
|
|
Bingo!!!!!!!
thanx Dave its work.
wasim khan
|
|
|
|
|
No problem
Dave
|
|
|
|
|
Hi,
All of you must have herd of Best fit also, but i would give a brief , just in case.
Say i have slots of 50 KB, and there are some codes of different sizes say [10KB,11KB,23KB,34KB,2KB,28KB,31KB,9KB]
Now i have to fit all the elements in the different 50KB Slots such that i make the optimum use of the space. Like:
31+9+10 = 50KB --- 1st slot.
11+34 = 45KB --- 2nd slot...
I need an algo for the same in C#..
Thanks in advance...
|
|
|
|
|
First, you have to define "optimum use". Obviously it's the least number of slots, but what is the optimum distribution of the free space?
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
You don't define "best fit" based on your needs (i.e. largest first, most-used first, etc) but, based on your example, I'll assume you need a solution to what is called a "bin packing problem" (see google.com). A bin-packing problem solves the problem of fitting different-sized objects (data) into a number of specifically-sized containers without being able to split objects between containers.
The solution you choose will depend on your requirements. The optimum solution (the absolute best possible fit) is computationally complex with longer execution times. A "good enough" solution will be simpler and will likely run in the amount of time you need to complete the task.
Here are some of the simpler solutions:
1. First Fit Decreasing - Sort the items (largest first), then place each item in the first container it will fit in.
2. Best Fit Decreasing - Sort the items (largest first), then place each item in the container that leaves the least room left over (tightest fit).
With these two algorithms, you should need no more than ~120% + 1 more containers than the optimal solution. If you don't sort the items first, I think you need 170% + 1 (or 2?) more containers than the optimum solution.
Best solutions depend on how big the items are in relation to your container (lots of little items in large container or larger items in "close fit" containers) and how much the item sizes and container sizes vary. Then you have to worry about whether you will be adding and removing items on an on-going basis (fragmentation occurs) or if you can move data once it is placed in a container (optimization).
For a start, see if "Best Fit Decreasing" works in your case. It's pretty easy to implement, assuming I even have your problem defined correctly.
Robert C. Cartaino
|
|
|
|
|
Hi,
I'm trying to debug a deadlock problem, but I can't find anything that shows which thread owns a particular lock. Is there something that does this?
klk
madness ? this.isSparta = true : this.isSparta = false;
|
|
|
|
|
Hi
My C# windows based application is calling Perl Script by using Process.Start and it does pass couple of parameters.
I could able to see those parameters in Perl on one specific systems, rest of the PCs are receiving properlly. Even on the same PC if i use BAT file insted Perl it is working well. Is there any specific settings for Perl?
Thanks in Advance
|
|
|
|
|
satsumatable wrote: Is there any specific settings for Perl?
I don't think so. Show us the code?
|
|
|
|
|
I try starting the default browser using the Process Class as follows:
Process p = Process.Start(GetDefaultBrowser(), "http://www.google.com");
I get back a Process object in 'p' but the 'HasExited' flag is true and the MainWindow handle is IntPtr.Zero. However the default browser did open (in this case IE7) and displayed Google's home page. Checking the PID of the this browser in Task Manager and it has a different PID then the PID in the 'p' object I received in the call to Process.Start() above.
I tried the alternate method of starting a Process as follows:
Process p = new Process();<br />
p.StartInfo.FileName = GetDefaultBrowser();<br />
p.StartInfo.Arguments = u.AbsoluteUri;<br />
p.Start();
and get the same result.
I dug deeper and discovered that the process that launched the IE browser that is displayed on the desktop was a process called ieuser.exe. I would not mind so much but there is no way I can figure out what the new process is since the StartInfo of the new process is empty.
The same application does not have this problem on XP.
My first questions is what the heck is going on?
Secondly, does anyone know how to work around this either by ensuring the process I start is the one that runs or determining which Process is displaying the URL?
Regards
David
|
|
|
|
|
It seems that the process that you start calls another application and quits itself. Try running process like this:
Process p = Process.Start("http://www.google.com");
Giorgi Dalakishvili
#region signature
my articles
#endregion
|
|
|
|
|
Giorgi Dalakishvili wrote: It seems that the process that you start calls another application and quits itself. Try running process like this:
Process p = Process.Start("http://www.google.com");
Thank you for the reply, OK tried that and still get same result. I agree, when IE is launched it appears to be handing off to 'ieuser.exe' which creates a new process and the original is exiting. I base this on looking at the 'Created by Process' attribute of the process that is displaying the URL, it points to the PID of 'ieuser.exe' This appears to be some new thing on Vista.
The only work around I have been able to come up with and it is a real hack is to get a list of all processes for iexplorer.exe before calling Process.Start() and then do another after and compare the lists. The new process for iexplorer.exe is the one I want (I hope) and I am good to go. The weakness of this workaround is that it can take a second or two for the process to appear in the Process List and a user could open a browser at the same time and I would not be able to tell the difference.
David
|
|
|
|
|
|
Thank you for the link but when I click it I get a 404 resource not found. Has the page moved?
David
|
|
|
|
|
|
OK got a problem here with our firewall and proxy server. Once I connected to s different network I can get to the links. The WMI example is interesting, I 'll give it a try. I do like the idea of letting an event tell me what was created and deleted, should give me a better idea of what is going on. Thanks again for all you help.
David
|
|
|
|
|
Glad to help you
Giorgi Dalakishvili
#region signature
my articles
#endregion
|
|
|
|