Showing posts with label Windows tweaks. Show all posts
Showing posts with label Windows tweaks. Show all posts

Thursday, June 5, 2014

Computer on/off event viewer filter

Sometimes I want to track when I turned my computer on or off, including when it went to sleep or woke back up again.  To do that, I have created a custom view in Event Viewer on my Windows 8 system (should be the same for all systems from Vista and beyond, I assume). Go to Custom Views and click on "Filter current custom...". Switch to the XML tab and check the "Edit query manually" in the lower part. Now, paste the following in there:

<QueryList>
  <Query Id="0" Path="System">
    <Select Path="System">
    *[System
        [Provider
            [@Name='Microsoft-Windows-Kernel-Power'
            or @Name='Microsoft-Windows-Power-Troubleshooter'
            ]
            and TimeCreated    [timediff(@SystemTime) &lt;= 2592000000]
        ]
    ]
        or
    *[System
        [Provider
            [@Name='Microsoft-Windows-Kernel-General']
            and ( (EventID &gt;= 12 and EventID &lt;= 13) )
            and TimeCreated    [timediff(@SystemTime) &lt;= 2592000000]
        ]
    ]
   </Select>
  </Query>
</QueryList>

Basically, it is the equivalent of this, but only showing event 12 (switch off) and 13 (switch on) for the Kernel General source:




Please remember to "Save filter to custom view" if you want quick access to it later.

Monday, November 12, 2012

Failing Office automation when run from a service

Scenario: I needed to create a small script to automate the conversion of a Word document into PDF. There's plenty of help out there to script this by using the Microsoft.Office.Interop namespace, for example this simple one. I tried both writing a Powershell script and a compiled C# .exe with the same result: When running from the desktop, everything works fine, whileas running from a scheduled task or from CruiseControl running as a system service failed. If CruiseControl was running from its debug console window however, everything ran fine.

Problem: It seemed clear that the Office libraries required a logged on session to run in, as  also Microsoft confirms here in their Q257757 article.

Solution/workaround: I came across this hack - reposting it here for my own easy access to the knowledge:
  1. Browse to or create this folder: C:\Windows\SysWOW64\config\systemprofile\Desktop on 64 bits Win7/Win2008 - for 32-bits Windows, substitute SysWOW64 part of the path with System32. You might have to change some permissions to get there and you of course need to have administrative rights.
  2. Make sure the user credentials running the service or scheduled task you want to use has full control access permissions to the folder.
I have no idea how this trick can make it all work, but it does - at least in my case. Since Microsoft does not recommend or describe it however - use solely at your own risk. Not suitable for rocket launchers, weapon systems etc..

Sunday, March 4, 2012

SyncBack hang/freeze on Windows 7 - SMB version problem

Problem: SyncBack Free is a brilliant free tool for synchronizing two folders' contents fast and accurate. I had been using a Windows XP computer with two network cards standing as a bridge between two networks to sync folders between two computers residing on each side of the bridge. Old of age the XP computer were looking forward to its retirement as a young Win7 computer were set up to take over its place. The same SyncBack running the same SyncBack profile on the Win7 computer completely hung the SyncBack process within seconds after syncing was attempted. Only a reboot would kill the process - not even Task Manager managed to take it down.

Factors in the picture:
  • The two remote computers were running Win7  and Server 2008 R2.
  • Syncing between a local folder on the Win7 computer and one of the remote computers would work. Just not syncing between the two remote computers.
  • It made no difference whether Windows Shell (on the Copy/Delete tab) was used to sync or not.
  • Copying files between the remote computers from Windows explorer works just fine.
Problem reason: The reason proved to be SMB version. WinXP uses SMB 1.0, whileas Win7 uses SMB 2.0. For some reason, SyncBack does not manage to copy files between two remote computers as long as the computer is set up to use SMB 2.0.

