Scheduled Tasks Failing to Fire VBS Scripts

I have a Windows Server 2003 box with a bunch of scheduled tasks that fire VBS scripts through the day, handling various maintenance, data import and other jobs for a client's web site.

Over the past few days I noticed the jobs were not firing, and after a fair bit of research I finally found a solution.

The first clue came when I tried to call the VBS scripts directly in the command prompt, and received the following error message:

cscript error loading your settings failed access is denied

Which seemed a strange error given I was logged in as a user with Administrator permissions.

After a little more poking around I noticed two more oddities:

1. The Start Menu didn't look right – for example, the Accessories folder didn't contain many of the shortcuts I'd grown used to

2. The Documents and Settings folder contained duplicate user profile folders, for example:

– [username]
– [username].[machinename]
– [username].[machinename].000
– [username].[machinename].001
– [username].[machinename].002

all the way through to

– [username].[machinename].012

I also noticed in my command prompt window that I appeared to be logged in under the '012' profile.

I found this article that pointed the way:

http://support.microsoft.com/?kbid=314045

I searched the Registry for the ProfileImagePath key and found it was set to:

%SystemDrive%\Documents and Settings\[username].[machinename].002

I changed it to:

%SystemDrive%\Documents and Settings\[username]

I logged off, and logged back on again, and this time I was logged in with the [username].[machinename] profile – confirmed by opening the command prompt:

C:\Douments and Settings \[username].[machinename]>

I then tried to call the VBS scripts in the command prompt and they worked fine. Then via Scheduled Jobs window. Again all ok. And my Start Menu is back to normal as well.

