Script Editors

I see a lot of people asking about script editors for vbScript and Powershell.

If you want free then I would suggest the following:

 Notepad Plus is a good replacement for Notepad.

http://notepad-plus.sourceforge.net/uk/site.htm

Here are the features of Notepad++ :

Syntax Highlighting and Syntax Folding

    Supported languages :
        C C++ Java C# XML HTML
        PHP CSS makefile ASCII art (.nfo) doxygen ini file
        batch file Javascript ASP VB/VBS SQL Objective-C
        RC resource file Pascal Perl Python Lua TeX
        TCL Assembler Ruby Lisp Scheme Properties
        Diff Smalltalk Postscript VHDL Ada Caml
        AutoIt KiXtart Matlab Verilog Haskell InnoSetup
        CMake YAML
    WYSIWYG 
    User Defined Syntax Highlighting 
    Auto-completion 
    Multi-Document 
    Multi-View 
    Regular Expression Search/Replace supported 
    Full Drag ‘N’ Drop supported 
    Dynamic position of Views 
    File Status Auto-detection 
    Zoom in and zoom out 
    Multi-Language environment supported 
    Bookmark 
    Brace and Indent guideline Highlighting 
    Macro recording and playback 

Or you could go with Sapiens PrimalPad:

 SAPIEN Technologies has released a new FREE (for personal use) portable editor called PrimalPad.
With PrimalPad you can edit PowerShell, VBScript, JScript and HTML files.
The editor also support multi-tabbed environment, line numbers and color coding.
The editor is a single EXE file, no need to install anything, just double click it and start editing your scripts.
PrimalPad is available as x32 and x64 versions and can be downloaded HERE (registration needed).
 

If you are only working in Powershell then:

 the Power Gui from PowerGui.org is a good choice and it’s free:

http://powergui.org/index.jspa

 For a few dollars more;

Try EditPlus

http://www.editplus.com/register.html

I like it because it lets me work in columns and it will find and replace tabs and line feeds.
It supports the basic scripting languages, but last I looked it did not directly support Powershell.
1-user license:   US  $35
 

One just for vbScript is vbsEdit;

 http://www.vbsedit.com/

This does amazing things in vbScript, including showing you all the functions and methods
available when you open up a com object. I really like this feature when I am scripting Excel.
VbsEdit  Single-user license for $49.00

 

Of course if you want the very best and are willing to pay for it then you must buy Primal Script.

Price: $299.00
 
I won’t go into details, but if scripting is you job, then this is the one for you.

Open Command Window Here

I ran across this article (Open Command Window Here « Burgaud.com) about adding the Open Command Line Here to the Right Click menu in Explorer.

It’s a good article and it shows you how to do the job with some registry hacks.

I have included my versions here:

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOTDirectoryshellrunas]
@="Open Command Window Here"
[HKEY_CLASSES_ROOTDirectoryshellrunascommand]
@="cmd.exe /k pushd %L"

[HKEY_CLASSES_ROOTDirectoryshellCommandPrompt]
@="Open Command Window Here"
[HKEY_CLASSES_ROOTDirectoryshellCommandPromptcommand]
@="cmd.exe /k pushd %L"
[HKEY_CLASSES_ROOTDriveshellCommandPrompt]
@="Open Command Window Here"
[HKEY_CLASSES_ROOTDriveshellCommandPromptcommand]
@="cmd.exe /k pushd %L"

Just copy the above and save it to a regfile. I call mine open_cmd_here.reg

Then open up explorer and double click the file. It will ask you if you want to add this to your registry,

say yes and then close Explorer. Next time you open Explorer and right click on a Directory, you will have two options.

1. open a command prompt as an admin

2. as a regular user.

And here is one to add Powershell:

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOTDirectoryshellpowershell]
@="PowerShell Here"
[HKEY_CLASSES_ROOTDirectoryshellpowershellcommand]
@="C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -NoExit -Command Set-Location -LiteralPath ‘%L’"

 

 

 

Open Command Window Here « Burgaud.com

Powershell InStr() and Mid()


First of all, PowerShell does not have an InStr() or Mid() function, at least version one does not.
I was trying to extract the Group name from the Common Name in AD and I wanted
everything between the first = sign and the first “,” comma. (I know there are other ways)
So I found that in Powershell you can get the first position of a character by using indexof() like so:

$a=$path
$b = $a.indexof("="     # so the first = is at character 9
 

I don’t want the equal sign so I add 1

$b = $b + 1

Next I get the index of the first comma.

$c = $a.indexof(",")

Then I get the number of characters between $c and $b

$d = $c - $b
 

Finally I get the substring I wanted:
The substring starts at the first character, in this case $b and then includes
the number of characters in your substring, in this case $d. 

$e = $a.substring($b,$d)
 

And here is my MID function:

Function MID($path) {
$a=$path
$b = $a.indexof("=")
$b = $b + 1
$c = $a.indexof(",")
$d = $c - $b
$e = $a.substring($b,$d)
$ws.Cells.Item($row,4) = $e      #This puts my substring in an Excel Spreadsheet in column 4
}
 

Error trapping and EXE’s in vbScript

I was asked to make up a menu for some connection testing.
Many of the machines that are being tested are Windows XP and many of the testers
are using XP.
 
I found that Net View works differently on XP than it does on Vista,
So I had to come up with a way to determine if the C$ share was available
on either XP or Vista machines and from either a Vista or XP machine.
 
I attempt to map to the test machine’s C$ share and record the results in a text file.
I then read the file and pull out the error code.
 
Here is the function:
 
Function View(strComputer)
On Error Resume Next
Const OpenAsDefault = -2
    Const FailIfNotExist =  0
    Const ForReading =  1
    Set oShell = CreateObject("WScript.Shell")
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    sTemp = oShell.ExpandEnvironmentStrings("%TEMP%")
    sTempFile = sTemp & "runresult.tmp"
    oShell.Run "%comspec% /c net use Z: \" & strComputer & "C$ " & ">" & sTempFile & " 2>&1", 0 , True
  
   Set fFile = oFSO.OpenTextFile(sTempFile, ForReading, _
                                       FailIfNotExist, OpenAsDefault)
     sResults = fFile.ReadAll
     fFile.Close
oShell.Run "%comspec% /c net use Z: /Delete >" & sTempFile & " 2>&1", 0 , True   
   
oFSO.DeleteFile(sTempFile)
     If CBool(InStr(sResults, "successfully."))then    
      statval.value = strComputer & " C$ Is Available"
     ElseIf CBool(InStr(sResults, "2")) Then
      statval.value = strComputer & " File not found"
     ElseIf CBool(InStr(sResults, "3")) Then
      statval.value = strComputer & " Path not found."
     ElseIf CBool(InStr(sResults, "4")) Then
      statval.value = strComputer & " Too many files open."
     ElseIf CBool(InStr(sResults, "5")) Then
      statval.value = strComputer & " Access denied."
     Else
   statval.value = statval.value & VbCrLf & strComputer & " C$ Is Not Shared"
     End If
‘   DOS 2=File not found.
‘   DOS 3=Path not found.
‘   DOS 4=Too many files open.
‘   DOS 5=Access denied. 
 
End Function
 
The 2>&1  puts the standard error in the standard out pipe so everything is in one file.
Oh and the function is part of an HTA which is why it writes out to statval.value.
You might recognize the construction from Alex K. Angelopoulos great ping function.
 

Adding Color to Excel the Powershell Way


Want to add a little color to your spreadsheets?
This will show you how and create a sample spreadsheet with the 56 colors available to you.


###### Start Posh Script ########

$xl = new-object -comobject excel.application 
$xl.Visible = $true 
$xl.DisplayAlerts = $False
$wb = $xl.Workbooks.Add() 
$ws = $wb.Worksheets.Item(1) 
$row = 1 
$i = 1
For($i = 1; $i -lt 56; $i++){ 
 $ws.Cells.Item($row, 1) = "'$'ws.Cells.Item($row, 2).Font.ColorIndex = " + $row #<-- row 10 
 $ws.Cells.Item($row, 2).Font.ColorIndex = $row 
 $ws.Cells.Item($row, 2) = "test " + $row 
 $row++ 
}
[void]$ws.cells.entireColumn.Autofit()

############# End POSH Script ###############

Try taking the ‘ out from around the $ in row 10 and see what you get..
Be sure you do if you want to just cut and paste the cell.