Pages

Thursday, August 27, 2015

Msgbox Fun

Copy the below code into a notepad and save it as ".vbs" file with name "danger". Double click on the file and watch out for magic!!!
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
MyVar = MsgBox ("Hello World!", 4096 , "MsgBox Example")
set WshShell = CreateObject("wscript.shell")  
If MyVar = 1Then
iTemp = MyVar + 1
WshShell.Run "Danger.vbs"
For iCount = 1to iTemp
iAbc = MsgBox ("Hello World!", 4096 , "MsgBox Example")
Next
EndIf
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Saturday, October 11, 2014

Delete Temp files using VB Script

Copy this code into a notepad and save it as .vbs file. It can be configured in scheduler so that it can be run on a regular basis and clear your system temp files or you can double click on the file on the need basis and it do the job.

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Set WShell            =   CreateObject("WScript.Shell")
sHost                =   WShell.ExpandEnvironmentStrings( "%USERNAME%" )
Set WShell            =   Nothing
Set oFSO            =   CreateObject("Scripting.FileSystemObject")
sTempPath            =   "C:\Users\"&sHost&"\AppData\Local\Temp"
Set oFolder        =   oFSO.getfolder(sTempPath)
Set oSubFoldersObj    =   oFolder.SubFolders
Set oFilesObj        =   oFolder.Files

Foreach oFile in oFilesObj
    OnErrorResumeNext
    oFile.Delete
    OnErrorGoto0
Next

Foreach oSubFol in oSubFoldersObj
    OnErrorResumeNext
    oSubFol.Delete
    OnErrorGoto0
Next