Solution: Disable SMB v. 2.0, forcing the Win7 computer to revert to using SMB 1.0. This excellent article on Petri explains how - or here in short: From an administrative command line window run the following commands and then reboot to activate (Observe that "bowser" is actually correctly spelled - or rather, it is spelled the way that the computer understands):
sc config lanmanworkstation depend= bowser/mrxsmb10/nsi
sc config mrxsmb20 start= disabled
If you need to revert to SMB 2.0, use the following commands:
sc config lanmanworkstation depend= bowser/mrxsmb10/mrxsmb20/nsi
sc config mrxsmb20 start= auto 
I have not put any effort into researching whether security is an issue with these settings or whether other functionality is negatively affected, for me it gave me what I needed, so I am happy.

Tuesday, February 22, 2011

Win7: Restore .bat default behaviour

One of those small, very annying problems: I had managed to assign .bat files to open with my favourite cleartext editor (Notepad++ by the way), so that instead of running the bat file upon double-click, it opened in the editor. Now I wanted it reverted back to the original behavior.

I finally came up with a working solution: Just delete this registry key with all subkeys and life as you knew it before will be smiling to you again:

HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.bat

Friday, May 28, 2010

WPF program crashes when started from within a 16-bit DOS program

Scenario: I am programming a Windows application in VB.NET using Windows Presentation Foundation. My program is going to be started from within another old-style 16-bit program, hence this starter program runs in NTVDM (NT Virtual Dos Machine - the way Windows creates backwards compatibility with Windows 3.x/MS-DOS programs). Yes, they are actually still being used out there - the app I am programming is a helper app for the medical journal system WinMed.

Problem: Starting my app by double-clicking its EXE file is no problem, neither is starting it from a command prompt - from a cmd.exe command prompt, that is. But starting the program from within the 16-bit WinMed (it has a customizable menu for starting external programs) or from a command.com (=16-bit) command prompt, immediately results in a crash simply stating: "A problem caused the program to stop working correctly. Please close the program". Why it stopped working is kept a secret.

Cause: I had a strong hunch that NTVDM has something to do with it, since starting my app from both command.com and from within the WinMed program fails. Then I found this post: The environment variable WINDIR is missing from the NTVDM environment. This can be easily checked by running a command.com window and type the set command - all environment variables are then listed. I found that no WINDIR setting was present in this list of environment variables.

Solution: To run the program from the command.com command prompt, I had to first run the following command:
set windir=c:\windows
Now I was able to start the program from within command.com. To ensure that the environment variable was always set when running NTVDM programs, I edited the c:\windows\system32\autoexec.nt file by adding the above command to the end of it - making sure I had no spaces before or after the equal sign. Now my app starts even from within WinMed!


Friday, December 14, 2007

Things they stole back in Vista

(Originally posted Nov. 25, 2007 - the the list of complaints keeps on growing...)

If this continues, I will have torn all my hair off in pure frustration as to what Microsoft decided I do not need. It turns out that Vista (as in my Vista Business) has taken away several features that I had gotten used to in standard Windows XP. Aaaaargh - this just makes my point as to whether to choose a freely developed OS, with freely available features thrown in (Linux), or yet another time stay with so-called (un)supported licensed software. Enough said, here's my frustration list:

  • Backup is gone! That is, they did add some substitute only good for backing up your whole disk to an external source. What I used to do in XP was backing up a subset of files (my data) to a local file destination, and then took that file and burnt it to a CD for offsite storage. Forget it - the old NTBackup software is gone. I found a good substitute in the free Simply Safe Backup software, but that's beside the point.
  • Telnet is gone! Not too much of an alarm though, I found it under Control Panel-Programs and features-Turn Windows features on or off.
  • Windows Explorer no longer lets you completely turn off the "Remember each folder's view settings" (although the choice is there under Tools-Advanced). When I browse the folder hierarchy, I normally choose to see file details. If Explorer decides to however, it just jumps to thumbnail view, I guess when you enter a folder where graphics files are present. You'll also notice that they took away the "up" button to go one level up the directory tree. You can always go "back" to the previous folder you visited, but that's not always the parent folder. And of course, there's no way to customize the toolbar to bring that button back...
  • The defragmenter has lost the little that was left of its visual interface (it had already suffered the transition from 9x to XP badly). Luckily, there are good third-party tools out there, like the free Defraggler, that shows you where each file is located on the disk and even gives you the option to only defrag the files you need quick access to. With the new "improved" Windows, this is a necessary addon.
