Jul 8 2008

Windows Command Line Find and replace – Made easy

I finally found a great little application that does a find and replace on a particular file or file type, then replacing it with a string, of your choice. It also looks in sub directory, whilst there are many grep’s out there most are GUI for windows or pay for items that run command line… I like free better, don’t you?

And yes SED could do it, as could a few other apps, but why write something when this  can be done so much easier?

the small app is called FART, yes that’s right FART!

Here are the options FART provides

Find And Replace Text  v1.99b                         by Lionello Lunesu

Usage: FART [options] [--] <wildcard>[,...] [find_string] [replace_string]

Options:
-h, –help          Show this help message (ignores other options)
-q, –quiet         Suppress output to stdio / stderr
-V, –verbose       Show more information
-r, –recursive     Process sub-folders recursively
-c, –count         Only show filenames, match counts and totals
-i, –ignore-case   Case insensitive text comparison
-v, –invert        Print lines NOT containing the find string
-n, –line-number   Print line number before each line (1-based)
-w, –word          Match whole word (uses C syntax, like grep)
-f, –filename      Find (and replace) filename instead of contents
-B, –binary        Also search (and replace) in binary files (CAUTION)
-C, –c-style       Allow C-style extended characters (\xFF\t\n\r\\ etc.)
     –cvs           Skip cvs dirs; execute “cvs edit” before changing files
     –svn           Skip svn dirs
     –remove        Remove all occurences of the find_string
-a, –adapt         Adapt the case of replace_string to found string
-b, –backup        Make a backup of each changed file
-p, –preview       Do not change the files but print the changes

 

As an example

fart -c -r -i -p *.config databaseserver1 databaseserver2

this will look for all config files in a sub directory then looking for the databaseserver1 string within the .config file and then changing it to databaseserver2, If you notice i have a -p which means it wont actually change anything because this is a preview, showing you how many strings it found within each .config file.

Download FART here

http://sourceforge.net/projects/fart-it/


Jun 13 2008

MSSQL: Automatically Create table and insert records

 

So we have started to create an IP accounting package the, package will dump to a CSV file on a daily Basis. We needed to be able to report on that, the easiest way is defiantly importing it into SQL server.

So I created a script that will create a table called ‘accounting_datehere’

With our requirements, we needed yesterdays date, as the import would happen once a day to and would happen after the day has ended (12:00am) which would give us the most accurate results. so therefore we needed to change the date stamp on the table name to yesterdays date, by adding a -1 to the Getdate() this would allow us to append yesterdays date.

Once the table is created, it does an insert from a CSV which is using a UNC connection.

 

Here is the code.

   1: Use Master
   2: declare @tablecreate varchar(1000)
   3: set @tablecreate = 'create table [Accounting_'+convert(varchar,getdate()-1,112)+']
   4: (
   5: Date varchar(500),
   6: IP_Address  varchar(500),
   7: Packets varchar(500),
   8: Out_Bytes varchar(500),
   9: In_Bytes varchar(500)

  10: )'

  11: exec (@tablecreate)
  12: go
  13: 
  14: 
  15: declare @insert_command varchar(MAX)
  16: set @insert_command = 'insert into Accounting_'+convert(varchar,getdate()-1,112)+'
  17:
  18: SELECT *

  19: FROM OPENROWSET('

'Microsoft.Jet.OLEDB.4.0'',
  20: '

'Text;database=\\server\share;HDR=NO'',
  21: '

'SELECT * FROM test4.csv'')'
  22: execute (@insert_command)

 

Some things you might need to know, if you need to use a UNC path like I, then your SQL service must be running under an account that does has network access (unlike the default local system account) .

Also that user that is used as the service account must have permissions to the file via the shares.

Thanks needs to go to Adrian Foyn for a little help with this code.

 

Brad


Jun 3 2008

Configuring the CRM v4 outlook Client Fails

A while ago we rolled out CRM v4, however we only started to roll out the client for V4 only very recently, When trying to roll out the application I was getting an odd error message.

 

“The configuration wizard cannot connect to the Microsoft CRM server. This might indicate that the server is down”

 

The server was clearly not down, as the web interface was fine. It turned out to be a mix of IIS and database related issues.

Lets look at IIS:

if you are running a host header with CRM, simple answer don’t. Use DNS rather then then setting a host header on CRM, this will cause you all sorts of grief (this was explained in a previous post also). Also within regards to the Host header, Also I find not setting a host header will cause problems when installing the client.

So you ask what can I do… easy have a host header of the server name, ensure you are NOT using ALL UNASSIGENED, but use a specific IP (the primary for the adaptor if more then one)

Then do a IISRESET.

So that’s IIS sorted.

So lets look at SQL server.

Now if you are like us we moved our front end server (IIS) a few times, which is fine but the CRM database makes reference to the web server and the port it runs on, so you must change these references also.

Backup your database before using this script.

USE MSCRM_CONFIG
Update DeploymentProperties SET NVarCharColumn = '<serverName>:<port>' WHERE ColumnName = 'AsyncSdkRootDomain'
Update DeploymentProperties SET NvarCharColumn = '<serverName>:<port>' WHERE ColumnName = 'ADSdkRootDomain' 
Update DeploymentProperties SET NvarCharColumn = '<serverName>:<port>' WHERE ColumnName = 'ADWebApplicationRootDomain' 

NOTE: replace the ‘<serverName>:<port>’ with your IIS servername and the Port it runs on. (STD install port for CRM is 5555)


May 28 2008

VISTA: Remote Registry off by default

Just a quick one today, as you probably have worked out the remote registry is turned off by default within windows vista making Sys Admin job’s a little harder to install third party applications through a central location.

I was unable to find a script that would start the service and then create the service as automatic.

whilst the starting the service is easy enough, I wanted the service to be automatic, so that way we only have to run the script on all VISTA machines just once, there is no point running it every time on boot up when  we can avoid slowing the system down a little.

Here is the script (.BAT) it will set the service to automatic (on XP and VISTA)

 

reg import "\\DOMAINCONTROLLER NAME HERE\SYSVOL\DOMAIN\scripts\remotereg.reg"
net start "remote registry"

NOTE: I did not use the delay start because my Group Policy applies to both XP and Vista, this would cause a conflict as the delay start is not an option in XP, I would recommend the delayed start method if you have isolated just your VISTA machines in a group policy

 

Above you can see it is calling a .reg file this is the contents of the reg, copy and save it as a .reg file also

Windows Registry Editor Version 5.00
 
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\RemoteRegistry]
"Start"=dword:00000002
 

