Saturday, September 02, 2017

EMACS Basic



To run script C-c C-x
C-f Move forward a character
C-b Move backward a character

M-f Move forward a word
M-b Move backward a word

C-n Move to next line
C-p Move to previous line

C-a Move to beginning of line
C-e Move to end of line

M-a Move back to beginning of sentence
M-e Move forward to end of sentence

M-< Go to beginning of file
M-> Go to end of file




QUIT -> C-x C-c
SEARCH -> M-x regex. C-s (C-r for reverse)( Type C-s and then word. Now type C-s agin to step through it)
UNDO -> C-x u
NEW / OPEN FILE -> C-x C-f test.emacs RET
SAVE FILE -> C-x C-s  C-x C-w C-x s


SHOW Line and column number -> M-x line-number-mode   M-x column-number-mode

YANKING
Paste: C-y
Paste the paste M-y


MULTI WINDOWS
C-x 1, C-x 2


DEBUG Emac
emacs —debug-init
M-x goto-char 
 M-x list-packages to list all package in emacs

To get documentation on your current major mode, type C-h m.



Mark a Region

C-Space C-Space
Now use arrow key to block the region and then use command to act on block.
Eg Use C-x TAB to indent

Mail in Emacs

C-x m
Begin composing mail (compose-mail).
C-x 4 m
Likewise, in another window (compose-mail-other-window).
C-x 5 m
Likewise, but in a new frame (compose-mail-other-frame).
C-c C-s
In the mail buffer, send the message (message-send).
C-c C-c
In the mail buffer, send the message and bury the buffer (message-send-and-exit).


Docker Swarm


Docker Swarm creation

docker-machine create --driver virtualbox manager1 ( Driver can be hyperv)
docker-machine create --driver virtualbox manager1
docker-machine create --driver virtualbox worker1
docker-machine create --driver virtualbox worker2
docker-machine create --driver virtualbox worker3
docker-machine create --driver virtualbox worker4
docker-machine create --driver virtualbox worker5

docker-machine ls docker-machine ls 
docker-machine ip manager1
docker-machine ssh manager1

From inside manager1 do init of swarm
docker swarm init --advertise-addr MANAGER_IP
docker node ls

Now get the token for worker joining in manager.
docker swarm join-token worker
docker swarm join-token manager

To join worker1 to manager ssh into worker1 in a new terminal 
docker-machine ssh worker1
docker swarm join --token SWMTKN-1-69hfhzjl83310rnx2b4t07qxmmi1xmgjkg5def1spotpiwki-dg29ra0thuptzmux2jq7brn1g 192.168.99.100:2377   (This is token from docker swarm join-token worker)
Continue with all workers

Now in manager do 
docker info
docker node ls


Create a Service
Now that we have our swarm up and running, it is time to schedule our containers on it. This is the whole beauty of the orchestration layer. We are going to focus on the app and not worry about where the application is going to run.
All we are going to do is tell the manager to run the containers for us and it will take care of scheduling out the containers, sending the commands to the nodes and distributing it.

To start a service, you would need to have the following:
  • What is the Docker image that you want to run. In our case, we will run the standard nginx image that is officially available from the Docker hub.
  • We will expose our service on port 80.
  • We can specify the number of containers (or instances) to launch. This is specified via the replicas parameter.
  • We will decide on the name for our service. And keep that handy.
What I am going to do then is to launch 5 replicas of the nginx container. To do that, I am again in the SSH session for my manager1 node. And I give the following docker service create command:


docker service create --replicas 5 -p 80:80 --name web nginx
docker service ls
docker service ps web
docker ps
docker service inspect --pretty web

To scale up the service use below command
docker service scale web=8

Checking:
docker service inspect --pretty web
docker node inspect manager1 --format "{{ .ManagerStatus.Reachability }}"
docker node inspect worker1 --format "{{ .Status.State }}"


Drain:
docker node update --availability drain worker5
docker node update —availability active worker5




To leave (stop) a node go to manager node and issue below command
docker node demote worker5
docker node rm --force worker5  (This has to be done after sometime from previous command)

Before you forcefully remove a manager node, you must first demote it to the worker role. Make sure that you always have an odd number of manager nodes if you demote or remove a manager.





