Solved Procedute to take a Print screen & Store in Data Item Using Blue Prism

Lalithkumar

New Member
Hi Naveen,

I got into developing this feature since a screenshot is required quite often by us. I believe that the ability to capture screenshot on errors is implemented in the version 6.
You can still explore the 'Image Manipulation' VBO and let me know if you find anything suitable.

Follow the below steps to create a new Action in the existing VBO:
Take a backup of 'Utility - Image Manipulation' xml file from the Blue Prism's VBO folder
1. Open the 'Initialise' tab -> 'Code Options' tab of the 'Utility - Image Manipulation'
- Add this path to the External References. (Must be at the same location but locate it on your machine)
C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll

2. Add a new tab and name it 'GetScreenshot' (or anything that you would like which shows in the Actions dropdown)
- Add a Code stage say 'Capture Screenshot'
- For the Start Input parameters of 'GetScreenshot', refer 1.jpg
- Refer 2.jpg for Input parameters of the Code stage
Add the necessary data items wherever required as you keep seeing them in the screenshots.
- Refer 3.jpg for Output parameters of the Code stage
- Add the below code in the 'Code' tab of the Code stage

Dim area As Rectangle
Dim capture As System.Drawing.Bitmap
Dim graph As Graphics


area = My.Computer.Screen.Bounds
capture = New System.Drawing.Bitmap(area.Width, area.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
graph = Graphics.FromImage(capture)
graph.CopyFromScreen(area.X, area.Y, 0, 0, area.Size, CopyPixelOperation.SourceCopy)
FullSavedScreenshotPath = OutputFolderPath & Format(now, "dd-MMM-yy hh-mm-ss") & ".jpeg"
capture.Save (FullSavedScreenshotPath, System.Drawing.Imaging.ImageFormat.jpeg)
ScreenshotImage = capture


- Refer 4.jpg for Output parameters of 'GetScreenshot'
- The overall 'Getscreenshot' tab looks like 5.jpg including all the required data items

3. Now, inside the process from where you want call this new Action
- Use an Action stage, choose the 'Utility - Image Manipulation', select the new Action 'GetScreenshot' from the dropdown (You need to Save and publish the VBO and hit Refresh or restart BP to reflect the new Action in the dropdown)
- Refer 6.jpg for the Input parameters of Action stage
- This is the path where the actual screenshot file will be saved. You need to make sure that the folders exists or can amend the code that checks if the folder exists and creates one if it doesn't. Note the backslash \ at the end of the path.
- Refer 7.jpg for the Output parameters of Action stage of Process call

4. The final output after running the process will look like this.

View attachment 442

i. You will find an actual image stored in the Image data item - CapturedScreenshot data item
ii. Its full file path will be in the text data item - FullSavedScreenshotPath data item
iii. A physical image will be stored in the specified folder ie; "C:\Screenshots\" in this case.


The above steps saves the actual screenshot image in an Image data item as well as saves the image to a folder path.
You can tweak the code as per your requirements perhaps something like having a flag as True or False if you want the result to be stored only in an Image data item or only a physical image in a folder or both.

Edit: Screenshots stored under "C:\Screenshots\"
View attachment 805

Also, the code is written such that the image is saved with the current date and time by default. If you want to customise that with the details of your running process, then that can be modified by passing a parameter to the code stage and modifying the .Save code and having a file name as required.
Similarly you can amend the code to save the image in the desired format - png, bmp ....and so on.
 

Jueeli

New Member
Hi @VJR ,

I tried modifying Image Manipulation VBO as per your instructions and didn't get any code error but I am getting below error while running process by calling Screenshot action:
"Internal : The Business Object Utility - Image Manipulation is not available. Please visit System Manager to check that this Object is installed and that it has not been disabled."

Could you please help me to deal with this error?

Thanks a lot in advance.
Jueeli Patil
 
Hello @VJR ,

Thanks for your Help!!!

When I am running 'Capture Screenshot' custom code in Production, I am getting "Internal : could not execute code stage because exception thrown by code stage : The handle is invalid" error.

Please find attached screenshots for the code and the way I am using it.

Thanks & Regards,
Naveen.
 

Attachments

  • Action Inputs.png
    20.9 KB · Views: 26
  • Action Outputs.png
    21 KB · Views: 21
  • Capture Screenshot.png
    25.4 KB · Views: 21
  • Get Screenshot action.png
    52.4 KB · Views: 19
  • Get Screenshot Outputs.png
    20.8 KB · Views: 14
  • Get Screenshot Inputs.png
    16.6 KB · Views: 15
  • Get Screenshot Code.png
    30.3 KB · Views: 20
  • Handle is Invalid.png
    5.3 KB · Views: 16
Hi Ujjaldas,

The code I've mentioned above is in BP v5 and you have v6. Perhaps something may have changed and hence you are seeing the errors.
In any case Format is a Microsoft.VisualBasic function.
Either add 'Microsoft.VisualBasic' to the Namespace imports section of the Initialise tab
OR use any of the .net equivalent of the format and now functions. (Refer link https://www.dotnetperls.com/datetime-format-vbnet)
HOw to resolve this error? and why it is coming?
View attachment 1559911058385.png
 
Hello Divyarani411,

Please make sure to add all the dll's which are mentioned in the attached screenshot.
 

Attachments

  • Capture Screenshots dll.png
    24.3 KB · Views: 33
Hi VJ,
I am getting error for two variable (Now and Format). Is there any setting needs to be done . I put code - vb and added below path in external ref as advised.
C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll

BP - 6
Windows 10

Can you please help me on this

View attachment 1317

I guess the path is different. Did you check if the dll exists in the same pah?
 

matuopm

Member
I implemented this Screenshot Functions but now I'm getting an error creating a new release:

An error occurred while attempting to create the release: Der Zugriff auf den Pfad wurde verweigert. (no access right to the path)

System.UnauthorizedAccessException: Der Zugriff auf den Pfad wurde verweigert.
bei System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
bei System.IO.__Error.WinIOError()
bei System.IO.FileInfo.MoveTo(String destFileName)
bei BluePrism.AutomateAppCore.clsRelease.Export(FileInfo file, Boolean compress, clsProgressMonitor mon)
bei BluePrism.AutomateAppCore.clsRelease.Export(FileInfo file, clsProgressMonitor mon)
bei AutomateUI.frmCreateRelease.HandleDoWork(Object sender, DoWorkEventArgs e)
bei AutomateUI.BackgroundWorkerStage.HandleWorkerDoWork(Object sender, DoWorkEventArgs e)
bei System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)
bei System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)

