Sunday, October 08, 2006

Insert Code from Live Writer Gallery

 

Below is a sample of a code paste into the "Insert Code" module from Omar Shahine.  As you can see it dies a nice jobe of formatting VBS code. 

 Two issues here:

1.  Code is not contained in a wrappable DIV the same as the Steve Dunn attempt.

2. Inserted HTML does not limit itself.  All future formatting is set to the last style set either before the insert or after.

While this is trivial and cosmetic it would be best if it were fixed.  I also found that running into the top of the block and accideentally deletin the opening tag will remove all formatting.

The code cannot be limited via scroll bars which is needed to limit the display area of the code in the blog entry.

Again - it would be nice to have a link that would paste the raw code to the clipboard so it sould be copied.

This code formatter cannot be easily changed by editing the HTML and adding a DIV wrapper due ti the use of PRE etc.  It took a painful amount of time to force the formatted code into the hand coded DIV.  Steve Dunn's formatter is already in a DIV and only requires the insertion of a style or adding a class tag.  This formatter can't display it's style when inside the DIV although it does show the formatiing when in Live Writer.

Both formatters are a good start.  A couple of fixes and both would be excellent additions to Live Writer.

Suggestion: Use external style sheet global to weblog. 

'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 3.1
'
' NAME: 
'
' AUTHOR: James Vierra , Designed Systems & Services
' DATE  : 5/18/2005
'
' COMMENT: 
'
'==========================================================================

on Error Resume Next

Dim strComputer, strInput
Dim sProgram, sProgram2, sProgram3
Dim objFS, objXL, objTS
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

intRow = 3
Set objXL = WScript.CreateObject("Excel.Application")
Set objShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

sProgram = UCASE("Adobe")
sProgram2 = UCASE("Reader")
sProgram3 = UCASE("Update")

Call CollectInput()
Call BuildSpreadSheet()

Set objTS = objFS.OpenTextFile(strInput)

Do Until objTS.AtEndOfStream
  strComputer = objTS.ReadLine

'strComputer = Array("OMEGA")
For Each strComputer In objTS  
WScript.echo strComputer
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32Reg_AddRemovePrograms", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)

For Each objItem In colItems
sString = UCase(objItem.DisplayName)
sFound = InStr(sString, sProgram)

If sFound > 0 Then
sFound2 = InStr(sString, sProgram2)
sFound3 = InStr(sString, sProgram3)
If sFound2 = 0 and sFound3 = 0 Then

objXL.Cells(intRow, 1) = UCase (strComputer)
    objXL.Cells(intRow, 2) = objItem.DisplayName
    objXL.Cells(intRow, 3) = objItem.Version
    intRow = intRow + 1
     End If
   End if
  Next
 Next
Loop 

Sub CollectInput()
    Dim intDoIt

Welcome_MsgBox_Message_Text = "This script will collect Adobe Acrobat Versions (*NOT READER*) Installed on Computers."
Welcome_MsgBox_Title_Text = "Collecting Adobe Acrobat Versions"

    intDoIt =  MsgBox(Welcome_MsgBox_Message_Text, _
                      vbOKCancel + vbInformation,    _
                      Welcome_MsgBox_Title_Text )
    If intDoIt = vbCancel Then
        WScript.Quit
      End If
    
    strInput = InputBox ("Enter the TextFile for input? ")

If strInput = "" Then
   WScript.Echo "No FileName provided, The Script will Terminate"
   WScript.Quit
    End If
End Sub

