4/16/2008

vbscript to check each line in a file if there are included keywords defined in another file


Dim objSourceFile, objKeywordFile, objNewFile, objFSO
Dim currentline, currentvariable, bIncluded

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objSourceFile = objFSO.OpenTextFile("D:\sourcefile.txt")
Set objKeywordFile = objFSO.OpenTextFile("D:\keywordfile.txt")
Set objNewFile = objFSO.CreateTextFile("D:\result.txt")
bIncluded = False


Do While Not objSourceFile.AtEndOfStream
currentline = objSourceFile.ReadLine
Call CheckIfIncluded
Loop



Function CheckIfIncluded

Do While Not objKeywordFile.AtEndOfStream
currentvariable = objKeywordFile.ReadLine

If InStr(currentline,currentvariable) Then
bIncluded = False
Exit Do
Else
bIncluded = True
End If
Loop
If bIncluded = True Then
objNewFile.WriteLine currentline
End If
Set objKeywordFile = Nothing
Set objKeywordFile = objFSO.OpenTextFile("D:\variablefile.txt")

End Function

3/18/2008

Unattended installation of a single Office 2007 Language Pack (MUI)

1. Copy the MUI language pack sources into your office source folder (do not replace available items)
2. In the OMUI.XX-YY folder for the specific language customize the config.xml as listed below:

3. Install the Language with the following command, where the setup.exe is the original from the office 2007 source, not from the language pack.

\\server\office\setup.exe /config \\server\office\omui.xx-yy\config.xml

3/02/2008

Office 2007: Automatically restore custom.dic

The next file to restore automatically, when migrating to Office 2007 is the custom.dic file. It contains all user self-defined words.
The Problem is that the directory for .dic files changes in Office 2007. So the following Script can be implemented in your Logon Script.
It creates the neccesary folder UProof, which is only available when Word is started the first time and then copies all .dic files from the old directory into the new UProof folder.

'Restore Custom.dic
Option Explicit

dim objFSO, objShell, objFile, objFolder
dim AppData
dim OldProofPath, NewProofPath


Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject( "WScript.Shell" )

AppData = objShell.ExpandEnvironmentStrings("%APPDATA%")

OldProofPath = Appdata &"\Microsoft\Proof\"
NewProofPath = Appdata &"\Microsoft\UProof"


'*********************************************************************************************'
'First create Folder if the folder doesn't exists
If Not objFSO.FolderExists (NewProofPath) Then
objFSO.CreateFolder NewProofPath
End If
'*********************************************************************************************'

'*********************************************************************************************'
Set objFolder = objFSO.GetFolder(OldProofPath)
'If source folder does not exists...dont copy'
If objFSO.FolderExists(OldProofPath) Then
For Each objFile In objFolder.Files
'Copy all files with DIC extension'
If Right(objFile.Name,3) = "DIC" Then
objFile.Copy NewProofPath & "\" & objFile.Name
End If
Next
End If
'*********************************************************************************************'

Set objFile = Nothing
Set objFSO = Nothing
Set objFolder = Nothing

3/01/2008

Office 2007: Automatically restore AutoText entries from normal.dot

As you maybe know, there seems to be no possibility to automatically restore AutoText entries from previous Office versions to Office 2007.
Microsoft released a Workaround how to restore the AutoText entries from your normal.dot to Office 2007.
The trick is to copy the old normal.dot into one of the following folders:
%APPDATA%\Microsoft\Document Building Blocks\{Language ID}
or
%APPDATA%\Microsoft\Word\STARTUP
See also Microsoft article: http://technet2.microsoft.com/Office/en-us/library/ca7d3d97-6970-45c6-9b05-6a64cf1fbe711033.mspx?mfr=true

I see two problems in this Workaround:
1. I don't trust the STARTUP folder when i only wanna restore the AutoText entries, so i prefer the Document Building Blocks\{Language ID} folder
2. If you want to copy the normal.dot automatically for example with your Logon Script to this folder when the user logs on the first time, you can't copy the file, because the folder Document Building Blocks\{Language ID} only exists when Word is started the first time.