May 21 2008

AD Based Outlook Email Signature for 2003 and 2007 Part 3 – Removing the Reply / forward signature

To even further requests for the script to be modified, where the script only add the signature to the new message, rather then the standard of adding to both new message and reply / Forward messages.

If you have run the original script previously  you will have find that just running the new script I am about to paste below is useless and it does not get rid of the reply / Forward. Well that’s because the script has added this into the registry, so we must remove this setting. to do this you can run the below batch file:

reg delete "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\9375CFF0413111d3B88A00104B2A66760000001" /v "Reply-Forward Signature" /f 
reg delete "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\9375CFF0413111d3B88A00104B2A66760000002" /v "Reply-Forward Signature" /f 
reg delete "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\9375CFF0413111d3B88A00104B2A66760000003" /v "Reply-Forward Signature" /f 

copy the above text and save it as a .bat file.

NOTE: for the 2003 users if you look in your registry and you are finding that you don’t have the 3rd registry hive, that’s OK, I have included it for 07 users as well, it will do no harm if you don’t have it.

OK now that you have run the above batch file you can open outlook and you will see you no longer have a reply / forward but you will still have your signature on a new message. So we are half way there, all we need to do is now modify the original script so that the reply / forward is not added to the registry again.

see below:

'====================
'
' VBScript: <Signatures.vbs>
' AUTHOR: Peter Aarts
' Contact Info: peter.aarts@l1.nl
' Version 2.04
' Date: January 20, 2006
' Modified by Brad Marsh on 21 may 08
' added 2007 support and remove reply / forward signatures
' Tested on both 03 and 07 outlook
' contact: gentex@tpg.com.au
'====================
 
'Option Explicit
 
On Error Resume Next
 
Dim qQuery, objSysInfo, objuser
Dim FullName, EMail, Title, PhoneNumber, MobileNumber, FaxNumber, OfficeLocation, Department
Dim web_address, FolderLocation, HTMFileString, StreetAddress, Town, State, Company
Dim ZipCode, PostOfficeBox, UserDataPath
 
 
 
 
' Read LDAP(Active Directory) information to asigns the user's info to variables.
'====================
Set objSysInfo = CreateObject("ADSystemInfo")
objSysInfo.RefreshSchemaCache
qQuery = "LDAP://" & objSysInfo.Username
Set objuser = GetObject(qQuery)
 
FullName = objuser.displayname
EMail = objuser.mail
Company = objuser.Company
Title = objuser.title
PhoneNumber = objuser.TelephoneNumber
FaxNumber = objuser.FaxNumber
OfficeLocation = objuser.physicalDeliveryOfficeName
StreetAddress = objuser.streetaddress
PostofficeBox = objuser.postofficebox
Department = objUser.Department
ZipCode = objuser.postalcode
Town = objuser.l
MobileNumber = objuser.TelephoneMobile
web_address = "http://www.elcom.com.au"
 
' This section creates the signature files names and locations.
'====================
' Corrects Outlook signature folder location. Just to make sure that
' Outlook is using the purposed folder defined with variable : FolderLocation
' Example is based on Dutch version.
' Changing this in a production enviremont might create extra work
' all employees are missing their old signatures
'====================
Dim objShell, RegKey, RegKey07, RegKeyParm
Set objShell = CreateObject("WScript.Shell")
RegKey = "HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Common\General"
RegKey07 = "HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Common\General"
RegKey07 = RegKey07 & "\Signatures"
RegKey = RegKey & "\Signatures"
objShell.RegWrite RegKey , "AD_elcom"
objShell.RegWrite RegKey07 , "AD_elcom"
UserDataPath = ObjShell.ExpandEnvironmentStrings("%appdata%")
FolderLocation = UserDataPath &"\Microsoft\AD_elcom\"
HTMFileString = FolderLocation & "Elcom.htm"
 
' This section disables the change of the signature by the user.
'====================
'objShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Common\MailSettings\NewSignature" , "L1-Handtekening"
'objShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Common\MailSettings\ReplySignature" , "L1-Handtekening"
'objShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook\Options\Mail\EnableLogging" , "0", "REG_DWORD"
 
' This section checks if the signature directory exits and if not creates one.
'====================
Dim objFS1
Set objFS1 = CreateObject("Scripting.FileSystemObject")
If (objFS1.FolderExists(FolderLocation)) Then
Else
Call objFS1.CreateFolder(FolderLocation)
End if
 
' The next section builds the signature file
'====================
Dim objFSO
Dim objFile,afile
Dim aQuote
aQuote = chr(34)
 
' This section builds the HTML file version
'====================
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
' This section deletes to other signatures.
' These signatures are automaticly created by Outlook 2003.
'====================
Set AFile = objFSO.GetFile(Folderlocation&"Elcom.rtf")
aFile.Delete
Set AFile = objFSO.GetFile(Folderlocation&"Elcom.txt")
aFile.Delete
 
Set objFile = objFSO.CreateTextFile(HTMFileString,True)
objFile.Close
Set objFile = objFSO.OpenTextFile(HTMFileString, 2)
 
 
objfile.write "<!DOCTYPE HTML PUBLIC " & aQuote & "-//W3C//DTD HTML 4.0 Transitional//EN" & aQuote & ">" & vbCrLf
objfile.write "<HTML><HEAD><TITLE>Microsoft Office Outlook Signature</TITLE>" & vbCrLf
objfile.write "<META http-equiv=Content-Type content=" & aQuote & "text/html; charset=windows-1252" & aQuote & ">" & vbCrLf
objfile.write "<META content=" & aQuote & "MSHTML 6.00.3790.186" & aQuote & " name=GENERATOR></HEAD>" & vbCrLf
objfile.write "<body>" & vbCrLf
objfile.write "    <head> <style type=text/css>" & vbCrLf
objfile.write "}" & vbCrLf
 
