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

2014-02-05

List users in a Windows local group

Note to myself: use net localgroup [groupname] to get a list of users in a Windows server's local group (e.g. Remote Desktop Users). Refer: Net localgroup.

2013-11-14

Adding portable programs to Windows 7 Start menu

A tiny addenda to Raymond Chen's series of posts about how programs appear in the Windows Start menu. According to Raymond's posts, Explorer counts the number of times the program is launched to place it in the Start menu. However, Explorer doesn't add the program's icon in the Start menu if you just start an executable (e.g. a PortableApp or a not-installed program) by entering its path in the "Search programs and files" field; a workaround is to add a shortcut to the program in the desktop.

2013-11-12

Showing last modified time with seconds in Windows 7 Explorer

Windows 7 Explorer only shows the last modified time of files and folders in hours and minutes, not seconds, i.e. hh:mm instead of hh:mm:ss. If you use the Properties dialog, you can briefly see the last modified time in hh:mm:ss but if you wait longer, the text in the dialog changes to the pretty useless "n minutes ago" and then a more useless "m hours ago". If you check the file or folder properties the next day, you can see the last modified time in hh:mm:ss again! This misfeature became a problem when I wanted to check the modified time of files created seconds within each other.

The workaround is to change the Long date format in your Region and Language from dddd, d MMMM yyyy to ddd, d MMMM yyyy, which stops last modified date format from changing in the Properties dialog. Note that Windows 7 Explorer's Date Modified column never shows seconds.

Reference to self: use "HH:mm:ss" for 24-hour time format and "dd/MM/yyyy" to ensure that day of month always has two digits.

2013-09-19

Cannot read CHM file in Windows 7

If you can't read pages in a CHM (Compiled HTML) file on a Windows 7 computer, you might have to "unblock" the file. Seems to be a security feature to prevent scripts running.

  1. Show the CHM file properties.
  2. In the General tab, press the Unblock button. Note: After you do this, the button no longer appears for this file.

Thankfully, you only need to do this one time for the CHM file.

See longer write-up in StackOverflow.

2012-11-03

Giving Up On Windows 7 Explorer

Giving up on Windows 7 Explorer because file management is harder than WinXP Explorer since it's not possible to disable "auto row highlight" and "select full row".
Feature #1 is confusing because two items can be highlighted in a directory list when you navigate using the mouse and cursor keys: the item under the pointer gets highlighted automatically without having to activate the window but the previously selected item remains highlighted (see the two highlighted folders in the image below). It's too easy to accidentally copy or move the wrong object using keyboard shortcuts because I couldn't tell which object was the active one. In WinXP, you have to click in the window before the selection is changed and only one item is highlighted. Feature #2 means you have to find a blank space (usually the small gap between the item and the edge of the window) with the pointer to show the folder's context menu otherwise you see the highlighted item's context menu.
Playing with an alternative file manager called FreeCommander now. Out of the box, it highlights the entire row but you can disable that feature in Settings, View, File/Folder List, Full row select.

2011-05-29

Avoid multiple instances of a task in Windows Task Scheduler

Using Task Scheduler, one way to run a task more often than once a day was to repeat the task within the day. For instance, if you wanted to run a task every hour, you would repeat the task once an hour for that day. Now, if the task's running time is longer (e.g. the task is delayed by a slow network connection) than the repeat interval then another instance would be started even if you specify Do not start a new instance!

For a backup task, my workaround is to specify an hourly repeat interval and call a wrapper (e.g. a CMD or VBS script) to test for a lock file before executing the main program. In the wrapper, if the lock file exists then the wrapper aborts else it creates a lock file, runs the main program then deletes the lock file.

It looks like a task's Do not start a new instance parameter only applies to triggers. With Task Scheduler 2.0 (Vista onwards), you can create triggers for specific times of the day (say 01:00, 02:00, etc. for hourly triggers) and only one instance of a task is started. It's a pity there aren't shorter trigger intervals because to schedule a task every hour of the day, you have to create 24 triggers.

2011-01-01

NTFS Compression versus Compressed (zipped) Folders

A New Year posting!

