Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
ravikiran_dvr
Explorer

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”

3. Select “More”

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

5. Select “Record Script”



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

6. Enter SU01 transaction

7. Enter user-id details

8. Select “Change password”

9. Reset the password and continue

10. Now stop recording

Amend the script to allow automation via excel

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

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.

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.

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-9838706b9...

4 Comments
Labels in this area