objfile.write "<!DOCTYPE HTML PUBLIC " & aQuote & "-//W3C//DTD HTML 4.0 Transitional//EN" & aQuote & ">" & vbCrLf
objfile.write "<HTML><HEAD><TITLE>Microsoft Office Outlook Signature</TITLE>" & vbCrLf
objfile.wr
ite "<META http-equiv=Content-Type content=" & aQuote & "text/html; charset=windows-1252" & aQuote & ">" & vbCrLf
objfile.write "<META content=" & aQuote & "MSHTML 6.00.3790.186" & aQuote & " name=GENERATOR></HEAD>" & vbCrLf
objfile.write "<body>" & vbCrLf
objfile.write "    <head> <style type=text/css>" & vbCrLf
objfile.write "}" & vbCrLf
 
objfile.write ".style4 {" & vbCrLf
objfile.write "    text-decoration: none;" & vbCrLf
objfile.write "    color: #696969;" & vbCrLf
objfile.write "    font-family: Verdana;" & vbCrLf
objfile.write "}" & vbCrLf
 
objfile.write "</style></head>" & vbCrLf
 
objfile.write "<font color=696969 face=Verdana>" & vbCrLf
objfile.write "<b> <span style='font-size: 10pt;'> "& FullName & "</span> </b> " & vbCrLf
objfile.write "<span style='color: #FF0000;font-size: 10pt;font-weight: bold;'>|</span> " & vbCrLf
objfile.write "<a href=mailto:" & Email &" span style='font-size: 8pt;text-decoration: none;color: #696969;' > <span style='font-size: 8pt;text-decoration: none;color: #696969;'>" & Email &" </span></a>" & vbCrLf
objfile.write "<br>" & vbCrLf
objfile.write "<span style='font-size: 8pt;color: #696969;font-weight: bold;'>" & title & " </span> <br>" & vbCrLf
objfile.write "<br>" & vbCrLf
objfile.write "<span style='font-size: 7.5pt;color: #696969;'>"& Company & " </span>" & vbCrLf
objfile.write "<span style='color: #FF0000; font-size: 7.5pt;'>|</span> <span style='font-size: 7.5pt;color: #696969;'>Australian Technology Park</span> " & vbCrLf
objfile.write "<span style='color: #FF0000; font-size: 7.5pt;'>| </span> " & vbCrLf
objfile.write "<span style='font-size: 7.5pt;color: #696969;'> Sydney </span><br>" & vbCrLf
objfile.write "<span style='color: #FF0000; font-size: 7.5pt;'>t</span><span style='font-size: 7.5pt;color: #696969;'> +612 " & PhoneNumber &"</span><span style='color: #FF0000; font-size: 7.5pt;'>&nbsp;&nbsp;f</span><span style='font-size: 7.5pt;color: #696969;'> +612 9209 4423</span>" & vbCrLf
objfile.write "<span style='color: #FF0000; font-size: 7.5pt;'>| </span>" & vbCrLf
objfile.write "<span style='font-size: 7.5pt;color: #696969;'> <a href=http://www.elcom.com.au><span class=style4>www.elcom.com.au</a></span> </span><br>" & vbCrLf
objfile.write "<br>" & vbCrLf
objfile.write "<A href=http://www.elcom.com.au/> <img src=http://www.elcom.com.au/images/elcom-logo-web-175x70.gif height=70 width=175 border=0></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" & vbCrLf
objfile.write "<img src=http://www.elcom.com.au/images/mspartner.gif height=55 width=265><br>" & vbCrLf
objfile.write "<br>" & vbCrLf
objfile.write "<span style='font-size: 7.5pt;color: #696969;'>Please consider </span><span style='font-size: 7.5pt;color: #00b050;'>our environment</span><span style='font-size: 7.5pt;color: #696969;'> before printing this email.</span></font><font color=696969 size=1 face=Verdana><br> " & vbCrLf
objfile.write "<hr size=1 font align=left width=465 color=696969><span style='font-size: 7.5pt;color: #696969;'>This email is intended for the intended recipients(s) and may contain confidential information. <br> Reproduction, dissemination or distribution of this message is prohibited unless authorised by the sender.<br> If you are not the intended recipient, please notify the sender immediately and you must not read,<br> keep, use, disclose, copy or distribute this email without the sender's prior permission.<br> The views expressed by the sender are not necessarily those of Elcom Technology Pty Ltd</font></span></font>" & vbCrLf
 
objFile.Close
' ===========================
' This section readsout the current Outlook profile and then sets the name of the default Signature
' ===========================
' Use this version to set all accounts
' in the default mail profile
' to use a previously created signature
 
Call SetDefaultSignature("Elcom","")
 
' Use this version (and comment the other) to
' modify a named profile.
'Call SetDefaultSignature _
' ("Signature Name", "Profile Name")
 
Sub SetDefaultSignature(strSigName, strProfile)
Const HKEY_CURRENT_USER = &H80000001
strComputer = "."
 