While playing with WMI to compress folders, I realised that NTFS compression is different from ZIP files. At the start, I wondered why my script didn't seem to create any ZIP files even though the call to SWbemObjectEx.Compress procedure was successful. Turns out that my test folder was being compressed in NTFS but I wasn't looking for it correctly; in Explorer, the folder's name is displayed in a blue colour and its Size on disk is smaller than its Size but its icon and type is the same as a regular folder. On the other hand, Compressed (zipped) folders which are just files that have been compressed, have a zipper and padlock icon. A great way to publicise a fundamental file system feature, eh?

References

2010-07-25

Invisible USB Drive

If you plug in a USB drive and Windows doesn't assign a letter to it, you can assign a letter yourself using the Disk Management console:

  1. Run diskmgmt.msc
  2. In Disk Management window, locate the box corresponding to your USB drive.
  3. Select context menu item Change Drive Letter and Paths....
  4. Assign a letter to your drive.

This problem happened after I had mapped a remote drive to Z: then plugged in a USB key. I could see the USB key and eject it in the Windows Start Bar but no letter was assigned to it.

See Also

2010-02-23

Vista Ctrl+Space IME Toggle Workaround

If you start using Windows Vista Input Method Editor (IME) for Chinese, you may find that you can no longer use Ctrl+Space in some applications (e.g. to select a column in Excel, to activate autocomplete in IDEs such as VBA, Netbeans or Visual Studio, or to activate Firefox Ubiquity). One workaround is to define a different hotkey, such as Ctrl+Shift+F12, to toggle the IME.

If you have only one keyboard service and find that Ctrl+Space mysteriously starts to act as a toggle for an unselected IME (in my case, Chinese (Traditional, Taiwan)), the workaround is to add a keyboard service and define a different IME hotkey. You must define a hotkey for toggling the IME, otherwise the IME is activated using the default Ctrl+Space.

Reference

2009-09-24

Auto-arranging multiple application windows in Vista

If you're taking notes or eyeballing a couple of documents at once on screen, you might tile your application windows so that they are arranged side by side and fill up the screen. In Working with windows, Arranging windows automatically, the Vista desktop provides two commands for tiling your windows: Show Windows Stacked and Show Windows Side by Side. (If you Cascade Windows, your windows are stacked one on top of another and you can only see the contents of the top one.) This posting digs a little deeper into how this feature works and explains its limitations.

To use these commands, press the right-mouse-button (RMB) over the task bar and select the appropriate item from the context menu. The Windows desktop should automatically tile all application windows. If you want to restrict automatic tiling to specific windows, hold down the CTRL key and select the window icons in the task bar first, then press RMB and select the required menu item. A gotcha I noticed is that you can undo automatic tiling if you tiled all the windows at once, but you can't undo the last command if you tiled specific windows.

When you have selected only two or three windows, Show Windows Stacked tiles your windows one over the other vertically, like this:

+--------+
|        |
+--------+
+--------+
|        |
+--------+
+--------+
|        |
+--------+

As you would expect, Show Windows Side by Side tiles your windows horizontally:

+---++---++---+
|   ||   ||   |
|   ||   ||   |
|   ||   ||   |
|   ||   ||   |
+---++---++---+

If you select four or more windows, then it doesn't matter which of the two auto-tiling commands you choose because the windows are tiled in the same manner:

+---++---+
|   ||   |
+---++---+
+---++---+
|   ||   |
+---++---+
+---++---+
|   ||   |
|   |+---+
+---+|   |
|   |+---+
|   ||   |
+---++---+

The commands tile the selected windows based on the windows' titles, in reverse alphabetical order, as below. You can't make windows appear in a particular order by changing the windows' initial positions in the desktop or picking window icons in a particular sequence.

+---++---+
| E || C |
|   |+---+
+---+| B |
| D |+---+
|   || A |
+---++---+

2009-06-17

Escaping special characters in Windows International Keyboard

The Windows International Keyboard allows you to enter letters with accent marks. For example, to type é, just type Apostrophe e. But what if you just want to enter (or escape) an apostrophe (for example, when entering a string literal while programming)? The trick is to type a space after the apostrophe, as per this bullet point in the support page: If you press the space bar, the symbol (apostrophe, quotation mark, accent grave, tilde, accent circumflex or caret) is displayed by itself.

