Friday, April 15, 2011

Simple way to backup event log on Windows Server

Is it possibile to create a simple way to backup the event log, with such as a batch file or a simple app ? I need to make it working on a customer's site, where the reference is an non-expert user. Thanks

From stackoverflow
  • If you're using Windows 2008, use the built-in wevtutil command. Example:

    wevtutil epl Application c:\temp\foo.evtx

    Otherwise, get dumpel.exe from the resource kit, or psloglist from http://technet.microsoft.com/en-us/sysinternals/bb897544.aspx

  • The Microsoft Script Center has some sample code for Backing Up and Clearing Event Logs using VBScript and WMI.

    Frank-Peter Schultze's Scripting Site has some code to clear an event log ( http://www.fpschultze.de/uploads/clrevt.vbs.txt) that you can modify to backup or backup then clear.

    If you have access to the server you can backup from the Event Viewer by right-clicking on a log and using the "Save Log File As..." command. You can save to a binary, tab delimited or comma delimited file.

  • Finally I made a little winapp using this method found on the internet:

    public void DoBackup(string sLogName)
    {
        string sBackup = sLogName;  // could be for example "Application"
        EventLog log = new EventLog();
        log.Source = sBackup;
    
        var query = from EventLogEntry entry in log.Entries
                    orderby entry.TimeGenerated descending
                    select entry;
    
        string sBackupName = sBackup+"Log";
        var xml = new XDocument(
            new XElement(sBackupName,
                from EventLogEntry entry in log.Entries
                orderby entry.TimeGenerated descending
                select new XElement("Log",
                  new XElement("Message", entry.Message),
                  new XElement("TimeGenerated", entry.TimeGenerated),
                  new XElement("Source", entry.Source),
                  new XElement("EntryType", entry.EntryType.ToString())
                )
              )
            );
    
        DateTime oggi = DateTime.Now;
        string sToday = DateTime.Now.ToString("yyyyMMdd_hhmmss");
        string path = String.Format("{0}_{1}.xml", sBackupName, sToday);
        xml.Save(Path.Combine(Environment.CurrentDirectory, path));
    }
    

    this is the source link:

    It simply works great!

  • With powershell and export-clixml its oneliner.

      get-eventlog -list | %{ get-eventlog $_.Log | export-clixml -path ($_.Log + ".xml") }
    

How can I disable "demand paging" for one of my userspace programs ?

For an dedicated test I have to disable "demand paging" for exactly one of my userspace programs

http://en.wikipedia.org/wiki/Demand_paging

Any idea how I could do this ? (embedded linux appliance; 2.6 kernel)

From stackoverflow
  • If you have the ability to modify the application, you could use the mlock() / mlockall() system calls to ensure that your memory doesn't get paged out:

    #include <sys/mman.h>
    
    mlockall(MCL_FUTURE);
    

    This will prevent all memory currently allocated, and any future memory that is allocated to this process from being swapped out. You can use the mlock() system call to get finer control over which parts of memory are locked.

    Chris AtLee : In that case, you can disable your swap device altogether :) I'm not aware of a way to do the equivalent of mlockall to another process. You could try and hack the executable to insert a call to mlockall as the very first thing to do when the application starts.

Geolocation based, wireless mesh routing alogorithm: useful?

I'm in a team and we are supposed to be setting up a 'geolocation based', ipv6, wifi mesh network to run on google android.

The idea is to use the geolocation (latitude, longitude, altitude) of each node to generate the IPv6 address, then use that to choose the closest node as the preferred node for routing through. Some optimisation is made through periodic 'routing load' messages.

http://www.v6pc.jp/apc/en/data/addressing.pdf

My understanding is: The main 'benefit' of doing a geolocation based algorithm is that each network hop will step physically closer to the destination... and we assume that travelling in the most direct path to the destination, is going to give us the most optimal routing path.

BUT, my problem with this approach is that physical proximity + load does not necessarily imply good connection strength or fast routing. What if there's a thick lead wall(?) or lots of interference?

Surely proximity is a fairly useless metric for determining routes?

The primary metrics should be primarily based on performance/load shouldn't they? Something like, signal strength, demonstrated throughput, cpu usage, time connected to network, etc. At least that was my understanding of how routing paths should be chosen.

Why is this a good idea? Is there something I'm missing?

I haven't spent a lot of time working with networks, so please put in noobmans terms.

