Skip to Content
Author's profile photo Venkata Ravikiran Devisetti

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…

Assigned Tags

      4 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Nihal Shetty
      Nihal Shetty

      Hi Ravi,

      Good document !!!

      Few inputs from my end

      1. The parameter sapgui/user_scripting has to be set with value  TRUE to activate GUI scripting.
      2. The Variables we maintain in the script are case sensitive hence care should be taken while maintaining header column in excel.
      3. The below entry is will be the location of the excel you give as input, hence this can also be any value.

      password.JPG

      4. After making changes to the script in notepad, make sure to save the script in .vbs format.

      Regards,

      Nihal Shetty

      Author's profile photo Venkata Ravikiran Devisetti
      Venkata Ravikiran Devisetti
      Blog Post Author

      Hi Nihal,

      Thanks for your message! Please review my feedback for your points.

      1. Above document was focused on creating and running the scripts rather than configuration. However, for details regarding installation and activation, can refer to http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/3099a575-9cf4-2a10-9492-9838706b9262?overridelayout=t…

      2. In the above instance, Header column in excel is irrelevant and headers can be with any name, as VBScript was coded to select the data from second col and assign to variables.

      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

      3. Obviously, this can of any location. For clarity, I will consider to update.

      4. Of course, this was implicit as I mentioned in "script recording section". For clarity, I will consider to update again.

      Regards,

      Ravikiran

      Author's profile photo Former Member
      Former Member

      Hi Ravikiran,

       

      I followed above steps, when I tried to run, I am getting error message "Invalid character - ". any idea what would be the issue.

       

      Author's profile photo Fayaz Ahmed
      Fayaz Ahmed

      Hello

      Please try to remove the double quotes from the piece of code which you had copied and type " correctly.

      It will work.

      Thanks

      Fayaz