Atomic I/O letters column #155

Originally published 2014, in PC & Tech Authority
(in which Atomic magazine is now a section)
Reprinted here December 14, 2014
Last modified 09-Jan-2016.
 

Targeted killing

At my work we've got some custom software that I won't identify because of possible trade-secret stuff, but let's call it BlargForce.

BlargForce is not good software, and hangs several times a day, usually doing something weird to a database connection that makes everybody else's BlargForce freeze, but not actually crash, until the hanged copy is killed in Task Manager.

This is tolerable (which is good because the people who made BlargForce do not appear to speak any human language), but it's occurred to me that it'd be nice if you didn't have to go Task Manager, Processes, sort by name, find blargforce.exe, End Process, confirm, every time, which everybody in this office can now do by feel in their sleep. Windows has a command-line process killer, right? Could you make a one-line batch file that kills the BlargForce process number in one step? How do you find the right process number? Does it change whenever you run a new BlargForce, or is it fixed for each program?

Henry

Answer:
The standard command-line utilities you're looking for are "tskill" and "taskkill". Tskill is the basic version that comes (I think) with every flavour of Windows; taskkill is the more powerful one that doesn't come with "Home" editions. Both can do what you want.

Tskill and taskkill can indeed kill tasks by process ID (PID). You can display PIDs in Task Manager via View -> Select Columns. But that's the wrong way to go about it, because PIDs do indeed change when you run the same program again. If BlargForce is PID 10208 now and you make a batch file that kills that task, it could be PID 12260 next time and your batch file won't hit it - but whenever PID 10208 is given to a completely different program's task, your batch file will murder that random other program just fine.

Fortunately, both killer-commands can also kill tasks by name, and the task name will always be the same for a given executable. So in your case you just need a text file called killzombie.bat (or whatever, all it needs is the .bat suffix to make it run as a batch file), that says

taskkill /IM blargforce.exe

or

tskill blargforce

The simpler tskill needs no command switches or suffix on the process name. If there are spaces in the task name, the name has to be enclosed in quotes.

 

Open-registry surgery

I upgraded my computer recently after the CPU on my old one carked it, and I've plugged the C drive from the old computer in as the X drive of the new one, which has made it pretty easy to transfer settings from old programs and such.

I'm at a loss for my video playing software, though, Media Player Classic Home Cinema. The only setting I care about for that is the huge list of bookmarked unfinished video files I had, but there doesn't seem to be a config file anywhere that I can copy to the new computer's MPC-HC folder (or another folder in C:\Users or whatever) to get the bookmarks back.

Everything's on the same drive letters it was before, so a bookmark to "e:\somemovie.mkv, 76 minutes 8 seconds" would still work, but I don't know where MPC-HC KEEPS all of those bookmarks.

Do you? How can you copy them over?

Chelsea

Answer:
By default, MPC keeps its favourites settings in the registry. So to move them to the new computer, you have to extract them from the old computer's registry and insert them into the new. This is a mildly terrifying process - screw up your registry and you screw up your computer, though modern Windows versions should be able to roll back to a last-known-good state.

(Media Player Classic has an option, turned off by default, to store that stuff in a simple .ini file instead. Sometimes that option even works!)

Registry editing is well within the capabilities of a careful home user, though, and it can be a lifesaver if something really important is lurking in the registry on the still-working hard drive of a deceased computer. This can actually be the case depressingly frequently, since a lot of dodgy software stores all sorts of important data in the registry, and many people (see above) have to use dodgy software to do their job.

In a situation like that you may think you've got everything backed up properly, but if the registry's huge encoded Windows mystery files aren't backed up, then you actually don't. And even if the registry is backed up, you may have to do stuff like this to get the data back out if there's a major failure.

Aaaaanyway, here's how to solve this particular problem. It's highly questionable whether it's worth the effort for data like video bookmarks without which you will probably be able to summon the courage to go on living, but this serves as an excellent example of how to do the same thing for other registry data transplants.