Docker Container commands:
docker container ls
docker container stop
docker container rm
docker container rm image







Tuesday, September 23, 2014

Get opts in Python

import sys
import os
from java.lang import System

import getopt

def usage():
print "Usage:"
print "createJMSModule [-n] -u user -c credential -h host -p port -s serverName -m moduleName [-d subDeploymentName] -j jmsServerName"

try:
opts, args = getopt.getopt(sys.argv[1:], "nu:c:h:p:s:m:d:j:",
["user=", "credential=", "host=", "port=",
"targetServerName=", "moduleName=",
"subDeploymentName=", "jmsServerName="])
except getopt.GetoptError, err:
print str(err)
usage()
sys.exit(2)

reallyDoIt = true
user = ''
credential = ''
host = ''
port = ''
targetServerName = ''
moduleName = ''
subDeploymentName = 'DeployToJMSServer'
jmsServerName = ''

for opt, arg in opts:
if opt == "-n":
reallyDoIt = false
elif opt == "-u":
user = arg
elif opt == "-c":
credential = arg
elif opt == "-h":
host = arg
elif opt == "-p":
port = arg
elif opt == "-s":
targetServerName = arg
elif opt == "-m":
moduleName = arg
elif opt == "-d":
subDeploymentName = arg
elif opt == "-j":
jmsServerName = arg

if user == "":
print "Missing \"-u user\" parameter."
usage()
sys.exit(2)
elif credential == "":
print "Missing \"-c credential\" parameter."
usage()
sys.exit(2)
elif host == "":
print "Missing \"-h host\" parameter."
usage()
sys.exit(2)
elif port == "":
print "Missing \"-p port\" parameter."
usage()
sys.exit(2)
elif targetServerName == "":
print "Missing \"-s serverName\" parameter."
usage()
sys.exit(2)
elif moduleName == "":
print "Missing \"-m moduleName\" parameter."
usage()
sys.exit(2)
elif jmsServerName == "":
print "Missing \"-j jmsServerName\" parameter."
usage()
sys.exit(2)

print "Got all the required parameters"

Saturday, December 29, 2012

Bulk Rename of files in Windows

You can rename files in windows with following command. Below command changes MOD extension of file to MPEG extension. It changes all the extensions even in subdirectories.

for /f "delims=*" %a in ('dir *.MOD /b /s') do ren "%a" *.MPEG

Saturday, June 19, 2010

Some good links to Powershell

Good reading
http://www.techotopia.com/index.php/Using_COM_with_Windows_PowerShell

http://www.youdidwhatwithtsql.com/automating-internet-explorer-with-powershell/467
http://www.pvle.be/2009/06/web-ui-automationtest-using-powershell/
http://powershell.com/Mastering-PowerShell.pdf

Active Directory
http://blogs.technet.com/b/benp/archive/2007/04/10/creating-an-ad-shell.aspx
http://blogs.technet.com/b/benp/archive/2007/03/26/searching-the-active-directory-with-powershell.aspx

http://blogs.technet.com/b/benp/archive/2007/03/05/benp-s-basic-guide-to-managing-active-directory-objects-with-powershell.aspx

Good book to download
http://blogs.technet.com/b/chitpro-de/archive/2008/02/28/free-windows-powershell-workbook-server-administration.aspx

RAM Count : Poweshell

RAM in MB
$mem = Get-WmiObject -Class Win32_ComputerSystem
# Display memory
"This system has {0} MB Free Memory" -f $($mem.TotalPhysicalMemory/1mb)
Processor cOUNT
$system = Get-WmiObject -Class Win32_ComputerSystem

Non Working devices
Get-WmiObject Win32_PNPEntity | where {$_.ConfigManagerErrorcode -ne 0}

Friday, June 18, 2010

Determine whether a computer is a tower, a mini-tower, a laptop, and so on: Powershell

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colChassis = objWMIService.ExecQuery _
("Select * from Win32_SystemEnclosure")
For Each objChassis in colChassis
For Each objItem in objChassis.ChassisTypes
Wscript.Echo "Chassis Type: " & objItem
Next
Next

Right way to read a file in itration. Powershell

Foreach ($name in (Get-Content c:\names.txt))
{
# do something with $name
}

Service Pack in OS. Powershell

