Posts tagged I.T.
Opening Terminal Server registry propogation window. (aka: Installing software in windows takes forever)
That’s not a typo. For the past few months, I’ve noticed that installing software or running updates on one particular terminal server that I manage (Windows Server 2003, std.), the updates/installation take hours — in some cases, days. So I enabled windows installer logging and here’s what I found:
MSI (s) (2C:E8) [02:35:44:188]: RunEngine wait timed out
Installer is no longer responding.
MSI (s) (2C:E8) [03:13:14:358]: RunEngine wait timed out
Installer is no longer responding.
MSI (s) (2C:E8) [03:50:44:453]: RunEngine wait timed out
Installer is no longer responding.
MSI (s) (2C:E8) [04:28:14:529]: RunEngine wait timed out
Installer is no longer responding.
MSI (s) (2C:E8) [05:05:44:619]: RunEngine wait timed out
Installer is no longer responding.
MSI (s) (2C:E8) [05:43:14:897]: RunEngine wait timed out
Installer is no longer responding.
Action ended 5:52:07: InstallInitialize. Return value 1.
MSI (s) (2C:30) [05:52:07:859]: Doing action: SxsInstallCA
Action start 5:52:07: SxsInstallCA.
So as you can see by the snippet above, this routine installation took an enormous amount of time. This exact scenario played out anytime I tried running updates or installing software. As it turns out, this was the problem. Simply removing the driver and deleting the following registry keys, and then installing the latest version of the driver (… I was on ~3 something; at the time of this writing, the latest version is 6.1) fixed the problem. Here are the registry keys that should be removed after the driver has been uninstalled (and before the latest version has been installed):
HKEY_CURRENT_USER\SOFTWARE\Hewlett-Packard
HKEY_USERS\.DEFAULT\Software\Hewlett-Packard
This was an extremely frustrating issue — other symptoms included server crashes with an error message about the registry being too large; logging in a brand new user for the first time takes ~15 minutes or so, and a whole host of other performance related weirdness. At first I thought that installing UPHClean would help solve this (the symptoms being registry-related and all) but it may have actually made the problem worse. If you scroll all the way down to the bottom of the page of the previous link to HP’s website, you’ll see the following post:
It is very likely that HP UPD problem replicating tons of registry keys to global default registry hive (.DEFAULT) being related to Terminal Server on which the Microsoft UPHClean Tool is installed. I would recommend to look at the readme.txt with UPHClean and setup an exclusion for svchost.exe/rpcss.dll.
“UPHClean assists the operating system to unload user profile hive by remapping the handles to the user profile hive to the default user hive. For example if a process has a handle to HKEY_USERS\S-1-5-21-X-Y-Z\Software\Microsoft after remapping it would have a handle to HKEY_USERS\.DEFAULT\Software\Microsoft.”
I haven’t had the chance to test this yet, but it does sound plausible enough. There’s also some other posts related to this on HP’s website that are worth having a look at. Here’s the readme.txt that comes with UPHClean. Setting up an exclusion list is fairly straightforward; for convenience, I’ve pasted the pertinent section of the UPHClean readme here:
=======================
Because UPHClean assists in unloading the users registry
hive some services may behave incorrectly. Administrators
are encouraged to test and watch for unexpected behavior.
If unwanted behavior is identified contact the developers of
software that UPHClean identified as preventing profile from
unloading.
UPHClean assists the operating system to unload user profile
hive by remapping the handles to the user profile hive to the
default user hive. For example if a process has a handle to
HKEY_USERS\S-1-5-21-X-Y-Z\Software\Microsoft after remapping
it would have a handle to HKEY_USERS\.DEFAULT\Software\Microsoft.
This allows the profile hive to unload. This may not work if the
application expects data that would only be available under the
specific user profile hive it was accessing since the data will not be copied.
If you find that removing UPHClean stops a particular problem from
occurring then you may be interested in restricting UPHClean from
processing certain handles. UPHClean ignores handles that are
held opened to profile hives for the users specified on the user
exclusion list or by processes specified on the process exclusion list.
These lists are specified using the following registry values:
HKLM\System\CurrentControlSet\Services\UPHClean\Parameters\PROCESS_EXCLUSION_LIST
HKLM\System\CurrentControlSet\Services\UPHClean\Parameters\USER_EXCLUSION_LIST
Note that since these values are specified as REG_MULTI_SZ strings
you should use regedt32 on Windows NT and Windows 2000 to edit them.
The process exclusion list is a list of process names that UPHClean
should ignore when determining which handles to user profile hives
to act on. Each process name is specified on its own line when
input in registry editor. The process name should be specified the
same way as it shows in Task Manager. Usually this is the file
name of the program (e.g. notepad.exe).
A few process show multiple times in Task Manager. It is possible to
specify that a certain DLL be loaded in the process to allow a selection
of a specific process. This is useful with the svchost process to identify
a specific instance. For example to specify the svchost process that
the Remote Procedure Call (RPC) service is running in on Windows 2000,
Windows XP and Windows Server 2003 you would specify
svchost.exe/rpcss.dll in the process exclusion list
The user exclusion list is a list of user security identifier (SID) or user that
UPHClean should ignore when determining which handle to user profile
hives to act on. Each user SID or name is specified on its own line when
input in registry editor. If specifying a user name you must enter the user
domain name followed by a backslash followed by the user name. For
example RCARONDOM\RCARON to specify the user RCARON from
domain RCARONDOM. SIDs should be specified in the usual string
format (e.g. S-1-5-21-2127521184-1604012920-1887927527-68486).
This is the same string you see under HKEY_USERS in registry editor.
Note that the user exclusion list always includes the following
SIDs: S-1-5-18, S-1-5-19, S-1-5-20. Unloading these profiles can cause
problems so UPHClean will not attempt to process handles to these profiles.
Which processes UPHClean performs handle remapping can specified
using the following registry value:
HKLM\System\CurrentControlSet\Services\UPHClean\Parameters\REMAP_HANDLE_PROCESS_LIST
The list by default contains ‘*’ which specifies that handle remapping should
be performed for all non-excluded processes. This list can be changed to
only include specified processes in the same manner as the process
exclusion list. Processes specified on this list can be preceeded by a ‘-’
character to specify that they should be excluded from handle remapping.
Any handle for a process that is not excluded but has handle remapping
turned off will be closed.
I hope this helps!
Solution for: “Microsoft office has stopped working” (applies to Office 2007 & 2010)
Symptoms: Microsoft word/excel/powerpoint/etc. crash a few seconds after being opened with the error message:
As a few clients of mine have upgraded to MS Office 2010, this problem has appeared a few times and it seems damn near impossible to fix… but there is a fix. You ready?
Set your default printer to the “Microsoft XPS Document Writer”.
I don’t know why this works, but it’s going to have to do until M$ releases and update/patch/fix/etc.
jqueryFileTree connector script for python cgi
If you use jquery and haven’t messed with the jqueryFileTree plugin, I’d highly recommend you do so. It’s pretty neat, and there are connector scripts already written in various languages for use with this plugin. However, there wasn’t one for python cgi (there was one for django however). So, I wrote my own! Try it out:
# jqueryFileTree connector script for python cgi
# Version: 1.0 / 10 August 2010
# Author: Charles Hamilton / musashi@nefaria.com
# Released under the GNU GPLv3
# Modifications and improvements are welcome
import os, cgi, cgitb, urllib, re
cgitb.enable()
form = cgi.FieldStorage()
print ’Content-Type: text/html\n\n‘
print ’<ul class="jqueryFileTree" style="display: none;">‘
path = urllib.unquote(form['dir'].value)
dirs = []
files = []
filelist = sorted(os.listdir(path))
for object in filelist:
if os.path.isfile(path + ‘/‘ + object):
ext = os.path.splitext(object)
files.append(‘<li class="file ext_‘ + re.sub(‘\.‘, ”, ext[1]) + ‘"><a href="#" rel="‘+ path + object + ‘">‘+ object + ‘</a></li>‘)
elif os.path.isdir(path + ‘/‘ + object):
dirs.append(‘<li class="directory collapsed"><a href="#" rel="‘+ path + object +’/">‘ + object + ‘</a></li>‘)
for d in dirs:
print d
for f in files:
print f
print ’</ul>‘
Python + Reportlab: example #1
So I’ve been using reportlab lately and I have to say, it’s pretty neat. This post will (hopefully) be the first of many to follow. It’s just a simple example that shows how to take input from a web form and insert it into a PDF. First, the code:
2
3 import cgi, sys
4
5 form = cgi.FieldStorage()
6
7 if not "name" in form:
8 print """Content-Type: text/html\n\n
9 <html>
10 <head>
11 <title>Reportlab Example</title>
12 </head>
13 <body>
14 <form action="index2.cgi" method="post" enctype="multipart/form-data">
15 <fieldset>
16 <legend>Personal Info:</legend>
17 Name: <input type="text" name="name"><br />
18 Photo: <input type="file" name="photo"><br />
19 <input type="submit">
20 </fieldset>
21 </form>
22 </body>
23 </head>"""
24
25 else:
26
27 from reportlab.platypus import *
28 from reportlab.lib.styles import getSampleStyleSheet
29 from reportlab.lib.units import inch
30 from reportlab.lib import colors
31 doc = SimpleDocTemplate(sys.stdout)
32 styles = getSampleStyleSheet()
33 content = []
34
35 if form['photo'].filename:
36 image = Image(form['photo'].file)
37 image.drawHeight = 2*inch*image.drawHeight / image.drawWidth
38 image.drawWidth = 2*inch
39
40 if form['name'].value:
41 text1 = Paragraph(form['name'].value, styles['Heading1'])
42 text2 = Paragraph(form['name'].value, styles['Heading2'])
43 text3 = Paragraph(form['name'].value, styles['Heading3'])
44
45 content.append(text1)
46 content.append(text2)
47 content.append(text3)
48 content.append(image)
49 print "Content-Type: application/pdf"
50 print "Content-Disposition: attachment; filename=example.pdf\n\n"
51 doc.build(content)
Now the explanation:
Lines #1 – #5 handle specifying the interpreter, importing modules, and initializing the “FieldStorage” dictionary (as the variable ‘form’).
2
3 import cgi, sys
4
5 form = cgi.FieldStorage()
Line #7 tests whether the form has been submitted by checking to see if the ‘name’ field has been filled out. There’s many better ways to test for form submission, but for the purposes of our example, this will work just fine.
Lines #8 – #23 print the form
9 <html>
10 <head>
11 <title>Reportlab Example</title>
12 </head>
13 <body>
14 <form action="index2.cgi" method="post" enctype="multipart/form-data">
15 <fieldset>
16 <legend>Personal Info:</legend>
17 Name: <input type="text" name="name"><br />
18 Photo: <input type="file" name="photo"><br />
19 <input type="submit">
20 </fieldset>
21 </form>
22 </body>
23 </head>"""
Lines #26 – #29 import some more modules (i.e., reportlab related stuff).
27 from reportlab.lib.styles import getSampleStyleSheet
28 from reportlab.lib.units import inch
29 from reportlab.lib import colors
Now line #30 is important, this is where we decide where we want to write the output. We can either save the output to a file, or we can dump it to stdout (i.e., back to the web browser). In this example, we’re going to send the output back to the web browser.
Line #31 handles getting the style sheet that we’re going to use to format our text.
In line #32, we initialize the ‘content’ dictionary — this is where we’re going to keep the elements of our PDF until we’re ready to write it to stdout.
In lines #34 – #37, we test for the ‘photo’ field — if it has been submitted, we create an Image object out of it. We’re assuming that the user is going to submit a photo, but in reality, the user could submit anything so some further “hardening” of this form would be required in order to ensure that the only things that actually get submitted are image files.
34 if form['photo'].filename:
35 image = Image(form['photo'].file)
36 image.drawHeight = 2*inch*image.drawHeight / image.drawWidth
37 image.drawWidth = 2*inch
Lines #39 – #42 test to see if the ‘name’ field has been submitted; if it has, it creates some text objects to insert into our PDF.
40 text1 = Paragraph(form['name'].value, styles['Heading1'])
41 text2 = Paragraph(form['name'].value, styles['Heading2'])
42 text3 = Paragraph(form['name'].value, styles['Heading3'])
Lines #44 – #47 append all the objects that we want to appear in our PDF, to the ‘content’ dictionary we created earlier.
45 content.append(text2)
46 content.append(text3)
47 content.append(image)
Lines #48 – #49 send the appropriate headers to the web browser, before we send our completed PDF file.
49 print "Content-Disposition: attachment; filename=example.pdf\n\n"
And finally, line #50 builds our PDF and sends the output to stdout.
Test it out; you should end up with a PDF that looks something like this:
Of course, this example doesn’t even scratch the surface of what you can do with reportlab. Hopefully I’ll post some more examples later on