Riaan Lehmkuhl's Blog

Subversion, Progamming, Tips & Tricks and whatever else springs to mind.
04Nov

Get DOS 8.3 short name with VbScript

04 November 2009 10:26 by Riaan Lehmkuhl
Create a new text file called shortname.vbs Open in notepad and paste the following code in it:
set fso = CreateObject("Scripting.FileSystemObject") 
strLongName = Wscript.Arguments(0)
strShortName = "Invalid File/Folder - (" & strLongName & ")"
Set fsoFile = Nothing
On Error Resume Next
Set fsoFile = fso.GetFile(strLongName)
if Err.number <> 0 then
Set fsoFile = fso.GetFolder(strLongName)
end if
if fsoFile is not nothing then
strShortName = fsoFile.ShortPath
end if
Wscript.Echo strShortName
Run the script using cscript:
cscript shortname.vbs "C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe"
You will then get the following output:
C:\PROGRA~1\Adobe\READER~1.0\Reader\AcroRd32.exe

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
23Feb

Windows.Forms Binding errors with .Net 2.0 (Part 4)

23 February 2009 20:53 by Riaan Lehmkuhl

The problem:
In a DataGridView control, after adding a new row, and clicking away, the new row just disappears without any visible error.

The solution:
This is most likely caused by an error being raised due to a data input error. Im my case it was because of a non visible column not allowing nulls.
To find out if this is the cause of yoyr issue, put a break point in the DataError event handler. Even though the error might have beeen written to the row's ErrorText, it is never displayed because the row disappears.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
19Aug

MSTSC /console not working anymore

19 August 2008 21:13 by Riaan Lehmkuhl
When using the "Virtual Server Administration Website" to admin your Virtual Server 2005 R2 virtual servers one needs to be logged on to the console of the host server or you get a HTTP 500 Internal Server Error message. For this reason I've always used the mstsc /console command to log in to session 0 of the host server, but to my dismay this just didn't seem to work anymore.
I opened the command prompt and typed in mstsc /?. Lo and behold, the console option is gone:
---------------------------
Remote Desktop Connection Usage
---------------------------
MSTSC [] [/v:] [/admin] [/f[ullscreen]]
[/w: /h:] [/public] | [/span] [/edit "connection file"] [/migrate]
"connection file" -- Specifies the name of an .rdp file for the connection.
/v: -- Specifies the remote computer to which you want to connect.
/admin -- Connects you to the session for administering a server.
/f -- Starts Remote Desktop in full-screen mode.
/w: -- Specifies the width of the Remote Desktop window.
/h: -- Specifies the height of the Remote Desktop window.
/public -- Runs Remote Desktop in public mode.
/span -- Matches the remote desktop width and height with the local
virtual desktop, spanning across multiple monitors if necessary. To span
across monitors, the monitors must all have the same height and be aligned
vertically.
/edit -- Opens the specified .rdp connection file for editing.
/migrate -- Migrates legacy connection files that were created with
Client Connection Manager to new .rdp connection files.
---------------------------
OK   
---------------------------
I noticed the /admin switch, which seemed to do the trick.
After some more research I've found that this was apllied with XP SP3 and supposed to be because of some new security features in Windows Server 2008 and Vista SP1. Due to this fact this trick won't work on these.

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
23Jul

Firefox 3 Bug: invalid 'in' operand this._sandbox

23 July 2008 19:27 by Riaan Lehmkuhl

If you are getting the following JavaScript error in Firefox 3, here is a quick workaround:

Error: invalid 'in' operand this._sandBox Source File: file:///C:/Program%20Files/Mozilla%20Firefox/components/nsProxyAutoConfig.js Line: 95
Open the file mentioned in your favourite text editor (one that can handle unix line endings; if you have nothing else, use WordPad), and seach for the this line:
if (!("FindProxyForURL" in this._sandBox))
   return null;
and wrap it in a try/catch block like this:
try {
   if (!("FindProxyForURL" in this._sandBox))
      return null;
} catch (e) { return null; }
Save your changes, and restart Firefox.

Although this is probably not the correct way to solve this problem, at least it helps to keep the 'Error Console' garbage free.

 

Currently rated 2.6 by 10 people

  • Currently 2.6/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
22Jul

Moving from Blogger to BlogEngine.NET