Get-WmiObject Win32_OperatingSystem |
Format-List BuildNumber,CSName,ServicePackMajorVersion

UPTIME of server in powershell

UPTIME
$myobj.uptime = (Get-Date) - [System.DateTime]::ParseExact($OSInfo.LastBootUpTime.Split(".")[0],'yyyyMMddHHmmss',$null)
$myobj.uptime = "$($myobj.uptime.Days) days, $($myobj.uptime.Hours) hours," +`
" $($myobj.uptime.Minutes) minutes, $($myobj.uptime.Seconds) seconds"

Adding data to database with Powershell

DaTA base: Add data
$ds = new-object System.Data.DataSet
$ds.Tables.Add("person")
[void]$ds.Tables["person"].Columns.Add("name",[string])
[void]$ds.Tables["person"].Columns.Add("last",[string])
$dr = $ds.Tables["person"].NewRow()
$dr["name"] = "ullas"
$dr["last"] = "t"
$ds.Tables["person"].Rows.Add($dr)
$dr

name last
---- ----
ullas t

Try Catch template for Powershell

Try Catch template
try
{
try
{
# Command that uses -erroraction stop or $erroractionpreference = 'Stop'
}
# Here we catch the Exception generated by the ErrorAction "Stop"
# Only necessary if there is any processing we want to do if the
# exception is of type ActionPreferenceStopExecution,
# otherwise this block can be deleted
catch [System.Management.Automation.ActionPreferenceStopException]
{
# Error Handling specific to ActionPreferenceStopException goes here
# Rethrow the "real" exception as a terminating error
Throw $_.exception
}
# All errors are caught and rethrown to the outer try/catch block
# as terminating errors to be handled.
catch
{
Throw $_.exception
}
}
# Here we can resume exception type handling as usual
catch #[System.Management.Automation.ItemNotFoundException]
{
"Got it!"
}

WMI Info on Excel

$strComputer = “.”

$Excel = New-Object -Com Excel.Application
$Excel.visible = $True
$Excel = $Excel.Workbooks.Add()

$Sheet = $Excel.WorkSheets.Item(1)
$Sheet.Cells.Item(1,1) = “Computer”
$Sheet.Cells.Item(1,2) = “Drive Letter”
$Sheet.Cells.Item(1,3) = “Description”
$Sheet.Cells.Item(1,4) = “FileSystem”
$Sheet.Cells.Item(1,5) = “Size in GB”
$Sheet.Cells.Item(1,6) = “Free Space in GB”

$WorkBook = $Sheet.UsedRange
$WorkBook.Interior.ColorIndex = 8
$WorkBook.Font.ColorIndex = 11
$WorkBook.Font.Bold = $True

$intRow = 2
$colItems = Get-wmiObject -class “Win32_LogicalDisk” -namespace “root\CIMV2? `
-computername $strComputer

foreach ($objItem in $colItems) {
$Sheet.Cells.Item($intRow,1) = $objItem.SystemName
$Sheet.Cells.Item($intRow,2) = $objItem.DeviceID
$Sheet.Cells.Item($intRow,3) = $objItem.Description
$Sheet.Cells.Item($intRow,4) = $objItem.FileSystem
$Sheet.Cells.Item($intRow,5) = $objItem.Size / 1GB
$Sheet.Cells.Item($intRow,6) = $objItem.FreeSpace / 1GB

$intRow = $intRow + 1

}
$WorkBook.EntireColumn.AutoFit()
Clear

Sunday, May 30, 2010

Sample of Powershell usage for displaying in IE

$oIE=new-object -com internetexplorer.application
$oIE.navigate2("About:blank")
while ($oIE.busy) {
    sleep -milliseconds 50
}
$oIE.visible=$true
$procList=ps |select-object ProcessName,Handles,NPM,PM,WS,VM,CPU,Id |convertto-html

$oDocBody=$oIE.document.documentelement.lastchild ;

#populate the document.body
$oDocBody.innerhtml=$procList 

$oDocBody.style.font="12pt Arial";
$oIE.document.bgcolor="#D7D7EA"