2008-06-25

Event 7000, DS1410D service failed to start

Windows Event Viewer kept reporting error event 7000 each time I restarted my computer:

The DS1410D service failed to start due to the following error: 
The system cannot find the file specified.

The error is caused by Windows trying to load a file called DS1410D.SYS. This file is part of an application called FlexLM but since I've uninstalled FlexLM, the file has also been deleted.

The fix is find all instances of .../services/DS1410D/Start in registry and set it from 2 (Auto load) to 4 (disabled). See Microsoft KB 103000 article for more information.

2008-05-25

Disable Vista Memory Diagnostic Tool

Vista has a Memory Diagnostic Tool which you can turn on to test your computer's memory when you restart it. Once it is enabled, this tool starts every time you restart your computer. Be warned: the Vista help system doesn't explain how to disable it!

After some Web searching, I found this tip:

- Open command prompt as Admistrator: by typing in start ''cmd'' right click the .exe file and then clicking on adminstrator. - Then typing in the console: ''bcdedit /bootsequence {memdiag} /remove'' press enter, after that you can restart your com. and it wont start

2008-05-24

Fix Incorrectly Encoded Unicode Files with Python

The Problem

We had a lot of text files committed into our CVS repository as Unicode format. When these files were checked out later, we found that they weren't really text files nor Unicode files because CVS had only prepended two bytes to the start of these files, FF FE, but left only one byte for encoding each character. Some text editors such as Vim could open these files but other applications such as Notepad and Excel showed only gibberish.

Unicode Encoded Text in Files

Unicode is an encoding standard … for processing, storage and interchange of text data in any language. For the purpose of fixing this problem, we just have to know how to identify and write valid Unicode files.

We use two tools to experiment and visualize the effect of different encoding methods:

  1. Microsoft Notepad editor, because it can save text files using different encoding methods.
  2. GnuWin32 od utility to output the data in a file as byte values.

Open Notepad and enter this text: Hello World. Select the File / Save As menu item. In the Save As dialog, there are four encoding methods in the Encoding drop down list: ANSI, Unicode, Unicode big endian and UTF-8. Save the same text using each of the encoding methods into four files, say TestANSI.txt, TestUnicode.txt, TestUnicodeBigEndian.txt and TestUTF8.txt, respectively.

Examine the contents of each file using od:

>od -A x -t x1 HelloANSI.txt
000000 48 65 6c 6c 6f 20 57 6f 72 6c 64
00000b

>od -A x -t x1 HelloUnicode.txt
000000 ff fe 48 00 65 00 6c 00 6c 00 6f 00 20 00 57 00
000010 6f 00 72 00 6c 00 64 00
000018

>od -A x -t x1 HelloUnicodeBigEndian.txt
000000 fe ff 00 48 00 65 00 6c 00 6c 00 6f 00 20 00 57
000010 00 6f 00 72 00 6c 00 64
000018

>od -A x -t x1 HelloUTF8.txt
000000 ef bb bf 48 65 6c 6c 6f 20 57 6f 72 6c 64
00000e

The ANSI encoded file contains 11 bytes representing the characters you typed. The Unicode encoded files contain 24 bytes, starting with a two-byte BOM and using two bytes to represent each character. If the first two bytes are FF FE, then the two bytes are stored in low-byte, high-byte order. Conversely, if the first two bytes are FE FF, then the two bytes are stored in high-byte, low-byte order. Finally, when a file starts with byte EF BB BF, only one byte is used to encode each ANSI character and two or more bytes are used to encode non-ANSI characters (not demonstrated).

Fixing Incorrectly Encoded Files in Python

Now we know the format of a Unicode encoded file: it starts with FF FE and stores each character in low-byte, high-byte order. Our text files in CVS just have ANSI characters, so we just have to insert a 0 byte between each character, starting from the third byte. Julian W. wrote a short Python script that to do this. I don't have his code right now, so here's my version for correcting the Unicode encoding for a file:

import codecs
raw = map(ord, file(r'HelloBadUnicode.txt').read())
if raw[0] == 255 and raw[1] == 254 and raw[3] != 0:
  output = codecs.open(r'HelloFixedUnicode.txt', 'w', 'UTF-16')
  for i in raw[2:]:
    output.write(chr(i))
  output.close()

References

Postscript

I started with a more complicated piece of Python code using lists and generators:

from itertools import repeat
from operator import concat

raw = map(ord, file(r'HelloBadUnicode.txt').read())
if raw[0] == 255 and raw[1] == 254 and raw[3] != 0:
  output = file(r'HelloFixedUnicode.txt','w')
  output.write(chr(255))
  output.write(chr(254))
  for i in reduce(concat, zip(raw[2:], repeat(0, len(raw)-2))):
    output.write(chr(i))
  output.close()

But then I realised I just had to write a 0 byte after each ANSI character, so here's a simpler version:

raw = map(ord, file(r'HelloBadUnicode.txt').read())
if raw[0] == 255 and raw[1] == 254 and raw[3] != 0:
  output = file(r'HelloFixedUnicode.txt','w')
  output.write(chr(255))
  output.write(chr(254))
  for i in raw[2:]:
    output.write(chr(i))
    output.write(chr(0))
  output.close()

2008-05-25. I remembered that Python had no problems with writing Unicode files, resulting in the even simpler code in the body of this article.

2008-05-23

MDI Child Window Menu Shortcuts

I accidently moved PythonWin's Interactive window out of sight when I grabbed and dropped it with my mouse pointer. Restarting PythonWin didn't help because the position of the child window was stored in Windows Registry, so it remained hidden even after restarting PythonWin. I considered hacking Windows Registry to reset the child window's position, until I found the keyboard shortcuts to move the keyboard focus to a child window, show the System Menu and select the Move menu item.

Background: A child window is a window in a MDI application.

The keyboard shortcuts required to bring the child window back into view were:

  1. Move focus through child windows: Control+F6.
  2. Show a child window's System Menu: Alt+- (Alt Minus).
  3. Move child window: m, then press the cursor keys.

Keyboard shortcuts for Microsoft Windows applications: KB 126449.

2008-05-11

Assign USB Drives to Folder

Each time you plug in a USB device to your Windows computer, Windows can assign a different drive letter to your device. If you have programs that rely on a fixed drive letter (e.g. portable applications on a USB drive or backups) or if you use more than one computer regularly, then it gets annoying to reset the programs' configuration after plugging in your drive or remember to plug in devices in a particular sequence. Assign USB Drives to Folder describes how to use Window's Disk Management to assign a fixed path to each device.

I wonder if it's possible to refer to a device using its volume name, which would make this method redundant?

2008-05-01

More Uses of Getclip-Putclip

More uses of GnuWin32 / Cygutils tools getclip and putclip using this recipe: getclip | <command chain> | putclip.

  • Copy m'th and n'th column of a table from a browser: cut -fm,n.
  • Copy columns from Excel and replace tab character with space: tr \t " ".
  • Capitalize letters: tr [:lower:] [:upper:]. (Duh! Enter Shift-F3 in Microsoft Word, thanks to Maria H.).
  • Remove indentation from e-mail messages: sed "s/> //".
  • Remove indentation from source code in Word document: sed -e "s/^ //" (5-May-2008).
  • Join lines broken into multiple lines by e-mail clients: dos2unix | tr -d \n. On a Windows system, tr doesn't recognise CR-LF pairs for terminating a line, so you have to convert them to a Unix-style LF using dos2unix first (6-May-2008).
  • Another way to join broken lines: tr -d \r\n using escape codes for carriage return and line feed, respectively (11-May-2008).
  • Remove formatting from string: getclip | putclip. This is equivalent to Microsoft Word's Paste Special / Unformatted Text. Also to work-around an annoyance in Outlook 2003, were the Edit / Paste Special is disabled when you are responding to an HTML-formatted document (7-May-2008).
  • Remove HTML / XML formatting from input: sed -e "s/<[^>]*>//g" (12-Jun-2008).