Sub BuildSpreadSheet()

    objXL.Visible = True
    objXL.WorkBooks.Add()
    objXL.Sheets("Sheet1").Select()
    objXL.Sheets("Sheet1").Name = "Adobe Acrobat Inventory"
    objXL.Sheets("Sheet2").Select()
    objXL.ActiveWindow.SelectedSheets.Delete
    objXL.Sheets("Sheet3").Select()
    objXL.ActiveWindow.SelectedSheets.Delete
    objXL.Caption = "Collecting Adobe Acrobat Inventory"
    
    objXL.Rows(1).RowHeight = 30

    objXL.Columns(1).ColumnWidth = 30
    objXL.Columns(2).ColumnWidth = 30
    objXL.Columns(3).ColumnWidth = 30

    objXL.Range("A1:C1").Select
    objXL.Selection.Font.Bold = True
    objXL.Selection.Interior.ColorIndex = 11
    objXL.Selection.Interior.Pattern = 1 'xlSolid
    objXL.Selection.Font.ColorIndex = 2
    objXL.Selection.WrapText = True
    objXL.Selection.HorizontalAlignment = 3 'xlCenter
        
    objXL.Cells(1, 1).Value = "Computer"
    objXL.Cells(1, 2).Value = "Program Name"
    objXL.Cells(1, 3).Value = "Program Version"
    
End Sub





 

Wednesday, October 04, 2006

Redmond | Column: Intelligent Transfer

 Don Jones column this month is very useful started for BITS download automation.  Read it here: Intelligent Transfer

I compiled some resources for anyone interested in going further.  I have also added a link the teh Resouce Kit which containds the BitsAdmin Tool.

BITS Extensions:  Remember that BITS can do uploads too.  BITS is manageble via AD.  BITS is fully accessible with dotNET and PowerShell.

Resources:

BitsAdmin is here:   Windows XP Service Pack 2 Support Tools

BitsAdmin Tool Help: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/bits/bits/bitsadmin_tool.asp

Coding Examples: http://www.microsoft.com/downloads/details.aspx?FamilyID=874cde91-e95f-47df-9c75-778f63a4f5cf&DisplayLang=en

BITS 2.0 Home Page: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/bits/bits/bits_start_page.asp

Scripting: <undocumented at Microsoft> <coming>

Tuesday, October 03, 2006

Live Writer - Steve Dunn's Code Formatter

Here is an example of the Live Writer PlugIn from Steve Dunn.  As you can see I have added height and width restrictions to the DIV style alongwith a "autoflow:auto ".  This causes the scrollbars to be turned on whenever the textflow exceeds the DIV size.  Adding these choices to the control by retrieveing the heghth and width of the formatter control and allowing a checkbox to turn on scrollbars would make this Writer AddIn awesome.

1 Option Explicit 2 Const ForReading = 1 3 Const ForAppending = 8 4 Const sLogFileName = "d:\log.txt" 5 Const sServerFileName = "d:\servers.txt" 6 'On Error Resume Next 7 Dim objDictionary, objFSO, objOU, objComputer, strComputer 8 Dim colNetcards, objWMIService, objNetcard, arrWINSServers 9 Dim i, objItem, sName, objTextFile, strNextLine 10 11 Set objDictionary = CreateObject("Scripting.Dictionary") 12 Set objFSO = CreateObject("Scripting.FileSystemObject") 13 Set objTextFile = objFSO.OpenTextFile(sServerFileName, ForReading) 14 i = 0 15 Do Until objTextFile.AtEndOfStream 16 strNextLine = objTextFile.Readline 17 objDictionary.Add i, strNextLine 18 i = i + 1 19 Loop 20 objTextFile.close 21 22 Dim oLogFile 23 Set oLogFile = objFSO.OpenTextFile(sLogFileName, ForAppending) 24 For Each objItem in objDictionary 25 26 StrComputer = objDictionary.Item(objItem) 27 WScript.Echo "Begin pinging:" & strComputer 28 If TestPing(strComputer) = False Then 29 WScript.Echo now() & " Couldn't reach " & strComputer 30 oLogFile.WriteLine now() & " Couldn't reach " & strComputer 31 Else 32 WScript.Echo "Ping successful!" 33 Set objWMIService = GetObject("winmgmts:\\" & strComputer& "\root\cimv2") 34 Set colNetCards = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = TRUE AND NOT Description LIKE '%ISCSI'") 35 For Each objNetCard In colNetcards 36 WScript.Echo objNetCard.Description 37 arrWINSServers = Array("Null", "Null") 38 'objNetCard.SetWINSServerSearchOrder(arrWINSServers) 39 Next 40 End If 41 42 Next 43 44 oLogFile.Writeline "" 45 oLogFile.Close 46 WScript.echo "Script Finished" 47 48 Function TestPing(sName) 49 TestPing = false 50 If sName = "" Then 51 WScript.Echo "Bad computer name string!" 52 else 53 Dim cPingResults, oPingResult 54 Set cPingResults = GetObject("winmgmts://./root/cimv2").ExecQuery("SELECT * FROM Win32_PingStatus WHERE Address = '" & sName & "'") 55 For Each oPingResult In cPingResults 56 If oPingResult.StatusCode = 0 Then 57 TestPing = True 58 End If 59 Next 60 End if 61 End Function 62 63