#Reading back from IE.
$oTBody=@($oIE.document.getElementsByTagName("TBODY"))[0] ;
foreach ($oRow in $oTBody.childNodes) 
{
   #check the 4 column(WS),and highlight it if it is greater than 5MB.
   $WS=(@($oRow.childNodes)[4].innerhtml) -as [int]  ;
   if (($ws -ne $null) -and ($WS -ge 5mb)) {
       $oRow.bgColor="#AAAAAA" ;
   }
}

#Prepare a title.

$oTitle=$oIE.document.createElement("P")
$oTitle.style.font="bold 20pt Arial"
$oTitle.innerhtml="Process List";
$oTitle.align="center" ;

#Display the title before the Table object.
$oTable=@($oIE.document.getElementsByTagName("TABLE"))[0] ;
$oDocBody.insertBefore($oTitle,$oTable) > $null;

A sample of IE automation with power shell

 
# Twitter login name or email
$username_or_email = "xxxxxxxxxxxxxxxx";
# Your twitter password
$password = "xxxxxxxxxxxx";
$url = "http://twitter.com/login";
 
# txt file containing 1 tweet per line
$tweets = Get-Content "$env:USERPROFILE\tweets.txt";
#Interval between tweets
$sleep = 60; 
 
# This is just an attempt to handle the situation where you are already logged into twitter
trap [Exception]
{
 # This will happen if you're already logged in
 if($_.Exception.Message -eq "Property 'value' cannot be found on this object; make sure it exists and is settable." -Or $_.Exception.Message -eq "You cannot call a method on a null-valued expression.")
 {
  # Try and skip this error
  continue;
 }
 else
 {
  # Fail for other Exceptions
  Write-Host -ForegroundColor Red $_.Exception.Message;
 }
}
 
# Create an ie com object
$ie = New-Object -com internetexplorer.application;
$ie.visible = $true;
$ie.navigate($url);
# Wait for the page to load
while ($ie.Busy -eq $true)
{
 Start-Sleep -Milliseconds 1000;
}
 
# Login to twitter
Write-Host -ForegroundColor Green "Attempting to login to Twitter.";
# Add login details
$ie.Document.getElementById("username_or_email").value = $username_or_email;
$ie.Document.getElementById("session[password]").value = $password;
# Click the submit button
$ie.Document.getElementById("signin_submit").Click();
# Wait for the page to load
while ($ie.Busy -eq $true)
{
 Start-Sleep -Milliseconds 1000;
}
 
# Loop through each tweet in the txt file
foreach($tweet in $tweets)
{
 $ie.Document.getElementById("status").value = $tweet;
 $ie.Document.getElementById("status_update_form").Submit();
 Write-Host -ForegroundColor Green "Tweeted; $tweet.";
 Start-Sleep -Seconds $sleep;
 # Check to see if ie is still busy and sleep if so
 while ($ie.Busy -eq $true)
 {
  Start-Sleep -Milliseconds 1000;
 }
}

Template for IE automation with PowerShell

<#
    .SYNOPSIS 
      Validates application login userid and password from a given excel sheet
    .EXAMPLE
     validateLogin users.xls
     This command picks userid and password from given excel sheets and validates from given URL
#>
#Set-PSDebug -trace 2 # Debug Information
#Set-PSDebug -step # Debug using stepping


if ($args) 
{
 throw "USAGE: validateLogin users.xls"
}

function openExcel($args)
{
 $xl = new-object -com Excel.Application
 foreach ( $wbk in $args )
 {
  foreach ($user in $users)
  {
   $xl.Workbooks.open($args) | out-null  #drop the object info output
   $xl.Cells.Item(1,1).Value()
   $xl.Cells.Item(3,3).Value()
   $xl.Cells.Item(6,8).Value()
   $xl.Workbooks.Close()
  }
 }
}


Function NavigateTo([string] $url, [int] $delayTime = 100)
{
  Write-Verbose "Navigating to $url"
  
  $global:ie.Navigate($url)
  
  WaitForPage $delayTime
}

Function WaitForPage([int] $delayTime = 100)
{
  $loaded = $false
  
  while ($loaded -eq $false) {
    [System.Threading.Thread]::Sleep($delayTime) 
    
    #If the browser is not busy, the page is loaded
    if (-not $global:ie.Busy)
    {
      $loaded = $true
    }
  }
  
  $global:doc = $global:ie.Document
}