From stackoverflow
  • The three main paramaters for any connection are bandwidth, latency and capacity. Bandwidth would be measured in bytes per second, latency in milliseconds, and capacity in % of bandwidth used. Those are all parameters you can determine for connections to neighboring nodes (Before you join the mesh, capacity used will likely be 0%)

    You need capacity because you want to avoid congested nodes even if they would have good bandwidth and latency.

    secoif : Can you see -any- benefit in a proximity based algorithm?
    Michael Todd : @secoif: Like you said, close proximity does not indicate best performance. I would use it as a first-stage filter but then use the bandwidth, etc., as MSalters mentioned to zero in on the correct path.
  • Is there something I'm missing?

    Yes, so far as I can tell there's no IPv6 support in Android yet...

How do I secure my Amazon S3 photos but still make them available via URLs?

I'm planning on making my (family) photo collection available online. I want to use S3 and build an ASP.NET site that will display the photos. I don't want the website to pull down the S3 content and return it to the browser. I want browsers to be able to go directly to S3 without affecting my ASP.NET bandwidth.

It is possible to build URLs for each photo if I set the S3 permission to public, but I only want the photos to be accessible by visitors to my website, not anyone who has the URL.

Any ideas greatly appreciated!

From stackoverflow

TFS Branch/Merge meets History View

We have a setup with a development "trunk" in our recently-migrated-to-from-VSS TFS system and developers have been doing work in branches off the trunk, which are merged back in.

We've been diligently commenting our changesets at check in time, something we never did in the VSS days. However when I right-click on a trunk file in the Source Control Explorer and choose History, I only see monolithic changesets labeled "merge from dev branch" (or whatever the developer scribbled in there when they merged.) A history entry doesn't even seem to contain info on which branch was merged in at that time, let alone any info about the changesets that make it up, or the comments that go with them.

How have other TFS users dealt with this issue? Is there another way to view the history that I'm missing here? Thanks for your help.

From stackoverflow
  • This might be what you are looking for: http://www.codeplex.com/TFSBranchHistory

    Haven't used it personally, so I can't vouch for it.

    Barry Fandango : that seems to be the closest thing i can get, i installed it and it works pretty well! thanks for the link.
  • Looking at the history of a change prior to the merge has been a bit of a pain point with TFS. So much so that Microsoft have done a lot of work to address this in the next version of TFS (TFS 2010). In TFS 2010 (when it comes out), when you get to a merge in the history view it is actually a little twistie that you can expand and go see the history for the thing that was merged which is much nicer.

    In the meantime, when I see I big monolithic merge (or branch) comment I tend to let out a audible sigh and then go find the file in the branch it was merged from in Source Control Explorer and do a view history there.

    Barry Fandango : Wish I could accept two answers but Ryan was closer. Thanks for the information, very useful.

Custom icon per file instance

Some Windows programs can use different icons for different files with the same extension.

Example

  • .sln can show a different icon depending on what version of Visual Studio the solution was made in (actually, determined by the version number in the top line in the .sln)
  • Photoshop .psd files have icons with a thumbnail of the image
  • A .url shortcut file has the page's favicon if opened in, or saved from, Internet Explorer

I'm guessing it must be custom to that computer only. On a box without Visual Studio installed, .sln files just have the default 'I don't know this program' icon. Is there something that needs to be changed in the registry?

How can I do this? I'd like to have the option of associating custom icons with files to my own programs.

[Edit] I really with I could do this in managed code. It's possible (<SDK v1.1>\Samples\Technologies\Interop\Applications\ShellCmd) but it also appears to be potentially dangerous and the wrong tool for the job in practice: http://social.msdn.microsoft.com/forums/en-US/netfxbcl/thread/1428326d-7950-42b4-ad94-8e962124043e/. I really hoped MS would have a good managed API for this kind of stuff by now.

From stackoverflow
  • Check out this C++ code on CodeProject: essentially, you write a COM handler and register it for your extension. Be aware that you can mess up the Explorer process pretty badly if you leak resources in icon handlers or shell extensions... C++ may be a challenge, but I wouldn't recommend doing this in C# or Java for reasons of memory consumption (a separate copy of the framework code for each extension/handler!).

    Dinah : Great link and good warning about .NET/Java. I've never coded in C++ before. Is this beyond my skill level unless I learn C++?
    Pontus Gagge : You can implement COM interfaces in .NET pretty easily, but the Explorer process will get bloated. It depends on what you want to achieve... but a small memory footprint is a definite plus for plugins!
    Pontus Gagge : Both C++ and COM at one go is pretty heavy duty programming: not impossible by any means, but plenty of things can trip you up, not least leakages.
    Pontus Gagge : But if you're doing it for fun, by all means try a .NET solution. I'd give some thought to testing it out on a virtual machine first, though!

Binding DropDownList to an Enumeration

How do i bind a regular asp.net dropdownlist to an enum?

From stackoverflow