Unfortunately it does not say which path ...

Does anyone have an Idea what could be the problem ?

I suspect, it is because I added the C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll to the "Utility - Image Manipulation" Initialise Page Start Stage Code Options but I'm not sure. (see screenshot)

View attachment codeoptions.png

Where can I copy this file that it matches the other External References in the Screenshot ?
 

hamzakhan

New Member
Hi VJR, your ScreenCapture code works like a charm.

1 Quesiton, I have multiple I.E Windows open and want to only Capture the screenshot of the Window Title e.g "Customer Details - Internet Explorer".

so intead of capturing multiple I.E ScreenCapture, is there a way to give input of the Window Title and get that pacific screen-capture?

thanks,
 

sunortap

Member
Hello Guys,

I have received an error "Internal : could not execute code stage because exception thrown by code stage : The handle is invalid".
It appears only in control room and in studio it works perfectly - any idea?
 

umbyrulez01

New Member
Hello @VJR ,

Thanks for your Help!!!

When I am running 'Capture Screenshot' custom code in Production, I am getting "Internal : could not execute code stage because exception thrown by code stage : The handle is invalid" error.

Please find attached screenshots for the code and the way I am using it.

Thanks & Regards,
Naveen.

Did you resolve this situation? i have the same issue

U.
 

mstark

New Member
Hi Naveen,

I got into developing this feature since a screenshot is required quite often by us. I believe that the ability to capture screenshot on errors is implemented in the version 6.
You can still explore the 'Image Manipulation' VBO and let me know if you find anything suitable.

Follow the below steps to create a new Action in the existing VBO:
Take a backup of 'Utility - Image Manipulation' xml file from the Blue Prism's VBO folder
1. Open the 'Initialise' tab -> 'Code Options' tab of the 'Utility - Image Manipulation'
- Add this path to the External References. (Must be at the same location but locate it on your machine)
C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll

2. Add a new tab and name it 'GetScreenshot' (or anything that you would like which shows in the Actions dropdown)
- Add a Code stage say 'Capture Screenshot'
- For the Start Input parameters of 'GetScreenshot', refer 1.jpg
- Refer 2.jpg for Input parameters of the Code stage
Add the necessary data items wherever required as you keep seeing them in the screenshots.
- Refer 3.jpg for Output parameters of the Code stage
- Add the below code in the 'Code' tab of the Code stage

Dim area As Rectangle
Dim capture As System.Drawing.Bitmap
Dim graph As Graphics