Function SetElementValueByName($name, $value, [int] $position = 0) {
  if ($global:doc -eq $null) {
    Write-Error "Document is null"
    break
  }
  $elements = @($global:doc.getElementsByName($name))
  if ($elements.Count -ne 0) {
    $elements[$position].Value = $value
  }
  else {
    Write-Warning "Couldn't find any element with name ""$name"""
  }
}

Function ClickElementById($id)
{
  $element = $global:doc.getElementById($id)
  if ($element -ne $null) {
    $element.Click()
    WaitForPage
  }
  else {
    Write-Error "Couldn't find element with id ""$id"""
    break
  }
}

Function ClickElementByName($name, [int] $position = 0)
{
  if ($global:doc -eq $null) {
    Write-Error "Document is null"
    break
  }
  $elements = @($global:doc.getElementsByName($name))
  if ($elements.Count -ne 0) {
    $elements[$position].Click()
    WaitForPage
  }
  else {
    Write-Error "Couldn't find element with name ""$name"" at position ""$position"""
    break
  }
}

#Entry point
#$verbosePreference = "SilentlyContinue"
$verbosePreference = "Continue"

$global:ie = New-Object -com "InternetExplorer.Application"
$global:ie.Navigate("about:blank")
$global:ie.visible = $true
$global:ie.children



#NavigateTo "http://www.bing.com"
#SetElementValueByName "q" "powershell variable scope"
#ClickElementById "sb_form_go"
#Can also do: ClickElementByName "go"

#NavigateTo "http://mail.com"
Write-Host -ForegroundColor Green "Attempting to login to Web Application.";
#SetElementValueByName "login1" "xxx@yyy.com"
#SetElementValueByName "password" "password"
#SetElementValueByName "lr" "lang_en"
#ClickElementById "btnSignIn"

function validate
{
 begin{
  #All init for this function
 }

 process{
  #All process function
 }

 end{
  #All finilazers
 }
}

Saturday, May 29, 2010

Windows Macros with WSH

http://www.icpug.org.uk/national/features/030316fe.htm
Eg.
Dim Wsh
Set Wsh = Wscript.CreateObject("Wscript.Shell")
Wsh.AppActivate "Exploring"
Wsh.SendKeys "{F2}{END}{LEFT}{LEFT}{LEFT}{LEFT}{BS}{BS}{BS}~{DOWN}"

Name it macro.vbs

When I instantiate the WshShell object I need to be able to refer to it in some way. Wsh is a variable for this purpose so, first of all, I explicitly declare it with the Dim statement

Set Wsh = Wscript.CreateObject("Wscript.Shell")

This is where I make an instance of the WshShell object.

Note that, as I am using the CreateObject method of WScript, I use the dot notation Wscript.CreateObject to call the method. The bit in brackets is what is called the 'programmatic identifier' of the object to be created and its value is in the documentation! The created object is then assigned to wsh so I can refer to it.

Wsh.AppActivate "Exploring"

Having set everything up this is the first line of real coding. It uses the AppActivate method of the newly defined WshShell object to tell the computer which window is to be activated for subsequent operations. (Which window is given focus is the techie way of saying this!). The string value, "Exploring" in this example, says activate the windows whose title begins with 'Exploring'. On my version of Windows at least, that means a Windows Explorer window. Note that if two Windows Explorer windows were open this code may activate the wrong one. I have not found this to be a problem in the way I use the code as a keyboard macro, since the Explorer window I wish to use has focus already.

Wsh.SendKeys "{F2}{END}{LEFT}{LEFT}{LEFT}{LEFT}{BS}{BS}{BS}~{DOWN}"

This uses the SendKeys method of the created WshShell object to send the keys to the Explorer window. The bits in quotes are the keys to send. Standard alphanumeric keys are simply typed as is. Special code strings, usually in braces, are used to define function keys. The keys in the line above correspond with the keyboard process defined in the previous section. Here is a full list of code strings taken from the documentation for SendKeys. Note that there does NOT appear to be a way of sending the special keys on a Windows keyboard

keyboard.

Key
 Code String
 
BACKSPACE
 {BACKSPACE}, {BS}, or {BKSP}
 
BREAK
 {BREAK}
 
CAPS LOCK
 {CAPSLOCK}
 
DEL or DELETE
 {DELETE} or {DEL}
 