First, you need to run Registry Editor - regedit.exe - and back up the whole registry by right-clicking "Computer", selecting "Export" and saving it wherever you want.

Exporting the registry

If you screw up the registry, double-clicking that file and telling Windows that yes, you do want to copy its data to the registry, should rescue you.

Now, select HKEY_USERS and load the registry hive (File -> Load Hive) from the old computer. The hive you want will be a file called "ntuser.dat" in the subdirectory of Users on the old C drive that matches the account-name you were using on that computer.

(Allow me to digress to again recommend "Everything Search" from voidtools.com. It allows you to, for instance, instantly find every ntuser.dat on any NTFS-formatted drive in your computer.)

You now have to give the old registry a name to appear under in your own registry - make it something noticeable like "aaaaaa".

Importing a hive into the registry

It'll appear under that name, and you'll now be able to drill down in it to the keys containing the data you need. In this case, the place where your current MPC-HC will save its bookmarks is HKEY_CURRENT_USER\Software\MPC\HC\Favorites\Files, and the old one's data should now be findable in HKEY_USERS\aaaaaa\Software\MPC\HC\Favorites\Files.

If you're having trouble finding the data for a given program, press F3 in regedit to search, and enter a string from the program name. Regedit will search the entire registry for that string. For this particular case, there are several different versions of Media Player Classic, which have different registry locations; the original ones from Gabest Software, for instance, keep their bookmarks in ...\Gabest\Media Player Classic\..., like so:

Registry entries for a program

I'm showing you this, and not MPC-HC's registry location, because I happen to have an old NTUSER.DAT that had the old MPC installed, but I don't have one with MPC-HC.

