Skip to main content

Posts

Showing posts with the label Vb Scripting

Uninstall a software using vbscript ,QTP

'This works for uninstalling most applications. In this example I will show how AutoCAD 2005 can be uninstalled using a VBScript. Open Regedit and look in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall search for the application and find a the product code that is in GUID format looking like this: {5783F2D7-0301-0409-0002-0060B0CE6BBA} It might be something else for you. The code below will uninstall AutoCAD 2005 as well as Express Tools. Copy the code below into Notepad and give the file the extension vbs.on error resume next Set WshShell = CreateObject("WScript.Shell") ' Uninstall Express Tools WshShell.Run "msiexec /x {5783F2D7-0311-0409-0000-0060B0CE6BBA} /q",1,true ' Uninstall AutoCAD 2005 WshShell.Run "msiexec /x {5783F2D7-0301-0409-0002-0060B0CE6BBA} /q",1,true Reference:JTBWorld blog

Uninstall a software using vbscript , QTP

'This works for uninstalling most applications. In this example I will show how AutoCAD 2005 can be uninstalled using a VBScript. Open Regedit and look in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall search for the application and find a the product code that is in GUID format looking like this: {5783F2D7-0301-0409-0002-0060B0CE6BBA} It might be something else for you. The code below will uninstall AutoCAD 2005 as well as Express Tools. Copy the code below into Notepad and give the file the extension vbs.on error resume next Set WshShell = CreateObject("WScript.Shell") ' Uninstall Express Tools WshShell.Run "msiexec /x {5783F2D7-0311-0409-0000-0060B0CE6BBA} /q",1,true ' Uninstall AutoCAD 2005 WshShell.Run "msiexec /x {5783F2D7-0301-0409-0002-0060B0CE6BBA} /q",1,true Reference:JTBWorld blog

compare Two Text files using Vb Script

Public Function CompareFiles (FilePath1, FilePath2) Dim FS, File1, File2 Set FS = CreateObject(“Scripting.FileSystemObject”) If FS.GetFile(FilePath1).Size <> FS.GetFile(FilePath2).Size Then CompareFiles = True Exit Function End If Set File1 = FS.GetFile(FilePath1).OpenAsTextStream(1, 0) Set File2 = FS.GetFile(FilePath2).OpenAsTextStream(1, 0) CompareFiles = False Do While File1.AtEndOfStream = False Str1 = File1.Read(1000) Str2 = File2.Read(1000) CompareFiles = StrComp(Str1, Str2, 0) If CompareFiles <> 0 Then CompareFiles = True Exit Do End If Loop File1.Close() File2.Close() End Function Return value: The function returns 0 or False if the two files are identical, otherwise True. Example: File1 = “C:\countries\apple1.jpg” File2 = “C:\countries\apple3.jpg” If CompareFiles(File1, File2) = False Then MsgBox “Files are identical.” Else MsgBox “Files are different.” End If    Source: Mercury Forum’s KB articles

Compare Two Excel sheets cell by cell Using Vb Script

'This code will open two excel sheet and compare each sheet cell by cell, if any changes there in cells , it will highlight the cells in red color  in the first sheet. Set objExcel = CreateObject(“Excel.Application”) objExcel.Visible = True Set objWorkbook1= objExcel.Workbooks.Open(“C:\Jaykrishna\Docs1.xls”) Set objWorkbook2= objExcel.Workbooks.Open(“C:\Jaykrishna\Docs2.xls”) Set objWorksheet1= objWorkbook1.Worksheets(1) Set objWorksheet2= objWorkbook2.Worksheets(1)    For Each cell In objWorksheet1.UsedRange        If cell.Value <> objWorksheet2.Range(cell.Address).Value Then            cell.Interior.ColorIndex = 3′Highlights in red color if any changes in cells        Else            cell.Interior.ColorIndex = 0        End If    Next set objExcel=nothing

Search for a particular value in Excel

Set appExcel = CreateObject(“Excel.Application”) appExcel.visible=true Set objWorkBook = appExcel.Workbooks.Open (filepath)'opens the sheet Set objSheet = appExcel.Sheets(“Sheet1″) 'To select particular sheet With objSheet.UsedRange 'select the used range in particular sheet     Set c = .Find (“nn”)'data to find     For each c in objSheet.UsedRange' Loop through the used range         If c=”nn” then' compare with the expected data             c.Interior.ColorIndex = 40' make the gary color if it finds the data         End If     Set c = .FindNext(c)' next search       Next End With objWorkBook.save objWorkBook.close set appExcel=nothing

How To open Password Protected Excel sheets using Vb Script

Function UnprotectXL(filePath,fileName,pwd,writeresPwd)    Set objExcel=CreateObject(“Excel.Application”)    objExcel.Visible=false    testData=filePath&”\”&fileName    Set oWorkbook=objExcel.Workbooks    Set myWkbook=objExcel.Workbooks.open (testData,0,False,5,pwd,writeresPwd)    objExcel.DisplayAlerts=False    oWorkbook(fileName).Activate    For Each w in objExcel.Workbooks         w.SaveAs testData,,”",”"          Next    objExcel.Workbooks.Close    objExcel.Quit    Set oWorkbook=Nothing    Set objExcel=Nothing   End Function Function ProtectXL(filePath,fileName,pwd,writeresPwd)      On Error Resume Next      Set objExcel=CreateObject(“Excel.Application”)      objExcel.Visible=False      testData=filePath...

How to Download a file using VbScript

Following is the code to download a file using Vbscript, without using QTP This code uses the HTMLDom and URLDownloadToFile method from urlmon API. Since VBScript does support calling Native API methods directly, here I am using  Excel macro to declare a function for the urlmon API and running the macro by Excel API from VBscript Step1: Create a new excel and open the visual basic editor, Insert Module and paste the following code the Module, save the excel file Private Declare Function URLDownloadToFile Lib “urlmon” Alias _                                            “URLDownloadToFileA” ( _                              ...

Close All Opened Browsers Except HP Quality Center/ALM

Option : I Function  CloseIEExceptALM()                 On   Error   Resume   Next         iCurItr = 0         bExit =  False          Do                           Set  objDlg = Dialog("regexpwndtitle:=.*Internet Explorer.*","Index:=" & iCurItr)              If  Dialog("regexpwndtitle:=.*Internet Explorer.*","Index:=" & iCurItr).Exist(0)  Then                  If  objDlg.WinButton("text:=Cancel","Index:=0").Exist(0)  Then  ...