DOWN ARROW
 {DOWN}
 
END
 {END}
 
ENTER
 {ENTER} or ~
 
ESC
 {ESC}
 
HELP
 {HELP}
 
HOME
 {HOME}
 
INS or INSERT
 {INSERT} or {INS}
 
LEFT ARROW
 {LEFT}
 
NUM LOCK
 {NUMLOCK}
 
PAGE DOWN
 {PGDN}
 
PAGE UP
 {PGUP}
 
PRINT SCREEN
 {PRTSC}
 
RIGHT ARROW
 {RIGHT}
 
SCROLL LOCK
 {SCROLLLOCK}
 
TAB
 {TAB}
 
UP ARROW
 {UP}
 
F1
 {F1}
 
F2
 {F2}
 
F3
 {F3}
 
F4
 {F4}
 
F5
 {F5}
 
F6
 {F6}
 
F7
 {F7}
 
F8
 {F8}
 
F9
 {F9}
 
F10
 {F10}
 
F11
 {F11}
 
F12
 {F12}
 
F13
 {F13}
 
F14
 {F14}
 
F15
 {F15}
 
F16
 {F16}
 

The documentation also tells you how to send the Ctrl and Alt keys in combination with alphanumeric keys.

Having created the script with Notepad, or whatever, save it to a VBScript file, (a file which has a .vbs extension). For the purpose of this example I will assume it is saved to:

C:\My Documents\WindowsScripts\Remove(n).vbs

CONVERTING THE SCRIPT TO A KEYBOARD MACRO
You could run this script in the same way as the Hello.vbs script was run, but it would be pointless. If you double clicked the Remove(n).vbs file then it would be the file highlighted and the effect of the script would be to rename the file to Remove.vbs.

We need to highlight a file of choice to be renamed and then execute the script. The way to do this is to assign a key combination to run the script. For example, if we set things up so that the key combination Ctrl-Alt-z ran the script then we could highlight the file whose name is to be changed and then press Ctrl-Alt-z. As the script will, after execution, highlight the next file in the Explorer window we could amend the names of a group of adjacent files simply by pressing Ctrl-Alt-z as many times as necessary. Even if the odd file in the window does not need its name amending we could press cursor down instead of Ctrl-Alt-z and then carry on.


Windows provides a means of assigning a key combination to run a file. You have to create a shortcut to the file ON THE DESKTOP. Creating a shortcut is not sufficient. It has to be on the desktop! Create a shortcut anywhere else and the key combination does not work. Whoever dreamt up this restriction of Windows functionality was obviously on the sauce on the day in question! Nevertheless, it does mean I have finally found a use for the desktop. I never start a program by clicking a desktop icon. I'm a clean desktop man and do not like it overrun with icons!

In the example we want to create a shortcut to C:\My Documents\WindowsScripts\Remove(n).vbs on the desktop. Do this as follows:

Right click the desktop and select New and Shortcut from the context menu. 
Click the Browse button 
Navigate to the C:\My Documents\WindowsScripts directory 
Click the down arrow next to the 'Files of type' box and select All files 
In the list of files displayed select Remove(n).vbs and click the Open button 
Click the Next button 
Give the shortcut a name, say Remove(n), and click the Finish button. 
A shortcut with the name Remove(n) will appear on the desktop. Right click it and select Properties from the context menu. 
Put the cursor in the Shortcut key box by clicking the box 
Press Ctrl-Alt-z together 
Click the OK button. 
That is all there is to it. Any time you need the script to execute just press Ctrl-Alt-z.

CREATING OTHER KEYBOARD MACROS

Now that I have explained how to create this example keyboard macro you have the template to create others. You have two things to change in the script:

Replace the "Exploring" in the Wsh.AppActivate line with the start of the title of the windows in which the macro is to work.

Define the keys to send in the Wsh.SendKeys line.

Save the revised script as another file and create another shortcut on the desktop with a different key combination.

If you are only going to use the keyboard macros infrequently you may wish to create the desktop shortcut only at the time of use and always use the Ctrl-Alt-z combination for its Shortkey. It saves remembering lots of different combinations or choosing a combination which conflicts with a shortcut in the application being used.

CONCLUSION

