cancel
Showing results for 
Search instead for 
Did you mean: 

Code Stage

HamitDinç1
Level 2
Hi everyone,
I'm trying to change my screen's resolution with code stage but it properly doesn't work but it works when I run it in visual studio,
I think the problem is to use class and methods in code stage but I do not know the proper use of this code,
If you have enough knowledge so can you show me the right usage of this c# code that I attached to the thread in Blue Prism code stage,

------------------------------
Hamit Dinç
------------------------------
5 REPLIES 5

PvD_SE
Level 12
Hi Hamit,

While your C# code certainly looks impressive, I wonder if this challenge could not be solved in an easy fashion by creating a little sub-process and object that does the resolution change? On the plus side of this proposal is that any RPA colleague would be able to maintain the solution, rather than only the ones that do C# programming. Just a thought.

As I'm not a C# programmer, I will not indulge in attempting to provide a Code stage based solution for that language. In my view, a Code stage can only be used for requirements that cannot be made by BP building blocks. If a more free use of Code stages would be allowed, we might as well throw out BP and start coding instead. Again, this is my view.

Happy coding!
Paul
Sweden
Happy coding!
Paul, Sweden
(By all means, do not mark this as the best answer!)

ErinConnerley
Level 4
Honestly, for even slightly advanced code I'd recommend tossing it in a dll, referencing dll on intialise, and create a code stage that simply calls the appropriate method / function from the dll. If you insist on putting this entirely in code stages you'll probably want to put it on the global code on intialise and reference the method / function in the global code from an action's code stage. There are a few extras in your code that you won't need in BP as they are already there but at a layer higher. There are also things like console writelines in your code that won't do anything you can actually see in BP. Your code CAN be adapted for BP though, take a deep look at some of the included VBOs for BP. (Excel VBO global code has some hints for you I would say.)

------------------------------
Erin Connerley
Automation Consultant
Agilify Automation
America/Indiana/Indianapolis
------------------------------

Your code is just fine and I was able to create a business object and use it to change resolutions.  The tricky part about using the code stage is knowing where to place the code from the console to the object.  In your case what I did was to place all of the code just after the USING statements down to (but not including)  the Namespace declaration in the Global Code, which is located in the Initialize section. Then in the code options I added the following references--

External References
System.Runtime.InteropServices.RuntimeInformation.dll 
Namespace imports
System.Runtime.InteropServices

And changed the language dropdown to C#

Finally for the action which I renamed the default Action1 to DisplayMode, I added a code object and placed the rest of the code starting with { Screen screen = ... down to the end making sure to preserve the curly brackets. The code should checkout just fine in both the code section and in the Global code section.  There are two warnings but these can be ignored. I commented out the console output but these could be changed to return a status and it would be easy to have the resolution modes passed in as a variable too.

Hope this helps.

------------------------------
Robert Borter
Systems Architect
Virginia Dept of Transportation
America/New_York
------------------------------

Hi Hamit,

I have made few modifications to your code and am showing you all the steps you need to do in the attached document. I was able to successfully change the screen resolution at my machine. However, technically such a setting should not be done programmatically as it changes your registry settings. 

Also, as said by Erin, such an advanced code where namespaces and classes are being defined should be a part of DLL and that should instead be called from Blue Prism. However, please find the detailed steps and let me know if it helps.



------------------------------
Regards,
Devneet Mohanty
Intelligent Automation Consultant
Blueprism 6x Certified Professional
Website: https://devneet.github.io/
Email: devneetmohanty07@gmail.com
------------------------------
---------------------------------------------------------------------------------------------------------------------------------------
Hope this helps you out and if so, please mark the current thread as the 'Answer', so others can refer to the same for reference in future.
Regards,
Devneet Mohanty,
SS&C Blueprism Community MVP 2024,
Automation Architect,
Wonderbotz India Pvt. Ltd.

Jrwork
Level 5
Hello friends!

I went through a very simple situation, in this case, I use one more method, I will inform you as steps if it is useful for you.

1) I used the QRES program and sent the command to change the password (I had a process that entered exactly and when going to the VM it found many problems, the best solution was simply the solution that had made the process).


Download QRES : Qres: https://www.majorgeeks.com/mg/getmirror/qres,1.html

2) I placed the executable inside the blueprism folder.

3) The command to change the screen you can send or send Keys Events, in this case it is this:
qres.exe /X Dimension /Y Dimension, example:
qres.exe /X 1920 /Y 1080

Then the change will be changed.

If you want to talk more about it, please contact me on whatsapp.

 +55 47 996866988