Tuesday, March 11, 2014

Mouse Move and use Other Function Keys in AutoIt

I was try to delete a background image from a pdf  using an editor. It was difficult to do the same task for more then 100 pages.

Bingo! AutoIt is in handy to complete the task in few seconds... ok in less then 3 Minutes,

here it goes the script to select the page and delete the background.


Sleep(10000)  ; To choose the application, script it is paused for 10 seconds
For $i = 1 to 600 ; Start page 1 to 600

Send ("!n")  ;Send Alt +n

MouseClick("left", X, Y, 1) ;To Select background  object, it is repeated  object in pdf

send("{DEL}") ; To delete the object

Next

--------------------------------------------------------------------------------

new addition.
; Sleep for 5 seconds.

Sleep(5000)



For $i = 1 To 815 Step +1
   Sleep(500)

MouseClick("left", 1371, 759, 1)
send ("{DEL}")
MouseClick("left", 1614, 1037, 1)
Next

----------------------------------------------------------------
Well the MouseClick function is used in the above script is to select a particular repeated object in the PDF.
You must the x and y coordinate of mouse and replace it in the script.
How to find the Mouse Coordinate of the repeated object....

Again you can use the AutoIt Script.

Sleep (15000)
$MousePos = MouseGetPos()
$MousePos[0] ; Mouse X position
$MousePos[1] ; Mouse Y position
msgbox(0,"Debug","Cursor located at " & $MousePos[0] & "," & $MousePos[1])


Note: Using the above script may delete the necessary objects in the document. Take a copy and use the script for delete the unnecessary repeating object in the same position.






Share Permission VBScript

I was struggling  to find share permission for couple of servers.  After a long search I found a script to fetch the Share permission. It is modified to get the remote server share permission and I have included a decent error handling to it.


On Error Resume Next
Const ForReading = 1
Const ForWriting = 2
Dim strComputer
Dim objWMIService
Dim colItems
Dim objItem, intRtn, wmiSecurityDescriptor
Dim colDACLs, objACE, objUserGroup, strPermission 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("server.txt", ForReading)
Set objFile1 = objFSO.CreateTextFile("Share.csv", ForWriting)
Set objFile2 = objFSO.CreateTextFile("Share_Error.csv", ForWriting)
objFile1.write "computername,sharename,User/Group,Permission"
objFile1.WriteLine 
objFile2.write "computername,Error Number,Description"
objFile2.WriteLine
Do Until objFile.AtEndOfStream 
  
strComputer = objFile.ReadLine
     
Set objWMIService = GetObject("winmgmts:\\" & _
                             strComputer & "\root\cimv2")
if  Err.Number = 0  then                            
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalShareSecuritySetting")
     For Each objItem In colItems
        
         intRtn = objItem.GetSecurityDescriptor(wmiSecurityDescriptor)
     
         colDACLs = wmiSecurityDescriptor.DACL
         
         For Each objACE In colDACLs
             Set objUserGroup = objACE.Trustee
     
             Select Case objACE.AccessMask
                 Case 1179817 strPermission = "READ"
                 Case 1245631 strPermission = "CHANGE"
                 Case 2032127 strPermission = "FULL CONTROL"
             End Select
             
            objFile1.write strComputer & "," & objItem.Name & "," & UCase(objUserGroup.Name) & ","  & strPermission 
   objFile1.WriteLine 
         Next
     Next
Err.Clear
Else
objFile2.write strComputer & "," & Err.Number & "," & Err.Description
objFile2.WriteLine 
Err.Clear
End If
loop
objFile1.close
objFile2.close
objFSO.close