I hope this discussion has opened your eyes as to the possibilities of Windows Scripting Host. I have already written my second script. I mentioned in the Blog at the beginning of the year a problem I was having at work, which I solved by an inelegant method of opening Explorer using Dynamic Data Exchange. It worked but, ever searching for the elegant method, I finally worked out a solution using a script, which did not use DDE at all. That script is now a fixture on my Office Shortcut Bar and my problem has gone away.

I am thinking of returning to another problem that has been with me since the beginning of Windows 9x. How to open 2 instances of Windows Explorer and tile them horizontally over the full screen. In this way I can drag and drop copy like was done with the old File Manager. At present I create this interface manually, when I need it. How much easier it would be if I could write a script to do the creation for me.

Update
Here is the script for dual Explorer windows:

'A script to open Dual Windows Explorers on folders of the user's choice.
'
'The script should be called with TWO parameter which define the folders to open
'
Dim sa
Set sa = Wscript.CreateObject ("Shell.Application")
If WScript.Arguments.Count = 2 Then
sa.explore WScript.Arguments.Item(0)
sa.explore WScript.Arguments.Item(1)
Else
WScript.Echo "Please call this script with TWO argument to define the folders to open"
End If
Wscript.sleep(1)
sa.TileHorizontally()


Maybe you have some problems that can be solved with a script. Now that you know about WSH, take a look at it and see if you can solve those problems and discover the joy of being in control of Windows.

If you create some useful scripts please send them to me for upload. They can then be shared with the whole ICPUG community.

READER WRITES

Cesar writes to say:

I just read your web page where you describe the use Windows scripting. I’m having looking for several days this type of solution. I was wondering if you could give me a tip. I need to create a simple script that basically executes the {scroll} + {scroll} combination, as simple as that. Is this something I can do with Windows scripting. I appreciate your page, it is going to be very useful for certain issues I need to solve.
I see no problems with sending what Cesar wants. The Help file for Windows Scripting 5.6 says the keys are: 

{SCROLLLOCK}{+}{SCROLLLOCK} 

(Note: There are 3 'L's in SCROLLLOCK!)

UPDATE: 25 APRIL 2004

One of the keys that the SENDKEYS method of WSH will not emulate is the Windows key (beside the ALT keys on a Windows keyboard). Also, it is not possible to define the Windows key as the keyboard trigger for a desktop shortcut.

Mike Newman writes to tell me of a program, Winkey, that will allow you to write Windows-key keyboard shortcuts. It is a free download at:

http://download.com.com/3000-2344-913626.html?tag=lst-0-1

Another problem with WSH is that it cannot emulate the numeric keypad keys. This makes it impossible to create, for example, the character defined by pressing the ALT key in combination with the numeric keypad keys 0230. Microsoft Word has an alternative shortcut to this character, press CTRL-& followed by a, but this will not apply to all applications. Why would generation of this character be useful? Apparently, Esperanto writers use this and other symbols to write certain Esperanto characters that are not available in English. If anyone has a solution to this puzzle let me know.

Friday, May 28, 2010

Selenium Testing articles

1) http://blogs.atlassian.com/developer/2009/06/selenium_testing_with_windows.html

2) http://www.thoughtworks-studios.com/twist-agile-test-automation/1.0/help/how_do_i_use_selenium_to_test_https_sites.html

3) http://yuce.tekol.net/2009/10/web-application-testing-with-selenium.html

Wednesday, May 26, 2010

Application Status Checking with WLST

def appStatus(server_name):
       try:
           print '---------------------- Application status---------------------'
           mBeans=adminHome.getMBeansByType("ApplicationRuntime")
           for bean in mBeans:
               if server_name != bean.getObjectName().getLocation():
                   continue
               components= bean.lookupComponents()
               for componentRTList in components:
                   #ejbRTList=componentRTList.getMBeansByType("EJBComponentRuntime")
                   app = componentRTList.getParent().getName()
                   istate=componentRTList.getDeploymentState()
                   if istate == 0:
                       istate='UNPREPARED'
                   if istate == 1:
                       istate='PREPARED'
                   if istate == 2:
                       istate='ACTIVE'
                   if istate == 3:
                       istate='NEW'

                   print "%65s %65s %7s" % (str(componentRTList.getName()), app, istate)

       except:
           print "This Server has no Applications"