As a sidebar I've noticed that the duplicate user profile folders were all created over the space of a single day – Christmas Day. Which is strange because I know that on Xmas Day I wasn't hunched over a computer RDCing into web servers, rather I was enjoying a day off with my family. The duplicate folders were all empty (eg they didn't have the normal complement of folders such as My Documents, Desktop, Favourites and so forth). All except the last one, 012. But that was the one I was logged into. So somehow Windows reacted to something and created the duplicates – but presumably whatever the 'something' was didn't constitute a login otherwise it would have populated the folders with the subfolders needed for the profile.

I've Google a little but can't immediately find anything that explains a big bunch of duplicate user profile folders turning up that are all empty.

All a bit strange, and I wish I had a more concrete explanation for how this all came about.

 

 

 

 

 

Check the page set up on your browser to make sure it prints text as black – NOT!

Here's an easy, blatant example of a web site with a built in problem, that the owner acknowledges but who has decided to make it the user's problem.

I picked up a parking ticket the other day and just went to pay the fine. It was with the City of Port Phillip, which like a bunch of councils around Melbourne uses the maxi.com.au online payment system (I remember Maxi launching years ago amidst much hullabaloo, ideas like terminals all over the city etc etc. Nowadays it still exists but only for these small irritating payments).

Anyhow, I dutifully pumped my Visa card number in, and back came the receipt page, which is a classic fail. Here's the page:

Maxi

The text I've highlighted says:

(If you print your receipt, check the page set up on your browser to make sure it prints text as black.)

So of course, red rag to a bull, I clicked the print button, yup, an entire page of dark blue background plus the white text.

They KNOW it's a problem, but they put it onto the user to solve the problem. Hands up everyone who knows how to change the page set up on their browser so that it would reverse or otherwise deal with this ludicrous situation? I do this for a living and I'd probably fiddle for 5 minutes.

Yet the issue is so incredibly simple to fix – just change the styling on the page to a white background and dark text. In fact, I'm positive the last time I used Maxi this issue didn't exist – which means they've updated the site and created a new problem.

 

How to host IIS7 web site on Mac OSX folder via Parallels

This has bugged me for a long time. I run Parallels on my MacBook Pro because I often have to work with Windows programming technologies, mostly Visual Studio and SQL Server. When I'm developing in Windows I run a localhost copy of the web site in IIS7 (I have Vista on my Mac). Up until now I've kept the site files in the Parallels VM windows drive, but this has constantly annoyed me because I don't back up my Windows drive with Time Capsule. Take too long and causes a marked slow down in my system each hour when the backup is running. Parallels has a specific option to not back up the VM with Time Capsule and I have that selected.

Every time I've ever tried to hook an IIS web site to a folder on my Mac (eg not in the VM) it's never worked – endless errors. Finally after a bit of hunting around I pulled together various tidbits of information from the net and made it work. Here's how:

1. In Parallels configuration make sure you are using Bridged Networking, this is to ensure your VM has a separate IP number to your Mac.

2. In Mac System Preferences > Sharing, enable File Sharing. Add the root folder for your web site (on your Mac) to the list of Shared Folders and give all users all rights (I kept it simple with permissions and just gave everyone every right, it's only for my localhost so I don't think security is a big deal).

3. In Windows use File Explorer and open Network and locate your Mac and the root folder for your web site. Copy the path, on mine it looks like \\MACBOOKPRO-31F6\wwwroot

4. In Windows IIS add a new web site, In Advanced Settings set the Physical Path to the network path you copied above

5. Still in Advanced Settings set the Physical Path Credentials to your Mac user name and password. I wound up adding a new Windows user with the same user name and password as I have on the Mac. I'm not completely sure if this is the right thing to do, but heck, it worked.

6. If you already have a default web site in IIS, you'll need to sort out the bindings, you can't have more than one web site on the same port, which by default is 80. Right click the new web site and edit the Bindings. I set the port to 8080.

7. In Windows open your browser and try http://localhost:8080/, you should see the default page, if you have one, from the folder on your Mac. If, like me, it didn't work first time, try creating a simple hello.htm and calling that. I discovered my problem was simply paths and configuration variables in my web site – moral being try calling the most basic page first before blaming errors on IIS rather than your web app.

ASP: Hiding file locations by binary stream reading

ASP: Hiding file locations by binary stream reading

I do a lot of work with internet content business – companies that earn their living by managing documents and content, either for their own services or on behalf of customers.

Often this involves making documents on the server available for viewing, but without propagating the URL of the actual file, and with permission checks to ensure that the person viewing the file is authorised to do so.

Here’s a simple technique to make a file, such as a PDF, available without revealing the file’s URL and with a security check.

The trick is to binary read the file to the user’s browser, instead of the user opening the file directly. In ASP we do this with the ADODB.Stream object. This allows us to open the file on the web server as a binary stream and send it to the browser. The user will be none the wiser to the file’s location.

 

' Run a security check
' Add code here to ensure that the logged in user has permission to view the file
' if we have a file identifier
if fileId>0 then
' grab the file's name and location - probably from a database table
sqlStr="SELECT filePath,fileName FROM tblMyFiles WHERE fileId="&request("fileId")
set rs=Server.CreateObject("adodb.Recordset")
rs.cursorlocation=aduseclient
rs.cachesize=1
rs.open sqlStr, conn, adOpenForwardOnly,adLockReadOnly
' if the file entry in our database table is found
if not rs.eof then
' open the file system object
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
' check the file we want does actually exist
If objFSO.FileExists(filePath&lcase(rs("fileName"))) then
' and if it does exist, then spit out to the browser
' open a binary stream for the file
Set strOutStream = Server.CreateObject( "ADODB.Stream" )
strOutStream.Type = 1 'adTypeBinary
strOutStream.Mode = 3 'adModeReadWrite
strOutStream.Open
' load the file into the stream
strOutStream.LoadFromFile (filePath&lcase(rs("fileName")))
Response.Buffer = TRUE
' use the content type appropriate to the file - here we're using a PDF
Response.ContentType = "application/pdf"
Response.AddHeader "content-disposition", "inline; filename=" & rs("fileName")
Response.BinaryWrite (strOutStream.Read)
Response.End
strOutStream.Close
Set strOutStream = Nothing
end if
set objFSO=nothing
end if
rs.close
Set rs=nothing
end if

activePDF ToolKit Error Code -998

So I don't have to yet again hunt down the activePDF ToolKit documentation, if an Error Code -998 is returned by activePDF ToolKit it means 'Product not registered/ Evaluation expired.'. And you have to take up arms and prepare to enjoy chasing down why your previously registered copy has decided, perhaps in a fit of pique, that it's happier unregistered. Which is not a fat lot of help when the bloke who has the serial number database is in a timezone slumbering through the middle of the night, it's the midst of a workday for you and you promised someone something for tomorrow.

I completely agree with software licencing. It's how companies legitimately make money. But some seem to have registration management systems calculated to drive us mere code crunchers up the wall.

 

Displaying code in your TypePad blog

Yesterday I wanted to show some SQL code in a blog post, and realised I'd never figured out how some blogs are able to display beautifully formatted, in living colour, code in their posts.

A quick Google and all was revealed: SyntaxHighlighter from Alex Gorbatchev. I then found a handy 'how to' install SyntaxHighlighter into a TypePad blog from Damien Krotkine. Five minutes later I was up and running.

 

 

 

iPad stencil for Omnigraffle

I've spent part of today scoping the screens for a new iPad application for a client. I normally use the wonderful Omnigraffle for this type of thing, so went hunting for iPad stencils for Omnigraffle and found:

This worked perfectly (just download, unzip, and place the stencil files into users/library/application support/omnigraffle/stencils.

These guys have a nifty app called Writer that I really must take a closer look now I know that one of my gods Stephen Fry knows its name.

 

Twitter sure handles a lot of messages

Been battling some Twitter code I wrote a few months ago that first posts a status update to a Twitter account using /statuses/update.json, then allows a user to retweet using /statuses/retweet/[tweetMessageId].json to another Twitter account.

When I tried the routine this morning it steadfastly refused to send the re-tweet. The Twitter api just returned 'Not Found'.

I tore all the routines apart, added debugs everywhere, without success. Then, staring at the returned JSON values, with the database open on another screen, I finally twigged.

When I post the Tweet I'm grabbing the message ID number and saving that to the database. Then, when I want to retweet, I use that message id in the retweet end point.

A couple of months ago the message Ids were 11 digits long, now they are 16 digits. I'd been grabbing the 'id' value coming back from Twitter, but a number that long was getting truncated by my JSON parse routine (I'm using the very handy JSON2 library). I checked the JSON values and Twitter very kindly also sends back 'id_str', which is the message id as a string. For example the JSON contained:

"id":1436631697457152

"id_str":"1436631697457152"

Indeed, now I look more closely, I can see that they also send back the ID of the Twitter account using the same, for example:

"id_str":"112303018"

I guess the explosion in the message Id in the past few months just continues to underscore the remarkable growth in Twitter's scale, presuming the message ID values have simply been incrementing sequentially over that time and haven't been jumped ahead manually for some reason.

 

WordPress “The requested theme does not exist”

Oh what fun. Was updating my theme on one of my WordPress blogs, saved the change, and up came an error page "the requested theme does not exist".

Googled and found someone else with the same problem.

Wound up doing what the commenters suggested – pulled the original CSS from archive, and laboriously had to go through and make my changes again. Easy way to waste half and hour. Alright now though.

Open a range of ports on Windows Firewall

Needed to open a big range of ports on Windows Firewall on one of my web boxes. Via the GUI you can only do one port at a time. But run this at the command prompt to add a range:

FOR /L %I IN (5001,1,5201) DO netsh firewall add portopening TCP %I "Passive FTP"%I

This opens ports 5001 to 5201, and names them 'Passive FTP'.

Found this here.

Oh, takes time, like a port or two a second, so if you have a wide range it's going to take some time.