Apart from that, I found a couple of tricks to be most necessary to get around:
  • Run as administrator seems to be the general medicine if a program fails to do what you expect it to. Especially programs that access any part of the computer other than your screen/desktop (like registry, folders for programs, network ports etc.). I guess this is part of the new security model requiring you to say that you are sure a dozen times before actually doing what you are sure you want to do.
    • Ethereal Wireshark network packet tracer needs to be run with this option - otherwise you will not find any network adapters to inspect.
    • DevPHP had to be run as administrator to avoid loosing all settings upon exit. Assumingly this has to do with the new way Microsoft has invented to handle writing to the HkeyLocalMachine hive of the registry - where you THINK you write to that key, whileas actually writing to your HkeyCurrentUser hive. This is not comfirmed though.
  • Check out this brilliant website for clues: Vista Rewired -It made it right into my group of favourite bookmarks!
If Microsoft could just do a little bit more than pleasing newbies to Windows (do they?) and let us nerdies also have a few goodies, they might actually have some of us recommend their stuff. As for now, I sincerely hate Windows Vista and recommend everyone (including my customers) who buys a new computer to stick with XP. Vista is just a really bad idea.

View Source with something else than Notepad in Internet Explorer

I'm doing some web development at the time, and since Internet Explorer is the customer's and their customers' preferred web browser, it is a good idea to check how the pages look even in IE (of course, Mozilla Firefox is my own open source preference).

If you want to check the source the browser is actually reading, the IE7's Page-View Source menu item will take you to a Notepad window with the source. I want to look at it in my favorite plain text editor, Notepad++ though, where I can view the code color highlighted. I might even want to clean up what I see so that the source is indented in a readable format, using the TextFX with HTML Tidy option.

So - to my business: How do I change the View Source option to run the text editor I want? Simply by a small registry hack:

------------8<----------------8<------------------
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\View Source Editor\Editor Name]
@="\"C:\\Program Files\\Notepad++\\notepad++.exe\""

------------8<----------------8<------------------

Cut and paste this into a .reg file and import to registry (if you are uncertain of how to do that, don't even try - messing with the registry is not for you). Of course, if you want to use another text editor, just change the file path accordingly. If you need to undo this hack, just delete the "View Source Editor" registry key with its full contents.

This is actually just a copy of another blog I found googling for a solution: The Thea Burger's Blog and Will's blog - Thanks for helping me out!

Thursday, October 11, 2007

Slow Windows login (Gone in 60 seconds)

I decided that today was going to be the day I solved why my Windows XP always takes excactly 1 minute to "think" after clicking the login button and until it shows my Windows desktop and starts to load traybar applications etc..

First try was to minimize the profile size. If I were using a roaming profile this would certainly have helped, because the size of my profile folders were around 800 megs. I moved out the Thunderbird mail profile and sqeezed some more unnecessary bits out of it and came down to around 150 megs. Still a bit much, but the change in login speed should be noticeable. Result: Nada. Still took a minute to think it all over before letting me in.

The solution was right under my nose the whole time - actually letting me know upon each login that "some network drives could not reconnect". Of course not - I use my laptop on different places and I am not always connected to those network drives. I just find it convenient to have them all ready for use in explorer. No longer. I disconnected them and did a login, and the whole minute's wait was gone.

The login was no longer "Gone in 60 seconds" - the 60 seconds were gone. :)

I just wonder where I can find the time to fetch my coffee now...