area = My.Computer.Screen.Bounds
capture = New System.Drawing.Bitmap(area.Width, area.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
graph = Graphics.FromImage(capture)
graph.CopyFromScreen(area.X, area.Y, 0, 0, area.Size, CopyPixelOperation.SourceCopy)
FullSavedScreenshotPath = OutputFolderPath & Format(now, "dd-MMM-yy hh-mm-ss") & ".jpeg"
capture.Save (FullSavedScreenshotPath, System.Drawing.Imaging.ImageFormat.jpeg)
ScreenshotImage = capture


- Refer 4.jpg for Output parameters of 'GetScreenshot'
- The overall 'Getscreenshot' tab looks like 5.jpg including all the required data items

3. Now, inside the process from where you want call this new Action
- Use an Action stage, choose the 'Utility - Image Manipulation', select the new Action 'GetScreenshot' from the dropdown (You need to Save and publish the VBO and hit Refresh or restart BP to reflect the new Action in the dropdown)
- Refer 6.jpg for the Input parameters of Action stage
- This is the path where the actual screenshot file will be saved. You need to make sure that the folders exists or can amend the code that checks if the folder exists and creates one if it doesn't. Note the backslash \ at the end of the path.
- Refer 7.jpg for the Output parameters of Action stage of Process call

4. The final output after running the process will look like this.

View attachment 442

i. You will find an actual image stored in the Image data item - CapturedScreenshot data item
ii. Its full file path will be in the text data item - FullSavedScreenshotPath data item
iii. A physical image will be stored in the specified folder ie; "C:\Screenshots\" in this case.


The above steps saves the actual screenshot image in an Image data item as well as saves the image to a folder path.
You can tweak the code as per your requirements perhaps something like having a flag as True or False if you want the result to be stored only in an Image data item or only a physical image in a folder or both.

Edit: Screenshots stored under "C:\Screenshots\"
View attachment 805

Also, the code is written such that the image is saved with the current date and time by default. If you want to customise that with the details of your running process, then that can be modified by passing a parameter to the code stage and modifying the .Save code and having a file name as required.
Similarly you can amend the code to save the image in the desired format - png, bmp ....and so on.

-------------------------------------------------------------------------
Hi, VJ.

I am trying to create this so we are able to use it with exception stages. I can't see this folder C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll, so I'm wondering if if my access to it is blocked. I have attached the code errors I am getting. Can you provide any insight? If that's the problem, is there any other way I can accomplish this without access to that folder?

Thank you!
 

Attachments

  • Code Error.PNG
    28.2 KB · Views: 6

Karthikeyan6182

New Member
Hello @VJR ,

Thanks for your Help!!!

When I am running 'Capture Screenshot' custom code in Production, I am getting "Internal : could not execute code stage because exception thrown by code stage : The handle is invalid" error.

Please find attached screenshots for the code and the way I am using it.

Thanks & Regards,
Naveen.
Hi Naveen,

How to add the business object utility image manipulation extended.pls advice
 

ashibm

New Member
Hi Naveen,

I got into developing this feature since a screenshot is required quite often by us. I believe that the ability to capture screenshot on errors is implemented in the version 6.
You can still explore the 'Image Manipulation' VBO and let me know if you find anything suitable.

Follow the below steps to create a new Action in the existing VBO:
Take a backup of 'Utility - Image Manipulation' xml file from the Blue Prism's VBO folder
1. Open the 'Initialise' tab -> 'Code Options' tab of the 'Utility - Image Manipulation'
- Add this path to the External References. (Must be at the same location but locate it on your machine)
C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll

2. Add a new tab and name it 'GetScreenshot' (or anything that you would like which shows in the Actions dropdown)
- Add a Code stage say 'Capture Screenshot'
- For the Start Input parameters of 'GetScreenshot', refer 1.jpg
- Refer 2.jpg for Input parameters of the Code stage
Add the necessary data items wherever required as you keep seeing them in the screenshots.
- Refer 3.jpg for Output parameters of the Code stage
- Add the below code in the 'Code' tab of the Code stage

Dim area As Rectangle
Dim capture As System.Drawing.Bitmap
Dim graph As Graphics


area = My.Computer.Screen.Bounds
capture = New System.Drawing.Bitmap(area.Width, area.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
graph = Graphics.FromImage(capture)
graph.CopyFromScreen(area.X, area.Y, 0, 0, area.Size, CopyPixelOperation.SourceCopy)
FullSavedScreenshotPath = OutputFolderPath & Format(now, "dd-MMM-yy hh-mm-ss") & ".jpeg"
capture.Save (FullSavedScreenshotPath, System.Drawing.Imaging.ImageFormat.jpeg)
ScreenshotImage = capture


- Refer 4.jpg for Output parameters of 'GetScreenshot'
- The overall 'Getscreenshot' tab looks like 5.jpg including all the required data items

3. Now, inside the process from where you want call this new Action
- Use an Action stage, choose the 'Utility - Image Manipulation', select the new Action 'GetScreenshot' from the dropdown (You need to Save and publish the VBO and hit Refresh or restart BP to reflect the new Action in the dropdown)
- Refer 6.jpg for the Input parameters of Action stage
- This is the path where the actual screenshot file will be saved. You need to make sure that the folders exists or can amend the code that checks if the folder exists and creates one if it doesn't. Note the backslash \ at the end of the path.
- Refer 7.jpg for the Output parameters of Action stage of Process call

4. The final output after running the process will look like this.

View attachment 442

i. You will find an actual image stored in the Image data item - CapturedScreenshot data item
ii. Its full file path will be in the text data item - FullSavedScreenshotPath data item
iii. A physical image will be stored in the specified folder ie; "C:\Screenshots\" in this case.


The above steps saves the actual screenshot image in an Image data item as well as saves the image to a folder path.
You can tweak the code as per your requirements perhaps something like having a flag as True or False if you want the result to be stored only in an Image data item or only a physical image in a folder or both.

Edit: Screenshots stored under "C:\Screenshots\"
View attachment 805

Also, the code is written such that the image is saved with the current date and time by default. If you want to customise that with the details of your running process, then that can be modified by passing a parameter to the code stage and modifying the .Save code and having a file name as required.
Similarly you can amend the code to save the image in the desired format - png, bmp ....and so on.
What would be the best way to save a screenshot of an excel sheet?
 

Balaji_MCA

New Member
Can anyone attach the bp process. Better way to check. Still i cant able to solve it. Want to take screenshot of the Exception.
 

Rohitkr99

New Member
Hi Naveen,

I got into developing this feature since a screenshot is required quite often by us. I believe that the ability to capture screenshot on errors is implemented in the version 6.
You can still explore the 'Image Manipulation' VBO and let me know if you find anything suitable.

Follow the below steps to create a new Action in the existing VBO:
Take a backup of 'Utility - Image Manipulation' xml file from the Blue Prism's VBO folder
1. Open the 'Initialise' tab -> 'Code Options' tab of the 'Utility - Image Manipulation'
- Add this path to the External References. (Must be at the same location but locate it on your machine)
C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll

2. Add a new tab and name it 'GetScreenshot' (or anything that you would like which shows in the Actions dropdown)
- Add a Code stage say 'Capture Screenshot'
- For the Start Input parameters of 'GetScreenshot', refer 1.jpg
- Refer 2.jpg for Input parameters of the Code stage
Add the necessary data items wherever required as you keep seeing them in the screenshots.
- Refer 3.jpg for Output parameters of the Code stage
- Add the below code in the 'Code' tab of the Code stage

Dim area As Rectangle
Dim capture As System.Drawing.Bitmap
Dim graph As Graphics


area = My.Computer.Screen.Bounds
capture = New System.Drawing.Bitmap(area.Width, area.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
graph = Graphics.FromImage(capture)
graph.CopyFromScreen(area.X, area.Y, 0, 0, area.Size, CopyPixelOperation.SourceCopy)
FullSavedScreenshotPath = OutputFolderPath & Format(now, "dd-MMM-yy hh-mm-ss") & ".jpeg"
capture.Save (FullSavedScreenshotPath, System.Drawing.Imaging.ImageFormat.jpeg)
ScreenshotImage = capture


- Refer 4.jpg for Output parameters of 'GetScreenshot'
- The overall 'Getscreenshot' tab looks like 5.jpg including all the required data items

3. Now, inside the process from where you want call this new Action
- Use an Action stage, choose the 'Utility - Image Manipulation', select the new Action 'GetScreenshot' from the dropdown (You need to Save and publish the VBO and hit Refresh or restart BP to reflect the new Action in the dropdown)
- Refer 6.jpg for the Input parameters of Action stage
- This is the path where the actual screenshot file will be saved. You need to make sure that the folders exists or can amend the code that checks if the folder exists and creates one if it doesn't. Note the backslash \ at the end of the path.
- Refer 7.jpg for the Output parameters of Action stage of Process call

4. The final output after running the process will look like this.

View attachment 442

i. You will find an actual image stored in the Image data item - CapturedScreenshot data item
ii. Its full file path will be in the text data item - FullSavedScreenshotPath data item
iii. A physical image will be stored in the specified folder ie; "C:\Screenshots\" in this case.


The above steps saves the actual screenshot image in an Image data item as well as saves the image to a folder path.
You can tweak the code as per your requirements perhaps something like having a flag as True or False if you want the result to be stored only in an Image data item or only a physical image in a folder or both.

Edit: Screenshots stored under "C:\Screenshots\"
View attachment 805

Also, the code is written such that the image is saved with the current date and time by default. If you want to customise that with the details of your running process, then that can be modified by passing a parameter to the code stage and modifying the .Save code and having a file name as required.
Similarly you can amend the code to save the image in the desired format - png, bmp ....and so on.


Hi,

Sometime the above code throws error "Handle is invalid" and no screen captures by it. Can you please provide me a root cause of such error ?

Best Regards,
Rohit Kumar
 
Top