Live Writer - Steve Dunn's Code Formatter

Here is an example of the Live Writer PlugIn from Steve Dunn.  As you can see it does not add scrollbars or truncate lines within the control as could be expected. 

The formatting is excellent for this example although the control is sluggish in Writer due to screen paints not be suppressed during the scroll.  This seems to be an artifact of the control itself. Once the control is de-selected the scroll problems go away. Sometimes, when the control is highlighted,  The insertion point gets stuck in the control and the UI becomes completely unresponsive.

I like the formatter an hope that it will improve with time.

Notice that the lines are rendered across the whole page outside of the controls area. The control needs to contain everything inside of a DIV and allow styling  to turn on the scroll bars.  This would allow the code to be viewed without annoying linewraps.  It would also allow it to be copied and pasted without errors.

1 Option Explicit
2 Const ForReading = 1
3 Const ForAppending = 8
4 Const sLogFileName = "d:\log.txt"
5 Const sServerFileName = "d:\servers.txt"
6 'On Error Resume Next
7 Dim objDictionary, objFSO, objOU, objComputer, strComputer
8 Dim colNetcards, objWMIService, objNetcard, arrWINSServers
9 Dim i, objItem, sName, objTextFile, strNextLine
10
11 Set objDictionary = CreateObject("Scripting.Dictionary")
12 Set objFSO = CreateObject("Scripting.FileSystemObject")
13 Set objTextFile = objFSO.OpenTextFile(sServerFileName, ForReading)
14 i = 0
15 Do Until objTextFile.AtEndOfStream
16 strNextLine = objTextFile.Readline
17 objDictionary.Add i, strNextLine
18 i = i + 1
19 Loop
20 objTextFile.close
21
22 Dim oLogFile
23 Set oLogFile = objFSO.OpenTextFile(sLogFileName, ForAppending)
24 For Each objItem in objDictionary
25
26 StrComputer = objDictionary.Item(objItem)
27 WScript.Echo "Begin pinging:" & strComputer
28 If TestPing(strComputer) = False Then
29 WScript.Echo now() & " Couldn't reach " & strComputer
30 oLogFile.WriteLine now() & " Couldn't reach " & strComputer
31 Else
32 WScript.Echo "Ping successful!"
33 Set objWMIService = GetObject("winmgmts:\\" & strComputer& "\root\cimv2")
34 Set colNetCards = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = TRUE AND NOT Description LIKE '%ISCSI'")
35 For Each objNetCard In colNetcards
36 WScript.Echo objNetCard.Description
37 arrWINSServers = Array("Null", "Null")
38 'objNetCard.SetWINSServerSearchOrder(arrWINSServers)
39 Next
40 End If
41
42 Next
43
44 oLogFile.Writeline ""
45 oLogFile.Close
46 WScript.echo "Script Finished"
47
48 Function TestPing(sName)
49 TestPing = false
50 If sName = "" Then
51 WScript.Echo "Bad computer name string!"
52 else
53 Dim cPingResults, oPingResult
54 Set cPingResults = GetObject("winmgmts://./root/cimv2").ExecQuery("SELECT * FROM Win32_PingStatus WHERE Address = '" & sName & "'")
55 For Each oPingResult In cPingResults
56 If oPingResult.StatusCode = 0 Then
57 TestPing = True
58 End If
59 Next
60 End if
61 End Function
62
63