22 July 2008 02:42 by Riaan Lehmkuhl

I just moved my blog from Blogger to BlogEngine.NET. I done this for various reasons, but mainly because I'm a control freak.

Although I could have used the "blog.importer.application" provided by BlogEngine.NET, I did the export and import manually to have full control of the process.

Normally when moving domains the best way would of course be to setup 301 redirects, So my new blog to keep rankings etc. but Blogger has made that impossible.

I searched for ways for just forwarding all the requests to the Blogger blog to my new blog and found many posts on moving from Blogger to Wordpress. So this post just includes the specifics for BlogEngine.NET.

The main two sources I used was:

I wanted my old blog to stay up with posts intact so that people that has bookmarked it or any posts can still find what they are looking for and because read this post: why-you-should-never-delete-your-blogger-blogs.

The Walkthrough:

(Remember to replace "YOUR_NEW_BLOG_DOMAIN_HERE" with your blog's address.)

  • Setup the auto redirect:
    Log into your Blogger account, navigate to the "Layout" tab and click on "Edit HTML". In the template editor put the following in the <head>...</head>:
    <meta content='5;url=http://YOUR_NEW_BLOG_DOMAIN_HERE/' http-equiv='refresh'/>
    This will handle the front page redirection of the blog.
  • To let the users know that your blog has moved, and that they will be redirected, add a message to the page:
    <div style='position: absolute; top: 30px; left: 30px; border: solid 2px #333; color: #000; background-color: yellow; padding: 5px; width: 400px; z-index: 5; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: large;opacity: .4;filter: alpha(opacity=40);'>
    <p><strong>My blog has moved!</strong></p>
    <p>You should be automatically redirected in 5 seconds. If not, visit<br/> <a href='http://YOUR_NEW_BLOG_DOMAIN_HERE/'> <strong>YOUR_NEW_BLOG_DOMAIN_HERE</strong></a> <br/> and update your bookmarks.</p>
    </div>
    Place this right after the opening <body> tag.
    redirect
  • Because your new blog will contain all the posts from the old Blogger blog you need to avoid being penalised for duplicate content, add this to the "head" section as in point one...
    <META NAME="ROBOTS" CONTENT="NOINDEX, FOLLOW"/>
    <META NAME="GOOGLEBOT" CONTENT="NOINDEX, FOLLOW"/>
    NOINDEX FOLLOW tells the crawler not to index the Blogger page but to FOLLOW the redirect. NOINDEX will also instruct the crawler to drop any already indexed version of page.
  • To make the individual posts forward to their new counterparts a few things need to be done:
    1. On the Blogger control panel in “Settings -> Formatting”, change the Timestamps on posts to the MM/DD/YYYY format.
    2. Look for this code in the Blogger Template
    <b:section class='main' id='main' showaddelement='no'>
    and enter the following widget code under it (combine the three bits):
    <b:widget id='Redirector' locked='true' title='Blog Posts' type='Blog' >
    <b:includable id='main' >
    <b:if cond='data:blog.pageType == "item"' >
    <b:loop values='data:posts' var='post' >
    <div id='redirectorTitle' style='visibility:hidden' > <data:post.title/ > </div >
    <script type='text/javascript' >
    var new_domain = 'http://www.lehmkuhl.za.net/blog/post'
    function utf8_uri_encode( str ) {
       var high_code = new RegExp(/[\u0080-\uffff]+/);;
       new_str = str;;
       while( m = high_code.exec( new_str ) ) {
          new_str = new_str.replace(m,encodeURIComponent(m));;
       }
       return new_str;;
    }
    var title = document.getElementById('redirectorTitle').innerHTML;;
    // [INCOMPLETE] Keep percent signs that aren't part of an octet?
    title = title.replace(/<[^>]*?>/g,'');; // remove tags
    title = title.replace(/&.+?;/g,'');; // remove entities
    title = utf8_uri_encode(title);; // handle UTF-8 characters
    title = title.toLowerCase();;
    title = title.replace(/[^%a-z0-9 _-]/g,'');; // remove punctuation
    title = title.replace(/\s+/g,'-');; // turn spaces into hyphens
    title = title.replace(/-+/g, '-');; // collapse runs of hyphens
    title = title.replace(/^-+/g,'');; // remove prefixed hyphens
    title = title.replace(/-+$/g,'');; // remove suffixed hyphens
    var timestamp = ' <data:post.timestamp/ >';
    timestamp = timestamp.split('/');
    timestamp = timestamp[2]+'/'+timestamp[0]+'/'+timestamp[1];
    var new_page = new_domain + '/' + timestamp + '/' + title + '.aspx';;
    document.location.href = new_page;
    </script >
    </b:loop >
    </b:if >
    </b:includable >
    </b:widget >

    This will redirect the blogger post...
    http://someblog.blogspot.com/2008/06/some-blog-post.html
    ...to...
    http://YOUR_NEW_BLOG_DOMAIN_HERE/post/2008/06/28/some-blog-post.aspx

To see a working example visit my old blog at http://somethingsubversion.blogspot.com/.

Currently rated 3.0 by 5 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
13Jul

Add Google Talk Online Presence to Web Pages

13 July 2008 00:08 by Riaan Lehmkuhl
If you use Google Talk instant messenger and would like to stay connected with visitors on your website, the Google Talk chatback badge is a cool way to display to them when you are online and available to chat / IM with them.

Just point your browser to http://www.google.com/talk/service/badge/New, and follow the easy instructions.

Currently rated 3.0 by 5 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
11Jul

Unable to run Proclarity Web Professional

11 July 2008 00:05 by Riaan Lehmkuhl

A while after installing and configuring Proclarity 6.3 the users started receiving a blank page when accessing Proclarity Web Professional:

Click to see larger image 

After some searching I found this post: http://forums.microsoft.com/TechNet/ShowPost.aspx?PostID=2901084&SiteID=17. There is a bug in Proclarity, for which MS has released a hotfix: http://support.microsoft.com/kb/946719.

Downloaded an installed the hotfix just to find a brand new error:

Unable to run Proclarity Professional. Either the required components are not installed or you don't have permission to download them.

 

Click to see larger image 

The user is a member of the Administrator so permissions shouldn't be an issue. The search continues…

I found a new hotfix rollup package released after the one I had installed: http://support.microsoft.com/kb/953604. But after installing it, the problem was still there!

Back to Google…

I tried everything suggested in this post about the subject: http://forums.microsoft.com/TechNet/ShowPost.aspx?PostID=2396186&SiteID=17

  • Give users professional access in the ProClarity Administration Tool (Analytics Server Administration Tool).
  • Select the components folder in the admin tool, right click the web professional and choose properties. Make sure the box "required component" is selected.
  • Made sure no pop-up blockers are enabled.

Oops! Still the same error.

To my surprise, it worked when I ran Web Professional from the server. This meant that Proclarity is working but that there has to be a problem with the user access.

Time to fool around... In the Analytics Server Administration Tool, I added a new user Role, ProclarityWebUsers, and added the required users to it. Then on the Publishing tab of the role properties I clicked on Allow All.

Click to see larger image 

And the same on the Access Rights tab.

Click to see larger image 

Returned to Proclarity Web Professional and another big surprise… It worked!

 Click to see larger image

If you are experiencing the same issues, I hope this helps. I'm not a Proclarity guru and have no idea which of these steps are the actual ones to solve the problem.

Happy analytics!

Currently rated 3.0 by 5 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
19Jun

Adding an Ordinal column using a sub query

19 June 2008 23:10 by Riaan Lehmkuhl
This is just a simple way of adding an ordinal column to a SQL result using a sub query. This method depends on the Primary Key field of the table. I used the Northwind database for this example.
The idea is to select the Products with an ordinal numbered column...
Ordinal ProductID ProductName CategoryID
1 11 Queso Cabrales 4
2 12 Queso Manchego La Pastora 4
3 31 Gorgonzola Telino 4
4 32 Mascarpone Fabioli 4
5 33 Geitost 4

To do this I've created the following stored procedure with the CategoryID is an optional parameter:
CREATE PROCEDURE [dbo].[sp_SelectProducts]
(
@CategoryID INT = NULL
)
AS
DECLARE @sql NVARCHAR(4000)
SET @sql = N'
SELECT top 5 (SELECT COUNT(*) 
FROM Products p 
WHERE p.ProductID <= Products.ProductID '
IF (@CategoryID IS NOT NULL) BEGIN
SET @sql = @sql + N' AND p.CategoryID = Products.CategoryID '
END
SET @sql = @sql + N') AS Ordinal,
ProductID,
ProductName,
CategoryID,
QuantityPerUnit,
UnitPrice,
UnitsInStock,
UnitsOnOrder,
ReorderLevel
FROM Products
WHERE Discontinued != 1'
IF (@CategoryID IS NOT NULL) BEGIN
SET @sql = @sql + N' AND CategoryID = ' + CAST(@CategoryID AS NVARCHAR)
END
EXEC sp_executesql @sql;
For each product that is returned we get it's ordinal position by counting the ProductIDs already returned and it self.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
12Jun

Microsoft Excel - How to check if a value exists in a range

12 June 2008 23:04 by Riaan Lehmkuhl
I had to compare some simple lists. I could have used a database, loaded the lists and used sql to do the comparisons. Not in the mood for that, then let's just use Excel.
We have the following two lists in a spreadsheet and we want to know which of the values in column B exists in column A:
  A B C
1 Fusce Vestibulum  
2 mauris mattis  
3 nulla Fusce  
4 pellentesque consequat  
5 iaculis libero  
6 aliquam eu  
7 eu sem  
8 tincidunt Nullam  
9 consequat iaculis  
10 metus elit  


After some digging around in the Excel functions, I found VLOOKUP that does the trick:
  A B C
1 Fusce
Vestibulum
=VLOOKUP(B1,$A$1:$A$10,1,FALSE)
2 mauris mattis #N/A
3 nulla Fusce Fusce
4 pellentesque consequat consequat
5 iaculis libero #N/A
6 aliquam eu eu
7 eu sem #N/A
8 tincidunt Nullam #N/A
9 consequat iaculis iaculis
10 metus elit #N/A


In column C it prints the search value if it was found, or "#N/A" if not found. This is ok, but we can make it look a bit nicer by adapting the formula a little bit:
  A B C
1 Fusce
Vestibulum
=ISNA(VLOOKUP(B1,$A$1:$A$10,1,FALSE)=B1)=FALSE
2 mauris mattis FALSE
3 nulla Fusce TRUE
4 pellentesque consequat TRUE
5 iaculis libero FALSE
6 aliquam eu TRUE
7 eu sem FALSE
8 tincidunt Nullam FALSE
9 consequat iaculis TRUE
10 metus elit FALSE


Using the updated formula, "TRUE" is printed if the value in column B is the same as the value returned from VLOOKUP otherwise "#N/A" is returned. This in turn is handled by the ISNA function, that's return value is then inverted so that the "TRUE" for "#N/A" is displayed as "FALSE" (the value was not found).

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
12Jun

Simple lamda expression example in C#

12 June 2008 22:58 by Riaan Lehmkuhl
A friend asked me for an example of a lamda expression, and after going through my code and searching the net, I discovered this little gold nugget:
A lambda expression is a way of creating a function without giving it a name.
Suppose you defined: bool blah(n) { return n%2 == 1; } That's a function named blah. (n => n%2 == 1) int[] numbers = {5,4,1,3,9,8,6,7,2,0 }; int oddNumbers = numbers.Count(n => n % 2 == 1); "numbers" is the sequence. It's an array, implementing IEnumerable<int>.
If you just call numbers.Count() you'll get 10. The version with the lambda expression is saying "only count elements which match this predicate".
It's sort of similar to calling: numbers.Where(n => n % 2 == 1).Count();
Reference:
http://www.eggheadcafe.com/software/aspnet/31850595/confused-about-the-lamda.aspx

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Riaan Lehmkuhl


Me, a disorder of the brain that results in a disruption in a person's thinking, mood, and ability to relate to others.

Recent comments

Comment RSS

Thingies

Calendar And Month List

<<  March 2010  >>
MoTuWeThFrSaSu
22232425262728
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar

Disclaimer & Privacy

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Privacy:
We use third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.

Most comments

Kevin Kevin
1 comments
gb United Kingdom
Moneymaker Moneymaker
1 comments
Indonesia Java International Destination Indonesia Java International Destination
1 comments
us United States

Cool Quote

I know that you believe that you understood what you think I said, but I am not sure you realize that what you heard is not what I meant. - Robert McCloskey