So....i wrote a script, which can be added to your Logonscript
The Script first creates the required folder and then copies the file!


'Restore AutoText entries from normal.dot
Option Explicit

dim objFSO, objShell
dim AppData
dim OldTemplatePath, NewTemplatePath, OldTemplate, NewTemplate
dim LanguageID

LanguageID = "1033"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject( "WScript.Shell" )

AppData = objShell.ExpandEnvironmentStrings("%APPDATA%")

'*********************************************************************************************'
'First create Folder if Word was not started yet'
If Not objFSO.FolderExists (AppData &"\Microsoft\Document Building Blocks\" &LanguageID) Then
objFSO.CreateFolder AppData &"\Microsoft\Document Building Blocks\"
objFSO.CreateFolder AppData &"\Microsoft\Document Building Blocks\" &LanguageID
End If
'*********************************************************************************************'

'*********************************************************************************************'
'Define office template paths here'
'OldTemplate = "normal10.dot" 'If languages match the file is renamed (OfficeXP)
'OldTemplate = "normal11.dot" 'If languages match the file is renamed (Office2003)
OldTemplate = "Normal.dot"
NewTemplate = "AutoText.dot"

'OldTemplatePath = AppData &"\Microsoft\Vorlagen\" german folder
OldTemplatePath = AppData &"\Microsoft\Templates\"

'NewTemplatePath = AppData &"\Microsoft\Word\STARTUP\"
NewTemplatePath = AppData &"\Microsoft\Document Building Blocks\" &LanguageID &"\"
'*********************************************************************************************'


'*********************************************************************************************'
'Determine if the old template exists'
If objFSO.FileExists(OldTemplatePath &OldTemplate) then
'Determine if the new template already exists'
If Not objFSO.FileExists(NewTemplatePath &OldTemplate) then
objFSO.CopyFile OldTemplatePath &OldTemplate, NewTemplatePath &NewTemplate
End If
End If
'*********************************************************************************************'

2/29/2008

vbscript for backup all event logs and delete them afterwards

Option Explicit
dim strComputer
dim objWMIService
dim colLogFiles
dim objLogfile
dim errBackupLog

strComputer = "." 'IP Address or Name
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate,(Backup)}!\\" & strComputer & "\root\cimv2")

Call eventlogbackup("Application")
Call eventlogbackup("System")
Call eventlogbackup("Security")
'Call eventlogbackup("DNS Server") Define further logs here

Function eventlogbackup(logtype)
Set colLogFiles = objWMIService.ExecQuery ("SELECT * FROM Win32_NTEventLogFile WHERE LogFileName='" &logtype &"'")
For Each objLogfile in colLogFiles
errBackupLog = objLogFile.BackupEventLog("\\server\eventlogs\" &strComputer &"\" &logtype &".evt")
If errBackupLog <> 0 Then
Wscript.Echo "The " &logtype &" event log could not be backed up."
Else
objLogFile.ClearEventLog()
Wscript.Echo "The " &logtype &" event log is backed up."
End If
Next
End Function

2/28/2008

vbscript to check if a computer is available

Option Explicit
dim objPing
dim objStatus
dim strComputer

strComputer="." 'IP Address or Name
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
ExecQuery("select Replysize from Win32_PingStatus where address = '" & strComputer & "'")

For Each objStatus in objPing
If IsNull(objStatus.ReplySize) Then
WScript.Echo "computer is offline"
'...
Else
WScript.Echo "computer is online"
'...
End If
Next

Set objPing=Nothing
Set objStatus=Nothing


What's this blog for?

welcome to my blog :)
in this blog i'll publish some technical information regarding my daily work as IT consultant.
Mainly this posts will treat the following themes:
- scripting (vbscript, vb, vba & windows scripting host, ...)
- windows (deployment, automation, 2k3, 2k8, xp & vista, ...)
- office (deployment, 2k7, ...)
- servers (sms, sql, sccm, isa, iis, ias,...)
- in summary: the daily IT doing

so come in soon...