If Not IsOutlookRunning Then
Set objreg = GetObject("winmgmts:" & _
"{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
strKeyPath = "Software\Microsoft\Windows NT\" & _
"CurrentVersion\Windows " & _
"Messaging Subsystem\Profiles\"
' get default profile name if none specified
If strProfile = "" Then
objreg.GetStringValue HKEY_CURRENT_USER, _
strKeyPath, "DefaultProfile", strProfile
End If
' build array from signature name
myArray = StringToByteArray(strSigName, True)
strKeyPath = strKeyPath & strProfile & _
"\9375CFF0413111d3B88A00104B2A6676"
objreg.EnumKey HKEY_CURRENT_USER, strKeyPath, _
arrProfileKeys
For Each subkey In arrProfileKeys
strsubkeypath = strKeyPath & "\" & subkey
objreg.SetBinaryValue HKEY_CURRENT_USER, _
strsubkeypath, "New Signature", myArray
Next
 
'strMsg1 = "Completed Signature Sucssefully"
'MsgBox strMsg1
 
Else
strMsg = "Please shut down Outlook before " & _
"running this script."
MsgBox strMsg, vbExclamation, "SetDefaultSignature"
End If
End Sub
 
Function IsOutlookRunning()
strComputer = "."
strQuery = "Select * from Win32_Process " & _
"Where Name = 'Outlook.exe'"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery(strQuery)
For Each objProcess In colProcesses
If UCase(objProcess.Name) = "OUTLOOK.EXE" Then
IsOutlookRunning = True
Else
IsOutlookRunning = False
End If
Next
End Function
 
Public Function StringToByteArray _
(Data, NeedNullTerminator)
Dim strAll
strAll = StringToHex4(Data)
If NeedNullTerminator Then
strAll = strAll & "0000"
End If
intLen = Len(strAll) \ 2
ReDim arr(intLen - 1)
For i = 1 To Len(strAll) \ 2
arr(i - 1) = CByte _
("&H" & Mid(strAll, (2 * i) - 1, 2))
Next
StringToByteArray = arr
End Function
 
Public Function StringToHex4(Data)
' Input: normal text
' Output: four-character string for each character,
' e.g. "3204" for lower-case Russian B,
' "6500" for ASCII e
' Output: correct characters
' needs to reverse order of bytes from 0432
Dim strAll
For i = 1 To Len(Data)
' get the four-character hex for each character
strChar = Mid(Data, i, 1)
strTemp = Right("00" & Hex(AscW(strChar)), 4)
strAll = strAll & Right(strTemp, 2) & Left(strTemp, 2)
Next
StringToHex4 = strAll
 
 
End Function

 

that’s it you can re-run the above script, of course modify the HTML and other parts to suite you (see here how to change the script)and you should have only signatures on a new message permanently.

 

Enjoy.


May 19 2008

Vista Activation: 0×8007232B – DNS name does not exist

If you have installed a Volume licence version on Vista business / Enterprise, you may get the below error message when trying to active the product

clip_image002

a pretty useless error message, but it does have a very easy fix, simply go to computer and then ‘change Product Key’ enter in the same product key that you had previously used for the VISTA installation.

That’s it it should activate within seconds.


May 15 2008

Show all Full Text Index’s in MSSQL

I looked long and hard for something that would query all databases on a MS SQL server where it would display all of the full Text Indexes. However there is really not that much I could find. However I came across this query

sp_msforeachdb ‘use [?] exec sp_help_fulltext_catalogs’

 

we all know that the SP_msforeachdb has the ability to query all databases on the server, then we combine that with:

exec sp_help_fulltext_catalogs’

which shows us

image

As you can see it only shows you for the database selected nothing more.

if you run the below query by itself then you will are unable to see the results in any clear manner, especially if you need to export them to a CSV or alike (like I needed to do)

sp_msforeachdb ‘use [?] exec sp_help_fulltext_catalogs’

image

 

So I got one of our brilliant Developers Adrian Foyn, do something where we can use this data into a readable format.

So he create a temp table against the master database, then we save the results to the table, then query and drop  the table

 

create table mytemp
(
FT_ID varchar(500),
FT_NAME varchar(500),
FT_PATH varchar(500),
DB_Name varchar(500),
col5 varchar(500)
)
go
sp_msforeachdb ‘use [?];insert into master..mytemp exec sp_help_fulltext_catalogs; update master..mytemp set DB_Name = ”?” where DB_Name=”0”’
go
select    *
from    mytemp
go
drop table mytemp

 

this will also show the database name which corresponds to the FT index.

 

works brilliantly.

Thanks Adrian.


May 14 2008

AD Based Outlook Email Signature for 2003 and 2007 Continued – Implementation Guide

earlier on in the year I blogged about AD based signatures for 2003 and 2007 outlook (find the post here), It seems I am not the only person that needs this, I have been getting rather high stats on this topic and a few questions.

So I thought I would go through a little more in detail in terms of what you have to modify and how you would go about implementing the script into an AD based environment.

Ok So lets start with the script and what you need to modify. I will highlight in RED what needs to change

NOTE: DO NOT COPY AND PASTE THE BELOW SCRIPT IT WILL NOT WORK, as there are various comments to show you what you need to change. Please refer to the previous post which has the original code, which you should copy, paste and modify.

 

‘====================

‘ VBScript: <Signatures.vbs>
‘ AUTHOR: Peter Aarts
‘ Contact Info: peter.aarts@l1.nl
‘ Version 2.04
‘ Date: January 20, 2006
‘ Moddified By Brad Marsh Now works with both 2003 and 2007 outlook
‘ Contact: gentex@tpg.com.au
‘ Date 19 feb 08
‘ Tested on Vista, XP, XP64 and office 2003 and 2007.
‘ NOTE will not work that well with various email accounts
‘====================

‘Option Explicit
On Error Resume Next

Dim qQuery, objSysInfo, objuser
Dim FullName, EMail, Title, PhoneNumber, MobileNumber, FaxNumber, OfficeLocation, Department
Dim web_address, FolderLocation, HTMFileString, StreetAddress, Town, State, Company
Dim ZipCode, PostOfficeBox, UserDataPath

‘ Read LDAP(Active Directory) information to asigns the user’s info to variables.
‘====================
Set objSysInfo = CreateObject(“ADSystemInfo”)
objSysInfo.RefreshSchemaCache
qQuery = “LDAP://” & objSysInfo.Username
Set objuser = GetObject(qQuery)

FullName = objuser.displayname
EMail = objuser.mail
Company = objuser.Company
Title = objuser.title
PhoneNumber = objuser.TelephoneNumber
FaxNumber = objuser.FaxNumber
OfficeLocation = objuser.physicalDeliveryOfficeName
StreetAddress = objuser.streetaddress
PostofficeBox = objuser.postofficebox
Department = objUser.Department
ZipCode = objuser.postalcode
Town = objuser.l
MobileNumber = objuser.TelephoneMobile
web_address = http://www.elcom.com.au”  — Change this to your web address

‘ This section creates the signature files names and locations.
‘====================
‘ Corrects Outlook signature folder location. Just to make sure that
‘ Outlook is using the purposed folder defined with variable : FolderLocation
‘ Example is based on Dutch version.
‘ Changing this in a production enviremont might create extra work
‘ all employees are missing their old signatures
‘====================
Dim objShell, RegKey, RegKey07, RegKeyParm
Set objShell = CreateObject(“WScript.Shell”)
RegKey = “HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Common\General”
RegKey07 = “HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Common\General”
RegKey07 = RegKey07 & “\Signatures”
RegKey = RegKey & “\Signatures”
objShell.RegWrite RegKey , “AD_elcom” — Change this to what you would like the regitsry key to specify

objShell.RegWrite RegKey07 , “AD_elcom”– Change this to what you would like the regitsry key to specify

UserDataPath = ObjShell.ExpandEnvironmentStrings(“%appdata%”)
FolderLocation = UserDataPath &”\Microsoft\AD_elcom\” – Change this to your desired path
HTMFileString = FolderLocation & “Elcom.htm” — change this to your desired file name

‘ This section disables the change of the signature by the user. AND HAS BEEN COMMENTED OUT, uncommented it at your risk
‘====================
‘objShell.RegWrite “HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Common\MailSettings\NewSignature” , “L1-Handtekening” — change this to your desired setting (note I did not use these settings they were commented out

‘objShell.RegWrite “HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Common\MailSettings\ReplySignature” , “L1-Handtekening” — change this to your desired setting (note I did not use these settings they were commented out

‘objShell.RegWrite “HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook\Options\Mail\EnableLogging” , “0″, “REG_DWORD”

‘ This section checks if the signature directory exits and if not creates one.
‘====================
Dim objFS1
Set objFS1 = CreateObject(“Scripting.FileSystemObject”)
If (objFS1.FolderExists(FolderLocation)) Then
Else
Call objFS1.CreateFolder(FolderLocation)
End if

‘ The next section builds the signature file
‘====================
Dim objFSO
Dim objFile,afile
Dim aQuote
aQuote = chr(34)

‘ This section builds the HTML file version
‘====================
Set objFSO = CreateObject(“Scripting.FileSystemObject”)

‘ This section deletes to other signatures.
‘ These signatures are automaticly created by Outlook 2003.
‘====================
Set AFile = objFSO.GetFile(Folderlocation&”Elcom.rtf”)
aFile.Delete
Set AFile = objFSO.GetFile(Folderlocation&”Elcom.txt”)
aFile.Delete

Set objFile = objFSO.CreateTextFile(HTMFileString,True)
objFile.Close
Set objFile = objFSO.OpenTextFile(HTMFileString, 2)

 

– HERE WE ARE STARTING HOW THE HTML LOOKS –

NOTES:
always start a new line of code with objfile.write “
Close every line with ” & vbCrLf

the rest is simple HTML, you will need to change this to suite your requirements

–start of HTML  Body Started, you can copy this–

objfile.write “<!DOCTYPE HTML PUBLIC ” & aQuote & “-//W3C//DTD HTML 4.0 Transitional//EN” & aQuote & “>” & vbCrLf
objfile.write “<HTML><HEAD><TITLE>Microsoft Office Outlook Signature</TITLE>” & vbCrLf
objfile.write “<META http-equiv=Content-Type content=” & aQuote & “text/html; charset=windows-1252″ & aQuote & “>” & vbCrLf
objfile.write “<META content=” & aQuote & “MSHTML 6.00.3790.186″ & aQuote & ” name=GENERATOR></HEAD>” & vbCrLf
objfile.write “<body>” & vbCrLf

– Start of Style and open and close of head, you can copy this you may want to change the style a little –

objfile.write “    <head> <style type=text/css>” & vbCrLf
objfile.write “}” & vbCrLf
objfile.write “.style4 {” & vbCrLf
objfile.write “    text-decoration: none;” & vbCrLf
objfile.write “    color: #696969;” & vbCrLf
objfile.write “    font-family: Verdana;” & vbCrLf
objfile.write “}” & vbCrLf
objfile.write “</style></head>” & vbCrLf

 

–Start of the actual Signature, CHANGE this, however make sure you keep the Variables in tack, just more them to suite you variables in this signature are and should look like below when inserted into the HTML:

“& FullName &”
“& EMail &”
“& Company &”
“& Title &”
“& PhoneNumber &”
“& FaxNumber &
amp;”
“& OfficeLocation &”
“& StreetAddress &”
“& PostofficeBox &”
“& Department &”
“& ZipCode &”
“& Town &”
“& MobileNumber &”
“& web_address &”

I will highlight them red so you can see where they actully are used within the HTML, I did not use all of the variables listed above.

 

 

objfile.write “<font color=696969 face=Verdana>” & vbCrLf
objfile.write “<b> <span style=’font-size: 10pt;’> “& FullName & “</span> </b> ” & vbCrLf
objfile.write “<span style=’color: #FF0000;font-size: 10pt;font-weight: bold;’>|</span> ” & vbCrLf
objfile.write “<a href=mailto:” & Email &” span style=’font-size: 8pt;text-decoration: none;color: #696969;’ > <span style=’font-size: 8pt;text-decoration: none;color: #696969;’>” & Email &” </span></a>” & vbCrLf
objfile.write “<br>” & vbCrLf
objfile.write “<span style=’font-size: 8pt;color: #696969;font-weight: bold;’>” & title & ” </span> <br>” & vbCrLf
objfile.write “<br>” & vbCrLf
objfile.write “<span style=’font-size: 7.5pt;color: #696969;’>“& Company & ” </span>” & vbCrLf
objfile.write “<span style=’color: #FF0000; font-size: 7.5pt;’>|</span> <span style=’font-size: 7.5pt;color: #696969;’>Australian Technology Park</span> ” & vbCrLf
objfile.write “<span style=’color: #FF0000; font-size: 7.5pt;’>| </span> ” & vbCrLf
objfile.write “<span style=’font-size: 7.5pt;color: #696969;’> Sydney </span><br>” & vbCrLf
objfile.write “<span style=’color: #FF0000; font-size: 7.5pt;’>t</span><span style=’font-size: 7.5pt;color: #696969;’> +612 ” & PhoneNumber &”</span><span style=’color: #FF0000; font-size: 7.5pt;’>&nbsp;&nbsp;f</span><span style=’font-size: 7.5pt;color: #696969;’> +612 9209 4423</span>” & vbCrLf
objfile.write “<span style=’color: #FF0000; font-size: 7.5pt;’>| </span>” & vbCrLf
objfile.write “<span style=’font-size: 7.5pt;color: #696969;’> <a href=http://www.elcom.com.au><span class=style4>www.elcom.com.au</a></span> </span><br>” & vbCrLf
objfile.write “<br>” & vbCrLf
objfile.write “<A href=http://www.elcom.com.au/> <img src=http://www.elcom.com.au/images/elcom-logo-web-175×70.gif height=70 width=175 border=0></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;” & vbCrLf
objfile.write “<img src=http://www.elcom.com.au/images/mspartner.jpg height=55 width=265><br>” & vbCrLf
objfile.write “<br>” & vbCrLf
objfile.write “<span style=’font-size: 7.5pt;color: #696969;’>Please consider </span><span style=’font-size: 7.5pt;color: #00b050;’>our environment</span><span style=’font-size: 7.5pt;color: #696969;’> before printing this email.</span></font><font color=696969 size=1 face=Verdana><br> ” & vbCrLf
objfile.write “<hr size=1 font align=left width=465 color=696969><span style=’font-size: 7.5pt;color: #696969;’>This email is intended for the intended recipients(s) and may contain confidential information. <br> Reproduction, dissemination or distribution of this message is prohibited unless authorised by the sender.<br> If you are not the intended recipient, please notify the sender immediately and you must not read,<br> keep, use, disclose, copy or distribute this email without the sender’s prior permission.<br> The views expressed by the sender are not necessarily those of Elcom Technology Pty Ltd</font></span></font>” & vbCrLf

objFile.Close

 

–END OF HTML–

 

‘ ===========================
‘ This section readsout the current Outlook profile and then sets the name of the default Signature
‘ ===========================
‘ Use this version to set all accounts
‘ in the default mail profile
‘ to use a previously created signature

Call SetDefaultSignature(“Elcom“,”")  — this appears in the outlook file as the signature name, change it to desired

‘ Use this version (and comment the other) to
‘ modify a named profile.
‘Call SetDefaultSignature _
‘ (“Signature Name”, “Profile Name”)

Sub SetDefaultSignature(strSigName, strProfile)
Const HKEY_CURRENT_USER = &H80000001
strComputer = “.”

If Not IsOutlookRunning Then
Set objreg = GetObject(“winmgmts:” & _
“{impersonationLevel=impersonate}!\\” & _
strComputer & “\root\default:StdRegProv”)
strKeyPath = “Software\Microsoft\Windows NT\” & _
“CurrentVersion\Windows ” & _
“Messaging Subsystem\Profiles\”
‘ get default profile name if none specified
If strProfile = “” Then
objreg.GetStringValue HKEY_CURRENT_USER, _
strKeyPath, “DefaultProfile”, strProfile
End If
‘ build array from signature name
myArray = StringToByteArray(strSigName, True)
strKeyPath = strKeyPath & strProfile & _
“\9375CFF0413111d3B88A00104B2A6676″
objreg.EnumKey HKEY_CURRENT_USER, strKeyPath, _
arrProfileKeys
For Each subkey In arrProfileKeys
strsubkeypath = strKeyPath & “\” & subkey
objreg.SetBinaryValue HKEY_CURRENT_USER, _
strsubkeypath, “New Signature”, myArray
objreg.SetBinaryValue HKEY_CURRENT_USER, _
strsubkeypath, “Reply-Forward Signature”, myArray
Next
Else
strMsg = “Please shut down Outlook before ” & _
“running this script.” – this is the message when error occurs, change it to desired.


MsgBox strMsg, vbExclamation, “SetDefaultSignature”
End If
End Sub

Function IsOutlookRunning()
strComputer = “.”
strQuery = “Select * from Win32_Process ” & _
“Where Name = ‘Outlook.exe’”
Set objWMIService = GetObject(“winmgmts:” _
& “{impersonationLevel=impersonate}!\\” _
& strComputer & “\root\cimv2″)
Set colProcesses = objWMIService.ExecQuery(strQuery)
For Each objProcess In colProcesses
If UCase(objProcess.Name) = “OUTLOOK.EXE” Then
IsOutlookRunning = True
Else
IsOutlookRunning = False
End If
Next
End Function

Public Function StringToByteArray _
(Data, NeedNullTerminator)
Dim strAll
strAll = StringToHex4(Data)
If NeedNullTerminator Then
strAll = strAll & “0000″
End If
intLen = Len(strAll) \ 2
ReDim arr(intLen – 1)
For i = 1 To Len(strAll) \ 2
arr(i – 1) = CByte _
(“&H” & Mid(strAll, (2 * i) – 1, 2))
Next
StringToByteArray = arr
End Function

Public Function StringToHex4(Data)
‘ Input: normal text
‘ Output: four-character string for each character,
‘ e.g. “3204″ for lower-case Russian B,
‘ “6500″ for ASCII e
‘ Output: correct characters
‘ needs to reverse order of bytes from 0432
Dim strAll
For i = 1 To Len(Data)
‘ get the four-character hex for each character
strChar = Mid(Data, i, 1)
strTemp = Right(“00″ & Hex(AscW(strChar)), 4)
strAll = strAll & Right(strTemp, 2) & Left(strTemp, 2)
Next
StringToHex4 = strAll

End Function

 

Ok that’s the end of the code

Now on to how to implement it into AD.

First this is first, copy your .vbs to one of the domain controllers, We generally put
scripts in the following location (we do this so that the scripts are replicated through our AD servers, if you have multiple AD server I recommend putting it in the same place.

\\computername\SYSVOL\domain name\scripts\

You will need to ensure all your users that you are applying this to have the required fields complemented with in AD remember your variables, these are what you will need filled in (or at least what you use within the signature)

“& FullName &”
“& EMail &”
“& Company &”
“& Title &”
“& PhoneNumber &”
“& FaxNumber &”
“& OfficeLocation &”
“& StreetAddress &”
“& PostofficeBox &”
“& Department &”
“& ZipCode &”
“& Town &”
“& MobileNumber &”
“& web_address &”

 

Now you to the users that you are applying this script to you must have a GROUP POLICY that is applied to those users, if not create one, or just use the default domain policy.

open up that group policy you wish to apply this VBS to and then within the Group Policy Editor choose:

User configuration
  Windows Settings
      Scripts (logon/logoff)
          Logon

double click on logon, you will see the below screen, you may not have anything in it just yet though, to add the location go to ‘Add’ and then simply browse to the location of the VBS. I am using a logon.bat because we have various logon scripts we execute, so we have complied it into just the one batch file that opens and executes all scripts.

image

 

Once you have added the file press OK.

That’s more or less all you need to do, however you might want to test it to do this you may want to force the GP to refresh

at the command line type ‘gpupdate /force’

then log off and then on, open outlook and test.

 

For any 2007 users if you find that after you run the script and then you or a user opens outlook after login and they revive the error message that from teh script saying that outlook is open, well there is a way around that too.

Go to your Group Policy management again

this time go to

User configuration
  Administrative Templates
      System/Scripts
          Run logo Scripts Scnchronously

Enable this!

image

 

If you are unsure about this, below is the description of what it is you are enabling

 

image

 

Hopefully this helps a few more people.

Good luck!


May 9 2008

Installing JSP on Windows Server 2003

I once had to do this and I found this rather hard to actually get working 100%, there are many guides on the net but nothing that would work 100% for me so I did wrote a guide some time ago, hopefully this can help one else out. The website that I performed this write on comprised of JSP and SHTML.

 

Required Installs / files

IIS 6.0

Java 2

Tomcat 5.5

Perl

MySQL

MySQL Administrator

MySQL J Connector

 

Install MySQL and MySQL Administrator, make sure that you have also imported the required databases, do not change any naming for the databases, as the JSP code refers directly to the  DB name.

First Step is to install you IIS server

Adding the Application Server Role to Windows Server 2003
When you start your server, you should see the Manage Your Server wizard. If you don’t display this by default, you can go to Administrative Tools and click on Manage Your Server. When the wizard opens, click on Add or Remove a Role.
clip_image001
Click Next and let the server detect your settings, then choose Custom Configuration and click Next, then choose the Application Server role and click Next This should bring you to the Application Server Options screen of the wizard.

clip_image002

At this point we want to choose ASP.NET, just in case later there is a need for it, the Front Page extensions are not required.

click Next to set up the role. The process may ask you for the Server 2003 CD and will take several minutes to complete. Just let it run until you see the Finish button, then click Finish.

Your IIS 6.0 is now installed, be sure to test this before moving on

Installing Java

Step 1.  Install the JRE
Install the JRE and choose a custom installation which will allow you to change the installation directory to D:\java (or leave it as the default C:\program files\Java if you prefer)
clip_image003
Fig.1 Installing the JRE
clip_image004
Fig.2 Select a Custom Installation
clip_image005
Fig.3 Choose the target Installation Directory
clip_image006
Fig.4 Installation Complete
Once this is done you need to set a system environment variable which will enable Tomcat to compile JSP pages at runtime. To do this right-click the My Computer icon, select properties and then the Advanced tab. Then click Environment Variables and under System variables click New
clip_image007
Fig.5  Setting the Environment Variable
Then add a new system variable with the name of JAVA_HOME and a value of D:\Java (or whichever directory you specified for your Java installation)
clip_image008
Fig.6  Setting the Java Environment Variable
Tomcat 5.5 also requires a system environment variable to be set so lets go ahead and do that whilst we are here. The Tomcat variable is called CATALINA_HOME and needs to be a system variable which points to the root of your Tomcat installation directory. In this example I am going to install Tomcat into D:\Tomcat so I set the variable accordingly
clip_image009
Fig.7  Setting the Tomcat Environment Variable

Installing Tomcat 5.5
Now we begin the installation of Tomcat itself.
clip_image010
Fig. 8 Tomcat Setup Dialog
Launch the installer, agree to the licensing and then select Full Install. Selecting either a full or custom install will give you the Examples and Webapps which will allow you to test your Tomcat installation to ensure everything is working properly.
clip_image011
Fig.9 Select a Full Installation Type
At the Choose Install Location dialog box, click browse and select your preferred directory. In this example I am going to install into D:\Tomcat (again you may use the default if you wish C:\Program Files\Apache Software Foundation\Tomcat 5.5)
clip_image012
Fig.10 Choosing the Installation Location
Next you need to select the HTTP/1.1 Connector Port, which is the port the Tomcat service itself will actually be listening on. Provided nothing else on your server is using this port then leaving it set to the default of 8080 is fine. (this is what I have used)
You also then need to select a user name and password for your Tomcat admin account.

clip_image013
Fig.11 Configuring the Tomcat Connector port and Administrator password
The Tomcat installation should find your default Java installation directory, if not then direct it accordingly. Click Install and you should soon have a working installation of Tomcat !
clip_image015
Fig.12 Configuring the JVM path

Once you installation has finished Go to the windows services, you will see that the installation has added a new service called Apache Tomcat which should be set to start automatically, if not do this. Also the service will normally use the local system for logging on, change this to the administrator user and password of the server. Tomcat also provides an interface where this can be achieved, however I found this to give me nothing but problems, stick to the windows services.
clip_image017
Fig. 14 The Apache Tomcat service
Now we need to test our installation and make sure that Tomcat is working, to view the tomcat welcome page in the browser type: localhost:8080, at this point you should see the default welcome page for Apache Tomcat
clip_image018
Fig. 15 The Default Tomcat page.
Also you can also test the examples or sample applications which you installed earlier by pointing your browser to either http://localhost:8080/jsp-examples/ or http://localhost:8080/servlets-examples/ I recommending doing this, as a double check to make sure the tomcat is communicating with all of the other ‘web apps’

clip_image019
Fig. 16 Browsing the samples using Tomcat directly
Now we need to create the website as a web app to so we can browse the JSP side of the  website, the required files can also be found in the install folder, copy the website folder and then go to you Tomcat installation folder, within the install folder you will have a folder called ‘Web Apps’ go into this folder in there you will find several folders such as jsp-examples, servlet-examples and a few others, paste you website folder in the root of the Web Apps folder.

So that’s the first part done. You now have Tomcat installed and working on a Windows 2003 Server machine. Next, we need to configure IIS to accept requests on behalf of Tomcat on port 80

Installing and Configuring the Tomcat JK2.0.4 Connector for IIS
The Tomcat connector is an ISAPI filter which allows IIS to handle requests for Java pages or applications and passes them off to Tomcat for processing.

Here we start by browsing to the installs\tomcat directory, in there you will find ‘setupJk204.exe’ this is how we setup the ISAPI filter within IIS.

clip_image021

Fig.17 Starting the ISAPI redirector

After pressing next it will ask you to agree, do this and then you will be presented with a screen where you are able to choose you web applications you want IIS and Tomcat to talk to

clip_image023

Fig.18 choosing the web app we want the filter to run

Make sure you choose your website, the other can be chosen if you like, once you are happy with you selections then choose Install.

Once we have installed this go back into the IIS and the make sure that that the ISAPI filter has been installed and is allowed.

clip_image025

Figure.19 as you can see the ISAPI filter is installed ‘Jakarta Isapi Redirector’

More Configuring IIS
There are a few steps which need to be completed in order to get Tomcat to work with IIS6,
We need to create a virtual directory for the Tomcat connector to use, however before this we need to add the website, so create a new site call it what ever you like, and then add the website directorty which in my case was found E:\Websites\xxxxxxx\xxxxxxx\xxxxx, once this has been created we now can create a Virtual Directory, call it what ever you wish (I called mine Jakarta), the next part asks for a path we need to find the path of the ISAPI filter, if you have installed tomcat to the default location you will find it: C:\Program Files\Apache Software Foundation\Tomcat 5.5\native\i386

clip_image027

Figure.20 Enter the location of the ISAPI filter.

Next, be sure to give the Virtual Directory READ, RUN Scripts and EXECUTE permissions

clip_image029

Figure.21 the permissions that are required

Create the Tomcat Application Pool
In IIS Manager and right-click Application Pools. Click New, Application Pool. Select a name for your new application pool and use the default settings to create the new pool. You should now see your new application pool in the list. Once you do go back to the  website and give this website the new application pool, also make sure that all other Virtual directory inherit this App Pool.

Check the ISAPI

Click on the properties of the website, and go to ISAPI filters, and check that you filter has appeared, if it is not there add it by navigating to the location of it (default location: C:\Program Files\Apache Software Foundation\Tomcat 5.5\native\i386).

clip_image031

Figure.22 the ISAPI filter is in place

Installing Pearl

Ok now that we have tomcat working, we need to do a few more things for the whole site to function properly, so we are now insdtalling perl, again you will find this install in the \install directory, just install this anywhere you wish. This is a simple Next, next process.

clip_image033

Figure.23 open
the pl ext

Once this is complete, you will see that pearl has added some required IIS extensions, however one of the required extension is missing, so we need to add it Double click on the .pl Ext and then copy the Executable path, then press cancel to the .pl ext, and choose the add button and paste the path into the ‘Executable’

And type

.cgi

Then press ok.

clip_image035

Figure.24 adding the CGI ext

Final Step

Installing the MySQL J connector

Navigate to E:\Installs\MySQL\mysql-connector-java-3.1.14 in this folder you will find serval .JAR files we are interested in the ‘mysql-connector-java-3.1.14-bin.jar’ copy this file.

We now need to paste this in 2 locations

  1. C:\Program Files\Java\jre1.5.0_01\lib\ext (this is the default installation folder for Java, choose the according folder that is right for you)
  2. C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\WEBSITE\WEB-INF\lib (again this the default installation path for tomcat, make sure you change yours accordingly)

Now you are done!!!

Test your site.


May 8 2008

Vista / 2008: Unable to move file into Command Line Window

I am sure anyone that uses command line has at some point pulled a file from a active window into a command line, this way you don’t have to type the path, and lets face it some of those paths are horrendously long.

If you have Vista or 2008 Server you will have noted that you no longer have this function, and from doming some reading on this some time ago there is quite an up roar about it, rightfully so I say!

I and many others I know use this functionality on a very regular basis. I was looking high and low  and just could not find anything, however today I stumbled across some way to do this, not exactly the same but its still a huge help

When you right click on a folder you get the following:

 

image

 

BUT hold down SHIFT and then right click on the folder

image

Notice the 2 new items within the list:

‘Open Command Window Here’

Which will do this:

image

And

‘Copy as Path’

You wont see but when pressing paste or CTRL + V it will reveal the path, which in my case is:

“C:\Drivers\audio”

 

the open command line is a big help, but this can only be used at the folder level if you try and do this on the file (eg .exe .bat .vbs) you will no longer have this option, however you will have the copy as path, this can be chosen and then paste this into your command line and then enter…

 

No more typing the full path again.