Thursday, September 17, 2009

Creating MS Word document using QTP

Hi ,
Let us create a very simple document in MS Word using the script.
Check the below script:
Dim obj_MSWord
Set obj_MSWord = CreateObject("Word.Application")obj_MSWord.Documents.Add
obj_MSWord.Selection.TypeText "This is a simple text"
obj_MSWord.ActiveDocument.SaveAs "D:\qtpkingblogspot.doc"
Set obj_MSWord=Nothing

Lock your PC automatically after the execution of QTP Scripts

Hi ,
The beauty of Automation Testing is that Scripts are run in an unattended mode.
Thus, what people usually do is, prepare the batch of scripts and leave for their homes. After the batch gets over, no matter even if it passes or even get failed, the PC is unlocked inviting others to view your secret project related data.
This remains a small issue in a simple project based company.
However it can become extremely devastating issue in case of a company having Finance or Banking related projects, having top most concern for the security of its data.
So one wonders as to what can be the way by which this situation can be tackled?

You can use the following QTP Script to lock your PC :
Set obj = CreateObject("WScript.Shell")
sCmnd = "%windir%\SYSTEM32\rundll32.exe user32.dll,LockWorkStation"
obj.Run sCmnd, 0, False
The above QTP script will lock your PC automatically.
Moreover, I will suggest you to create this script as a separate script and call this script lastly in your batch. This will solve the purpose :)