Wednesday, 16 September 2009

Batch Scripting: Environment Dates

Encountered a funny issue in our staging environment.
Seems like the environment date - %date% is user profile dependant.

If I run echo %date% using my account - I get 16/09/2009
If I run echo %date% using a service account - I get Wed 16/09/2009

Workaround is to strip the dayofweek from the above dates and then split each day, month and year component from the and reassemble each component manually.

For /F "tokens=1-4 delims=/ " %%i in ('date /t') Do (
Set _1=%%i
Set _2=%%j
Set _3=%%k
Set _4=%%l
)
:: Assign to datestamp and split out each date component to associated variable
:: Check for case when date stamp doesn't include day of week
If (%_4%)==() (
Set _datestamp=%_3%%_2%%_1%
Set _year=%_3%
Set _month=%_2%
Set _day=%_1%
) else (
Set _datestamp=%_4%%_3%%_2%
Set _year=%_4%
Set _month=%_3%
Set _day=%_2%
)

Monday, 10 August 2009

IIS: Resyncing Anonymous User Account Password

This error can occur if the password for the user account that is used for anonymous access in IIS is not synchronized with one of the following passwords:
  • The password for the user account in Active Directory
  • The password for the user account in Local Users and Groups
To synchronize the IIS password with the password that is used in Active Directory or in Local Users and Groups, follow these steps:

1. Click Start, click Run, type cmd, and then click OK.

2. Use the cd command to connect to the folder where the Adsutil.vbs file is located. By default, the Adsutil.vbs file is located in the following folder:
drive:\Inetpub\Adminscripts
Note drive is the folder where Windows is installed.

3. At the command prompt, type Cscript adsutil.vbs get w3svc/anonymoususerpass, and then press ENTER. Note the password that is generated.

Note You may have to set the Issecure property in the Adsutil.vbs file to False before you generate a password. To do this, follow these steps:

a. In Notepad, open the Adsutil.vbs file.
b. On the Edit menu, click Find, type IsSecureProperty = True, and then click Find Next.
c. Change “IsSecureProperty = True” to “IsSecureProperty = False”.
d. Save the changes, and then close Notepad.

4. Click Start, click Run, type Dsa.msc, and then click OK.

Note If the Web server is a stand-alone server, type Lusrmgr.msc.

5. Expand the domain that you want, and then click Users. If the Web server is a stand-alone server, click Users.

6. Right-click the user account that you want, and then click Reset Password or Set Password.

7. Type the password that you obtained in step 3 two times, and then click OK.

http://support.microsoft.com/kb/909887

Tuesday, 21 July 2009

HTML: optgroup

Grouping drop down items together:


Wednesday, 8 July 2009

SEO: Google analytics workaround for non-FQDN sites

we've setup google analytics on our external facing internet site and its been running great for the past year.
But now, we're looking at employing the same solution to our intranet.
Reading the FAQ on google, states that analytics requires two things for it to work correctly.

First, your internal network needs to be able to access certain resource files located on google's server.
Secondly, the site needs to have a FQDN (Fully Qualified Domain Name).

My problem is our intranet doesn't have an FQDN.
Read a few posts that there is a simple workaround for this.

First, copy the google tracking code and add it to a page on a site that does have a FQDN.

Add the _setDomainName property to the code, just beneath the variable declaration for pageTracker.
var pageTracker = _gat._getTracker("UA-xxxxxx-x");
pageTracker._setDomainName("none");

Change your settings in analytics to point to the location of the temporary site.
Confirm tracking code is working and leave it overnight to collect stats.

Once a day's worth of stats have been collected, you can remove the tracking code on your temporary site and append the code to your intranet site.

Analytics will continue tracking your site as if nothing has changed =)

Thursday, 2 July 2009

VS2003: Change or Move location of VSwebcache folder

The cache is usually located at :-

C:\Documents and Settings\username\VSWebCache
.

The path can be changed but only via the windows registry :-

HKCU\Software\Microsoft\VisualStudio\7.1\WebProject\OfflineCacheDir
.

Wednesday, 3 June 2009

TSQL: SQLNotify

Add this to the master database:

Useful for SQL Jobs used to notify failures and successes:

To use:

exec master.dbo.sp_sqlnotify 'From email','To email semi-colon separated','Subject','Body'

CREATE PROCEDURE [dbo].[sp_SQLNotify]
@From varchar(100) ,
@To varchar(100) ,
@Subject varchar(100)=" ",
@Body varchar(4000) = ""
/*********************************************************************

This stored procedure takes the above parameters and sends an e-mail.
All of the mail configurations are hard-coded in the stored procedure.
Comments are added to the stored procedure where necessary.
Reference to the CDOSYS objects are at the following MSDN Web site:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdosys/html/_cdosys_messaging.asp

***********************************************************************/
AS
Declare @iMsg int
Declare @hr int
Declare @source varchar(255)
Declare @description varchar(500)
Declare @output varchar(1000)

--************* Create the CDO.Message Object ************************
EXEC @hr = sp_OACreate 'CDO.Message', @iMsg OUT

--***************Configuring the Message Object ******************
-- This is to configure a remote SMTP server.
-- http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdosys/html/_cdosys_schema_configuration_sendusing.asp
EXEC @hr = sp_OASetProperty @iMsg, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendusing").Value','2'
-- This is to configure the Server Name or IP address.
-- Replace MailServerName by the name or IP of your SMTP Server.
EXEC @hr = sp_OASetProperty @iMsg, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/smtpserver").Value', 'your mail server'

-- Save the configurations to the message object.
EXEC @hr = sp_OAMethod @iMsg, 'Configuration.Fields.Update', null

-- Set the e-mail parameters.
EXEC @hr = sp_OASetProperty @iMsg, 'To', @To
EXEC @hr = sp_OASetProperty @iMsg, 'From', @From
EXEC @hr = sp_OASetProperty @iMsg, 'Subject', @Subject

-- If you are using HTML e-mail, use 'HTMLBody' instead of 'TextBody'.
EXEC @hr = sp_OASetProperty @iMsg, 'TextBody', @Body
EXEC @hr = sp_OAMethod @iMsg, 'Send', NULL

-- Sample error handling.
IF @hr <>0
select @hr
BEGIN
EXEC @hr = sp_OAGetErrorInfo NULL, @source OUT, @description OUT
IF @hr = 0
BEGIN
SELECT @output = ' Source: ' + @source
PRINT @output
SELECT @output = ' Description: ' + @description
PRINT @output
END
ELSE
BEGIN
PRINT ' sp_OAGetErrorInfo failed.'
RETURN
END
END

-- Do some error handling after each step if you need to.
-- Clean up the objects created.
EXEC @hr = sp_OADestroy @iMsg

PRINT 'Mail Sent!'




GO

Wednesday, 13 May 2009

AJAX: IE's autocomplete getting in your way

IE 6's autocomplete window was getting in the way of my input textbox.
It was hindering my javascript onblur event when you select a value from autocomplete with your mouse.

To stop this and get my onblur event working, I had to disable the autocomplete on my form.

To do this just add a new attribute to the tag.

Autocomplete=off

Monday, 11 May 2009

WSS3.0: Sharepoint Lists - modify default CRUD forms

REF : http://blog.henryong.com/2007/09/05/how-to-edit-the-form-fields-of-a-sharepoint-list/

Here’s an often forgotten feature that any SharePoint Designer person should be aware of. It’s the ability to edit and customize the default form fields for any list. This is made possible by using SharePoint Designer to navigate and open the form page that you want to edit. When you open the page you’ll see something like this:

You’ve probably tried right clicking around, trying to convert the web part to a dataview web part, and then you threw up your hands and said this is impossible!

But wait! Check this out… First select the ListFormWebPart and *EDIT: DO NOT hit the delete key. Instead hide the webpart. If you delete it, this will happen: http://support.microsoft.com/kb/935504

Ta da! Now you can go about your daily business of form customizations.

Thursday, 7 May 2009

TSQL: Email Notifications

Method 1:

When setting up a new SQL job, you can add additional steps after the job has run.

In the command area, type in the following to send an email:

exec master.dbo.sp_sqlnotify '[from email]','[to email 1];[to email 2]','[subject]','[msg body].'



Setup 2 additional steps, one for failure and one for success (only if you want to be notified on success), point the actions on Step 1 to the additional steps.