(Oh, and apparently there's some malware thing that calls itself "Gabest Media Player Classic" too, which need not detain us here but which I thought was worth mentioning. Malware uses, or at least leaves footprints in, the registry just like all other Windows software, so if your computer's infected by this fake-media-player thing then you'll probably get search hits for the malware in the registry when you search for the real software.)

Now for the tricky bit.

Drill down to the Favorites\Files key in the MPC-HC section of the old registry hive (the old Gabest versions should have the same stuff in the same place), right-click it, and "Export" again. Save the exported data (which will be a much smaller file than your earlier gigantic export of the whole registry) as whateverfilenameyoulike.reg, and then have a look at it in a text editor. (Notepad is perfectly adequate.)

You'll see the text of all of the bookmark values, with at the top the version of Registry Editor that created the file, and then the registry address from which the data came. That registry address will be something like:

[HKEY_USERS\aaaaaa\Software\MPC-HC\MPC-HC\Favorites\Files]

And the bookmark data will all look like this:

"Name0"="name_of_video_file.mkv; 22201215000;K:\\movies\\name_of_video_file.mkv"
"Name1"="name_of_another_video_file.avi; 14229976361;C:\\Downloads\\Video\\name_of_another_video_file.avi"

The name of the file, then a long number that's the precious timestamp that's pretty much the whole reason for this lengthy exercise, and then the path to the file, including its name again.

If you double-click this new registry file you've made, you'll get a warning asking if you really want to add that data to the registry. You don't, yet, because all it'd do is write the data back to the same HKEY_USERS\aaaaaa\... location it came from, which is not where your current Media Player Classic will look.

All you have to do, though, is edit that square-bracketed address at the top, from HKEY_USERS\aaaaaa\... to the correct address for your current MPC, which is HKEY_CURRENT_USER\Software\MPC\HC\Favorites\Files.

(You can probably transplant the data between different MPC versions that keep their data in different places, too, but I'm making no promises.)

Widening our field of view back out to registry-editing in general to transplant program data from one Windows install to another, if you're uncertain of the location of a program's data, you'll have to search by program-name or program-author-name again, to find it. In this case you could get there a bit faster by making a bookmark in your current Media Player Classic. Somewhere among the hits in recently-opened-file lists and such there will be the location of the current MPC's bookmarks. Or, for speed, rename a video file to qqqqqqqqqq.avi or something, play it in MPC, make a bookmark, and then search the registry for qqqqqqqqqq. (The same trick can be done with other applications, if you just save a similarly-distinctively-named data file.)

Other logical edits to the .reg file's text will also work, allowing you to, for instance, change the location of all of the files if your video drive used to be E but is now F, or whatever.

Once you've got the .reg file re-aimed at the right key, double-click it and tell Windows that this time you do want to continue. Now, the next time you run MPC, your old bookmarks should be back. You can now safely delete the hive you imported into your registry and named "aaaaaa", too - though it won't do any harm just sitting there. (And in the dry run of doing all this stuff myself to make the screenshots and make sure I wasn't telling you to do something impossible, I just discovered that the old ntuser.dat that I imported into my own registry had some SecuROM stuff that couldn't be deleted because the keys had null characters in their names - which Microsoft have a special utility to counter! Aaaaaannd there's some stuff to do with the Protected Storage System Provider and old encryption certificates that also can't be deleted regardless of permissions settings, perhaps because Windows thinks I'm trying to delete current encryption-related stuff and throw my data away.

Fortunately, this bit of left-over cruft shouldn't mess anything up. Generally speaking, it's not adding things to the registry that causes problems, it's changing or removing stuff that was already there and doing something important. You can leave the whole old hive you imported sitting there under "aaaaaa" and all it'll do is take up a bit of disk space.

As I said, all of this is too much trouble to go to for data whose loss is only a slight nuisance. But it can really get you out of a tight spot - or save you some hefty tech-support fees - if vitally important data is locked up in an old registry.

 

Better than a diary with a lock

When I scanned through my son's chat history, checking to see if he was buying drugs or hiring prostitutes with my credit card (which I'd actually be pretty proud of, come to think of it, he's only nine), I found chunks of chat with some friends of his that all looked like this:

"yby ab qvqag qb vg z8 jung nobhg fro?" [this is one representative line from quite a lot submitted]

I don't think textspeak's gone quite that far yet, I presume this is a code. Do you know what kind of code it is?

[Name withheld, for security!]

Answer:
Yep: It's ROT13, a very simple "substitution cipher".

In ROT13, every letter of the message is "rotated" thirteen steps through the alphabet, wrapping around at the ends. ROT13 the text again and you get the original message. So your example of "yby ab qvqag..." ROT13s back into "lol no didnt do it m8 what about seb".

ROT13 is so simple that you can do it somewhat laboriously with pencil and paper, or automatically in various text editors, or indeed by applying the "awesome powa" of rot13.com. Because it's so simple, it provides no real cryptographic security - people use ROT13 more just to conveniently obscure non-secret text, like spoilers in a discussion of a movie.

It's often easy to spot ROT13 when you know that it exists, because common words like "the" and "and" rotate into strings that you can come to recognise ("gur" and "naq"). Work with it enough and you'll actually be able to read it directly, like a newsagent who's learned how to read upside-down. ROT13ed curse words are also highly recognisable and often even moderately pronounceable, which can be useful if you want to talk filthy in polite society without learning a whole new language.

I now suggest you make like the Allies in World War II and do not reveal to your enemy that you have broken his codes, lest he move on to better encryption when discussing un-done homework, unhealthy lunch foods and video games.

 

Other letters columns

I/O #1
I/O #2
I/O #3
I/O #4
I/O #5
I/O #6
I/O #7
I/O #8
I/O #9
I/O #10
I/O #11
I/O #12
I/O #13
I/O #14
I/O #15
I/O #16
I/O #17
I/O #18
I/O #19
I/O #20
I/O #21
I/O #22
I/O #23
I/O #24
I/O #25
I/O #26
I/O #27
I/O #28
I/O #29
I/O #30
I/O #31
I/O #32
I/O #33
I/O #34
I/O #35
I/O #36
I/O #37
I/O #38
I/O #39
I/O #40
I/O #41
I/O #42
I/O #43
I/O #44
I/O #45
I/O #46
I/O #47
I/O #48
I/O #49
I/O #50
I/O #51
I/O #52
I/O #53
I/O #54
I/O #55
I/O #56
I/O #57
I/O #58
I/O #59
I/O #60
I/O #61
I/O #62
I/O #63
I/O #64
I/O #65
I/O #66
I/O #67
I/O #68
I/O #69
I/O #70
I/O #71
I/O #72
I/O #73
I/O #74
I/O #75
I/O #76
I/O #77
I/O #78
I/O #79
I/O #80
I/O #81
I/O #82
I/O #83
I/O #84
I/O #85
I/O #86
I/O #87
I/O #88
I/O #89
I/O #90
I/O #91
I/O #92
I/O #93
I/O #94
I/O #95
I/O #96
I/O #97
I/O #98
I/O #99
I/O #100
I/O #101
I/O #102
I/O #103
I/O #104
I/O #105
I/O #106
I/O #107
I/O #108
I/O #109
I/O #109
I/O #110
I/O #111
I/O #112
I/O #113
I/O #114
I/O #115
I/O #116
I/O #117
I/O #118
I/O #119
I/O #120
I/O #121
I/O #122
I/O #123
I/O #124
I/O #125
I/O #126
I/O #127
I/O #128
I/O #129
I/O #130
I/O #131
I/O #132
I/O #133
I/O #134
I/O #135
I/O #136
I/O #137
I/O #138
I/O #139
I/O #140
I/O #141
I/O #142
I/O #143
I/O #144
I/O #145
I/O #146
I/O #147
I/O #148
I/O #149
I/O #150
I/O #151
I/O #152
I/O #153
I/O #154
I/O #155
I/O #156
I/O #157
I/O #158
I/O #159
I/O #160
I/O #161
I/O #162
I/O #163
I/O #164
Dan's Data letters #1
Dan's Data letters #2
Dan's Data letters #3
Dan's Data letters #4
Dan's Data letters #5
Dan's Data letters #6
Dan's Data letters #7
Dan's Data letters #8
Dan's Data letters #9
Dan's Data letters #10
Dan's Data letters #11
Dan's Data letters #12
Dan's Data letters #13
Dan's Data letters #14
Dan's Data letters #15
Dan's Data letters #16
Dan's Data letters #17
Dan's Data letters #18
Dan's Data letters #19
Dan's Data letters #20
Dan's Data letters #21
Dan's Data letters #22
Dan's Data letters #23
Dan's Data letters #24
Dan's Data letters #25
Dan's Data letters #26
Dan's Data letters #27
Dan's Data letters #28
Dan's Data letters #29
Dan's Data letters #30
Dan's Data letters #31
Dan's Data letters #32
Dan's Data letters #33
Dan's Data letters #34
Dan's Data letters #35
Dan's Data letters #36
Dan's Data letters #37
Dan's Data letters #38
Dan's Data letters #39
Dan's Data letters #40
Dan's Data letters #41
Dan's Data letters #42
Dan's Data letters #43
Dan's Data letters #44
Dan's Data letters #45
Dan's Data letters #46
Dan's Data letters #47
Dan's Data letters #48
Dan's Data letters #49
Dan's Data letters #50
Dan's Data letters #51
Dan's Data letters #52
Dan's Data letters #53
Dan's Data letters #54
Dan's Data letters #55
Dan's Data letters #56
Dan's Data letters #57
Dan's Data letters #58
Dan's Data letters #59
Dan's Data letters #60
Dan's Data letters #61
Dan's Data letters #62
Dan's Data letters #63
Dan's Data letters #64
Dan's Data letters #65
Dan's Data letters #66
Dan's Data letters #67
Dan's Data letters #68
Dan's Data letters #69
Dan's Data letters #70
Dan's Data letters #71
Dan's Data letters #72
Dan's Data letters #73
Dan's Data letters #74
Dan's Data letters #75
Dan's Data letters #76
Dan's Data letters #77
Dan's Data letters #78
Dan's Data letters #79
Dan's Data letters #80
Dan's Data letters #81
Dan's Data letters #82
Dan's Data letters #83
Dan's Data letters #84
Dan's Data letters #85
Dan's Data letters #86
Dan's Data letters #87
Dan's Data letters #88
Dan's Data letters #89
Dan's Data letters #90
Dan's Data letters #91
Dan's Data letters #92
Dan's Data letters #93
Dan's Data letters #94
Dan's Data letters #95
Dan's Data letters #96
Dan's Data letters #97
Dan's Data letters #98
Dan's Data letters #99
Dan's Data letters #100
Dan's Data letters #101
Dan's Data letters #102
Dan's Data letters #103
Dan's Data letters #104
Dan's Data letters #105
Dan's Data letters #106
Dan's Data letters #107
Dan's Data letters #108
Dan's Data letters #109
Dan's Data letters #110
Dan's Data letters #111
Dan's Data letters #112
Dan's Data letters #113
Dan's Data letters #114
Dan's Data letters #115
Dan's Data letters #116
Dan's Data letters #117
Dan's Data letters #118
Dan's Data letters #119
Dan's Data letters #120
Dan's Data letters #121
Dan's Data letters #122
Dan's Data letters #123
Dan's Data letters #124
Dan's Data letters #125
Dan's Data letters #126
Dan's Data letters #127
Dan's Data letters #128
Dan's Data letters #129
Dan's Data letters #130
Dan's Data letters #131
Dan's Data letters #132
Dan's Data letters #133
Dan's Data letters #134
Dan's Data letters #135
Dan's Data letters #136
Dan's Data letters #137
Dan's Data letters #138
Dan's Data letters #139
Dan's Data letters #140
Dan's Data letters #141
Dan's Data letters #142
Dan's Data letters #143
Dan's Data letters #144
Dan's Data letters #145
Dan's Data letters #146
Dan's Data letters #147
Dan's Data letters #148
Dan's Data letters #149
Dan's Data letters #150
Dan's Data letters #151
Dan's Data letters #152
Dan's Data letters #153
Dan's Data letters #154
Dan's Data letters #155
Dan's Data letters #156
Dan's Data letters #157
Dan's Data letters #158
Dan's Data letters #159
Dan's Data letters #160
Dan's Data letters #161
Dan's Data letters #162
Dan's Data letters #163
Dan's Data letters #164
Dan's Data letters #165
Dan's Data letters #166
Dan's Data letters #167
Dan's Data letters #168
Dan's Data letters #169
Dan's Data letters #170
Dan's Data letters #171
Dan's Data letters #172
Dan's Data letters #173
Dan's Data letters #174
Dan's Data letters #175
Dan's Data letters #176
Dan's Data letters #177
Dan's Data letters #178
Dan's Data letters #179
Dan's Data letters #180
Dan's Data letters #181
Dan's Data letters #182
Dan's Data letters #183
Dan's Data letters #184
Dan's Data letters #185
Dan's Data letters #186
Dan's Data letters #187
Dan's Data letters #188
Dan's Data letters #189
Dan's Data letters #190
Dan's Data letters #191
Dan's Data letters #192
Dan's Data letters #193
Dan's Data letters #194
Dan's Data letters #195
Dan's Data letters #196
Dan's Data letters #197
Dan's Data letters #198
Dan's Data letters #199
Dan's Data letters #200
Dan's Data letters #201
Dan's Data letters #202
Dan's Data letters #203
Dan's Data letters #204
Dan's Data letters #205
Dan's Data letters #206
Dan's Data letters #207
Dan's Data letters #208
Dan's Data letters #209
Dan's Data letters #210



Give Dan some money!
(and no-one gets hurt)