set oFolder        =   Nothing
Set oSubFoldersObj    =   Nothing
Set oFilesObj        =   Nothing`
Set oFSO            =   Nothing


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Tuesday, July 23, 2013

SO_DO_KU Solving Program in VB Script

Copy this code into a notepad and save it as .vbs file. Provide input so do ku puzzle in an excel sheel as shown in the screenshot to the program.
When iput file is read, give its path to the program and also the output path where you want to place the output.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Version:0.9 StartHTML:00000107 EndHTML:00038478 EndFragment:00038438 EndFragment:00000000 

sStartTime = Now

Set oXLObj = CreateObject("Excel.Application")

oXLObj.Visible = True

Set oXLWB = oXLObj.Workbooks.Open ("D:\personal\Sudoku\PuzzleFile.xlsx")

Set oXL = oXLWB.Worksheets("Sudoku")

sNumString = "123456789"

For iRow = 1To9

   For iCoulmn = 1To9
      
      IfLen(Trim(oXL.Cells(iRow,iCoulmn))) = 0Then
      
         sFillerString = sNumString
         
         For iSubRow = 1To9
            IfLen(oXL.Cells(iSubRow,iCoulmn)) = 1Then
               sFillerString = Replace(sFillerString, oXL.Cells(iSubRow,iCoulmn),"")
            EndIf         
         Next
         
         For iSubCoulmn = 1To9
            IfLen(oXL.Cells(iRow,iSubCoulmn)) = 1then
               sFillerString = Replace(sFillerString, oXL.Cells(iRow,iSubCoulmn),"")
            EndIf
         Next
         
         oXL.Cells(iRow,iCoulmn) = sFillerString
                  
      EndIf
   
   Next
   
Next

Function FillCells(iFRomRow, iToRow, iFromColumn, iToCoulmn)
   
   For iTempRow = iFRomRowTo iToRow
   
      For iTempCoulmn = iFromColumnTo iToCoulmn
         
         IfLen(oXL.Cells(iTempRow, iTempCoulmn)) > 1Then
            
            For iTemp_Row = iFRomRowTo iToRow
   
               For iTemp_Coulmn = iFromColumnTo iToCoulmn
                  
                  IfLen(oXL.Cells(iTemp_Row, iTemp_Coulmn)) = 1And iTemp_Row <> iTempRowAnd  iTempCoulmn <> iTemp_CoulmnThen
                  
                     oXL.Cells(iTempRow, iTempCoulmn) = Replace(oXL.Cells(iTempRow, iTempCoulmn),oXL.Cells(iTemp_Row, iTemp_Coulmn),"")
                  
                  EndIf
               
               Next
               
            Next
         
         EndIf
      
      Next
      
   Next

EndFunction

Function PuzzleStatus ()

   ExitFlag = "False"
   
   For iRow = 1To9

      For iCoulmn = 1To9
         
         IfLen(Trim(oXL.Cells(iRow,iCoulmn))) <> 1Then
            
            ExitFlag = "True"
            
            ExitFor
         
         EndIf
         
      Next
      
      If ExitFlag = "True"Then
      
         ExitFor
         
      EndIf
      
   Next
   
   If ExitFlag = "True"Then
      
      PuzzleStatus = "NotSolved"
   
   ElseIf ExitFlag = "False"Then
   
      PuzzleStatus = "Solved"
      
   EndIf   

EndFunction


FillCells1, 3, 1, 3
FillCells1, 3, 4, 6
FillCells1, 3, 7, 9

FillCells4, 6, 1, 3
FillCells4, 6, 4, 6
FillCells4, 6, 7, 9

FillCells7, 9, 1, 3
FillCells7, 9, 4, 6
FillCells7, 9, 7, 9


iLoopCount = 1

DoWhile PuzzleStatus = "NotSolved"
   
   For iRow = 1To9
   
      For iCoulmn = 1To9
         
         IfLen(Trim(oXL.Cells(iRow,iCoulmn))) > 1Then
         
            sFillerString = oXL.Cells(iRow,iCoulmn)
            
            For iSubRow = 1To9
               IfLen(oXL.Cells(iSubRow,iCoulmn)) = 1Then
                  sFillerString = Replace(sFillerString, oXL.Cells(iSubRow,iCoulmn),"")
               EndIf         
            Next
            
            For iSubCoulmn = 1To9
               IfLen(oXL.Cells(iRow,iSubCoulmn)) = 1then
                  sFillerString = Replace(sFillerString, oXL.Cells(iRow,iSubCoulmn),"")
               EndIf
            Next
            
            oXL.Cells(iRow,iCoulmn) = sFillerString
            
         EndIf
      
      Next
      
   Next
   
   FillCells1, 3, 1, 3
   FillCells1, 3, 4, 6
   FillCells1, 3, 7, 9
   
   FillCells4, 6, 1, 3
   FillCells4, 6, 4, 6
   FillCells4, 6, 7, 9
   
   FillCells7, 9, 1, 3
   FillCells7, 9, 4, 6
   FillCells7, 9, 7, 9
   
   iLoopCount = 1 + iLoopCount
   
   If iLoopCount = 100Then
   
      ExitDo
      
   EndIf

Loop

sEndTime = Now

MsgBox PuzzleStatus & vbNewLine & sStartTime & vbNewLine & sEndTime

oXLWB.Save

oXLWB.Close

oXLObj.Quit

Set oXLObj = Nothing

Monday, July 22, 2013

Find and Replace a Word with another word in all of the files a specified folder

Copy this code into a notepad and save it as .vbs file and double click on it and wait for information popup to see your job getting done!!
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Const ForReading=1
Const ForWriting=2
sPath = < "FolderPath" > 'Example: "C:\MyFolder"
sFindString = < "String you want to find" > 'Example: "Hero"
sReplaceString = < "String you want to replace" > 'Example: "Zero"
Set fso = CreateObject("Scripting.FileSystemObject")
set oF = fso.getfolder(sPath)
Set oFO = oF.Files
For each oFile in oFO
    sFileName = oFile.name
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    filePath = sPath &"\"& sFileName
    Set myFile = objFSO.OpenTextFile(filePath, ForReading, True)
    Set myTemp= objFSO.OpenTextFile(filePath &".tmp", ForWriting, True)
    Do While Not myFile.AtEndofStream
        myLine = myFile.ReadLine
        If InStr(myLine, sFindString) Then
            myLine = replace(myLine,sFindString,sReplaceString)
        End If
        myTemp.WriteLine myLine
    Loop
    myFile.Close
    myTemp.Close
    objFSO.DeleteFile(filePath)
    objFSO.MoveFile filePath&".tmp", filePath
    Set objFSO = nothing
Next
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

How to block a site in IE using DOMscript

Copy this code into a notepad and save it as .vbs file and double click on it and see the fun!!!
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
sFlag = ""
While sFlag <> "WorkDone"
Set oShellObj = CreateObject("Shell.Application")
Set oShellWinObj = oShellObj.Windows
For Each obj In oShellWinObj
on error resume next
Do
    WScript.Sleep 1000
    iWaitCount = iWaitCount + 1
    If iWaitCount = 30 Then
        Exit Do
    End If
Loop until obj.ReadyState = 4
If lcase(obj.Document.Title) = "gmail: email from google" Then
obj.Navigate "about:blank"
sFlag = ""
msgbox "No '"& obj.Document.Title &"' please!!!"
end if
Next
Set oShellObj = Nothing
Set oShellWinObj = Nothing
wend
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
When you want to stop this, go to task manager and kill the process wscript.exe