SAP GUI Script Recording & Playback for mass password resets

This document will explain how to automate the SAP User-id password resets using the Script Recording and Playback.

You can able to make the script on your own by following this document and programming knowledge is not required.

Script recording

Following screenshots show how to record and create the script file for password resets.

1. Click “Customize Local Layout”

2. Select “Script Recording and Playback”

/wp-content/uploads/2016/07/1_1000163.png

3. Select “More”

/wp-content/uploads/2016/07/2_1000169.png

4. Enter the new file name with .vbs extension with the preferred existing folder path.

/wp-content/uploads/2016/07/3_1000170.png

5. Select “Record Script”

/wp-content/uploads/2016/07/4_1000171.png

When recording is in progress, we can see this indicator at the bottom of the screen.

/wp-content/uploads/2016/07/5_1000176.png

6. Enter SU01 transaction

/wp-content/uploads/2016/07/6_1000177.png

7. Enter user-id details

8. Select “Change password”

/wp-content/uploads/2016/07/7_1000178.png

9. Reset the password and continue

/wp-content/uploads/2016/07/8_1000179.png

/wp-content/uploads/2016/07/9_1000181.png

10. Now stop recording

/wp-content/uploads/2016/07/10_1000182.png

Amend the script to allow automation via excel

Access the generated script file (PasswordReset.vbs) from the saved path and open with Notepad.

/wp-content/uploads/2016/07/11_1000183.png

/wp-content/uploads/2016/07/12_1000187.png

Insert below two blocks of code in the script file as marked above along with the suggested changes. Then Save and close the file.

‘**********Insert this code additionally**********BLOCK BEGIN – 1

Dim objExcel, objWorkbook, objSheet, i

Set objExcel = CreateObject(“Excel.Application”)

Set objWorkbook = objExcel.Workbooks.Open(“C:\Scripts\PasswordReset.xlsx”) ‘Provide the file path where you ‘are supposed to store the excel file

Set objSheet = objWorkbook.Sheets(“Sheet1”)

For i = 2 to objSheet.UsedRange.Rows.Count

USERID = Trim(CStr(objSheet.Cells(i, 1).Value)) ‘Column1

PWD = Trim(CStr(objSheet.Cells(i, 2).Value)) ‘Column2

‘**********Insert this code additionally**********BLOCK END – 1

‘**********Insert this code addtionally**********BLOCK BEGIN – 2

next

msgbox “Password reset completed”

‘**********Insert this code addtionally**********BLOCK END – 2

Final code should be as below:

If Not IsObject(application) Then

Set SapGuiAuto  = GetObject(“SAPGUI”)

Set application = SapGuiAuto.GetScriptingEngine

End If

If Not IsObject(connection) Then

Set connection = application.Children(0)

End If

If Not IsObject(session) Then

Set session    = connection.Children(0)

End If

If IsObject(WScript) Then

WScript.ConnectObject session, “on”

WScript.ConnectObject application, “on”

End If

session.findById(“wnd[0]”).maximize

‘**********Insert this code additionally**********BLOCK BEGIN – 1

Dim objExcel, objWorkbook, objSheet, i

Set objExcel = CreateObject(“Excel.Application”)

Set objWorkbook = objExcel.Workbooks.Open(“C:\Scripts\PasswordReset.xlsx”)

Set objSheet = objWorkbook.Sheets(“Sheet1”)

For i = 2 to objSheet.UsedRange.Rows.Count

USERID = Trim(CStr(objSheet.Cells(i, 1).Value)) ‘Column1

PWD = Trim(CStr(objSheet.Cells(i, 2).Value)) ‘Column2

‘**********Insert this code additionally**********BLOCK END – 1

session.findById(“wnd[0]/tbar[0]/okcd”).text = “su01”

session.findById(“wnd[0]”).sendVKey 0

session.findById(“wnd[0]/usr/ctxtUSR02-BNAME”).text = USERID ‘Replace “TEST” with USERID

session.findById(“wnd[0]/usr/ctxtUSR02-BNAME”).caretPosition = 4

session.findById(“wnd[0]”).sendVKey 0

session.findById(“wnd[0]/tbar[1]/btn[20]”).press

session.findById(“wnd[1]/usr/pwdG_PASSWORD1”).text = PWD ‘Replace “********” with PWD

session.findById(“wnd[1]/usr/pwdG_PASSWORD2”).text = PWD ‘Replace “********” with PWD

session.findById(“wnd[1]/usr/pwdG_PASSWORD2”).setFocus

session.findById(“wnd[1]/usr/pwdG_PASSWORD2”).caretPosition = 11

session.findById(“wnd[1]/tbar[0]/btn[0]”).press

‘**********Insert this code addtionally**********BLOCK BEGIN – 2

next

msgbox “Password reset completed”

‘**********Insert this code addtionally**********BLOCK END – 2

Create an excel file as below sample and save in the file path: “C:\Scripts\PasswordReset.xlsx”. This file path has been suggested here, as the same was coded in the above script. You can create and save the excel file in the desired path and ensure to update the same in the script.

NOTE: Ensure to provide the existing user-ids with appropriate passwords in order to avoid errors while executing the script.

/wp-content/uploads/2016/07/13_1000188.png

Playback the script

Close the script file and excel file, if opened.

Click “Customize Local Layout” and Select “Script Recording and Playback”. Select the script file (PasswordReset.vbs) and press Play.

/wp-content/uploads/2016/07/14_1000189.png

/wp-content/uploads/2016/07/15_1000196.png

For SAP GUI scripting installation and activation, please refer to http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/3099a575-9cf4-2a10-9492-9838706b9262?overridelayout=t…

Was this article helpful?

Related Articles

Leave A Comment?

You must be logged in to post a comment.