Custom Search
Tuesday, April 28, 2009
Kill the Process if the process is under System not in User Using QTP
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "cmd /k cd\ & cd c:\windows\system32 & taskkill /F /IM ProcessName.exe"
''''' like "services.exe"
WshShell.Run "cmd /k cd\ & cd c:\windows\system32 & taskkill /F /IM ProcessName.exe"
''''' like "services.exe"
Verify whether Database is exist or not if not Create DB in SQL
if not exists(select * from sys.databases where name = 'selftest')
create database selftest ''' Here selftest is DB Name
create database selftest ''' Here selftest is DB Name
Tuesday, April 7, 2009
Connect the Data Base and Retrieve the Data from tables use QTP
'Variable Declaration
Option Explicit
Dim Dsn_conn,rs,PTime,NowDate
Dim myarray,DiffADate
Dim strServer,strUid,strQry
Dim objConnection
' Action parameters
strServer=parameter("Server") ' This is Server Name
strUid=parameter("Uid") ' User Id
Set objConnection=Createobject("ADODB.Connection")
Dsn_conn= "DRIVER=SQL Server;SERVER="&strServer&";UID="&strUid&";APP=QuickTest Professional;WSID="&strServer&";Trusted_Connection=Yes"
objConnection.Open(Dsn_conn)
If err.number <> 0 Then
Reporter.ReportEvent 1 ,"DBConnection","Unable to Connect to the database"&"Err Description = " & err.Description
Else
Reporter.ReportEvent 0 ,"DBConnection","Connection Succeeded"
End If
Set rs=CreateObject("ADODB.RecordSet")
strQry = "UPDATE ELinkQueues.dbo.ELKMasterArchive SET ProcessedTime = DATEADD(""Day"", -10, ProcessedTime) WHERE (ProcessedTime IS NOT NULL) AND (Status = 2 OR Status = 3)" ' this is Query
Set rs=objconnection.execute(strQry)
Set rs=objconnection.execute("Select * from ELinkQueues.dbo.ELKMasterArchive")
rs.MoveFirst
Do While Not rs.EOF
PTime=rs.fields.item("ProcessedTime")
Exit Do
rs.movenext
Loop
rs.Close
objConnection.Close
Wednesday, April 1, 2009
Change the Data in XML File
Set oFSO = CreateObject("Scripting.FileSystemObject")
strApptEnterPath = "C:\Documents and Settings\krao\Desktop\environment.xml"
If CheckFileExists(strApptEnterPath) Then
Set objFile = oFSO.GetFile(strApptEnterPath)
' Checks for file attributes. This is a check for file being readonly. As the latests is taken from VSTS it will be marked as readonly. This code will uncheck the Readonly property
If objFile.Attributes AND 1 Then
objFile.Attributes = objFile.Attributes - 1
End If
Else
ExitAction "Fail"
End If
set objReadFile = OpenFile(strApptEnterPath,1)
strContents = objReadFile.ReadAll
iTmpLoc = Instr(strContents,"ELK_DATA_FILES " & vbcrlf & vbtab & vbtab & "")
strTmpVal = left(strContents,iTmpLoc-1)
strFinal = strTmpVal & "ELK_DATA_FILES " & vbcrlf & vbtab & vbtab & ""
strContents = replace(strContents,strFinal,"")
iTmpLoc = Instr(strContents,"")
strTmpVal = left(strContents,iTmpLoc-1)
' this is the exact if condition in the logic section.
strIfCondString = "C" & right(strTmpVal,len(strTmpVal) - 1)
strFinal = strFinal & strIfCondString & ""
strContents = replace(strContents,strTmpVal & "","")
strFinal = strFinal & strContents
objReadFile.close
set objReadFile = OpenFile(strApptEnterPath,2)
objReadFile.write strFinal
objReadFile.close
Set objReadFile = Nothing
Set objFile = Nothing
Function CheckFileExists (FilePath)
CheckFileExists = oFSO.FileExists(FilePath)
End Function
Function OpenFile (FilePath,mode)
set OpenFile = oFSO.OpenTextFile(FilePath, mode, True)
End Function
strApptEnterPath = "C:\Documents and Settings\krao\Desktop\environment.xml"
If CheckFileExists(strApptEnterPath) Then
Set objFile = oFSO.GetFile(strApptEnterPath)
' Checks for file attributes. This is a check for file being readonly. As the latests is taken from VSTS it will be marked as readonly. This code will uncheck the Readonly property
If objFile.Attributes AND 1 Then
objFile.Attributes = objFile.Attributes - 1
End If
Else
ExitAction "Fail"
End If
set objReadFile = OpenFile(strApptEnterPath,1)
strContents = objReadFile.ReadAll
iTmpLoc = Instr(strContents,"
strTmpVal = left(strContents,iTmpLoc-1)
strFinal = strTmpVal & "
strContents = replace(strContents,strFinal,"")
iTmpLoc = Instr(strContents,"")
strTmpVal = left(strContents,iTmpLoc-1)
' this is the exact if condition in the logic section.
strIfCondString = "C" & right(strTmpVal,len(strTmpVal) - 1)
strFinal = strFinal & strIfCondString & ""
strContents = replace(strContents,strTmpVal & "","")
strFinal = strFinal & strContents
objReadFile.close
set objReadFile = OpenFile(strApptEnterPath,2)
objReadFile.write strFinal
objReadFile.close
Set objReadFile = Nothing
Set objFile = Nothing
Function CheckFileExists (FilePath)
CheckFileExists = oFSO.FileExists(FilePath)
End Function
Function OpenFile (FilePath,mode)
set OpenFile = oFSO.OpenTextFile(FilePath, mode, True)
End Function
Subscribe to:
Posts (Atom)