A second recipe is (for /f %i in ('getclip') do @command %i) | putclip if command cannot be used in a pipeline. Two examples are basename (return name of file in a path string) and dirname (return path string without file name).

2008-05-01: Don't simply list transformations and filters that can be done with GnuWin32 tools, but ones where existing applications (e.g. Excel, Firefox, Outlook or Word) don't have an easy way to achieve a particular action.

2012-06-25: Flatten or collapse Excel multi-column data.

2008-04-30

Using Clipboard in the Command Line

GnuWin32 / Cygutils package has two tools for interacting with the Windows clipboard: getclip and putclip. The first copies text from the clipboard to standard output and the second copies text from standard input to the clipboard. These tools are useful when you want to process text from one Windows application before pasting the text into another application, in the following recipe: getclip | <filters> | putclip.

For example, I want to paste all DLL file names in a folder into a document:

  1. Navigate to the required folder using 2xExplorer browser.
  2. Type Alt+a to select all files.
  3. Type Alt+c to copy all file names. 2xExplorer copies the absolute path for each file.
  4. Start cmd.exe console.
  5. In cmd.exe console, enter: getclip | cut -d\ -fn | grep dll$ | putclip. cut is GnuWin32 tool which selects a column of data given a column delimiter (-d\ defines backslash) and field number (-fn defines column n). grep filters the output to only list files with "dll" in their name.
  6. Start editor.
  7. Paste the text in the clipboard in destination document.

Of course, you can do the same using Excel:

  1. Navigate to the required folder using 2xExplorer browser.
  2. Type Alt+a to select all files.
  3. Type Alt+c to copy all file names. 2xExplorer copies the absolute path for each file.
  4. Start Excel.
  5. Paste data in a worksheet column.
  6. Select all cells by typing Shift+Space.
  7. Open Convert Text to Columns Wizard by typing Alt+d+e.
  8. Select Delimited data type by typing Alt+d.
  9. Type Alt+n to go to page 2.
  10. Select Other delimiter by typing Alt+o, then enter "\" for paths.
  11. Type Alt+f run the wizard.
  12. Start Auto Filter by typing Alt+d+f+f.
  13. Move to filter column using the mouse (no keyboard shortcuts?) then select from the drop down list (Custom …).
  14. Select ends width criteria, enter .dll, then press Enter.
  15. Move cursor to required column and select it using Control+Space.
  16. Copy column by typing Control+C.
  17. Start editor.
  18. Paste the text in the clipboard in destination document.

The Excel solution has many more steps than the getclip-putclip solution but Excel leads you through to a solution step-by-step. If you're familiar with GNU tools, then getclip-putclip recipe is faster to use and much more extensible.

2008-05-07. I should have remembered that the basename command would output the name of the file without the leading path string. See later article More Uses of Getclip-PutClip about how to use basename in a pipeline.

2008-02-19

Hide Recycle Bin in Windows Desktop

While noodling around Windows' Group Policy Editor, I noticed that you can hide the Recycle Bin in the desktop:

  1. Start Group Policy Editor using gpedit.msc.
  2. Select User Configuration / Administrative Templates / Desktop.
  3. Select Remove Recycle Bin icon from desktop.
  4. Select Enabled radio button.

Note that Windows' Group Policy Editor is generally used to turn off features, so enabling a setting generally means to disable a function.

2008-02-16

OpenGL for ATI Mobility Radeon in Vista

This is way annoying. I installed an OpenGL game on my Asus notebook and it ran abysmally. When I tried to test the OpenGL interface with glview, that program crashed. The ATI's Catalyst Control Center (CCC) reported that OpenGL Version was Not available.

It turns out that I have to update the driver for my notebook's ATI Mobility Radeon X1700 card and enable OpenGL support. ATI does not support any Mobility Radeon cards but I found an updated driver on the Asus site. Then I used Mobility Modder tool and it enabled OpenGL. Now my system has OpenGL version 6.14.10.7275 and glview runs to completion.

Whew! Thank goodness Mobility Modder worked since I wasn't looking forward to hacking .INF files without knowing anything about configuring video adapters.