1. Rick Domogalik
  2. PowerBuilder
  3. Thursday, 10 March 2022 15:17 PM UTC

I need to open an elevated (administrator) command prompt from a program.  I have tried using a simple RUN('CMD") and that opens a standard command prompt.  I need this to be the administrator version and have hit a wall on finding any documentation with how to do this.

Anyone know if this is even possible in PowerBuilder?

Thanks.

 

Rick

Mark Goldsmith Accepted Answer Pending Moderation
  1. Thursday, 10 March 2022 16:49 PM UTC
  2. PowerBuilder
  3. # 1

Hi Rick,

Possibly similar to John's suggestion re Roland's Run and Wait code...and it may be doing something similar...you should be able to accomplish this using the ShellExecute API call. The code would look something like the following:

li_return = ShellExecute(Handle(Parent), "runas", "cmd", ls_null, ls_null, 1)

Keep in mind that you will still have to respond to the User Account Control prompt that always displays (like when you right click on an app and select "Run as administrator")

...and, if I'm not mistaken, if this is being run on an account without admin rights, I believe you will be prompted for an admin account user and password.

HTH...regards,
Mark

Comment
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Thursday, 10 March 2022 16:33 PM UTC
  2. PowerBuilder
  3. # 2

Hi, Rick -

I suggest you examine the RunAndWait free code sample at Roland Smith's TopWizProgramming web site:

   https://topwizprogramming.com/freecode_runandwait.html

When you run the RunAndWait app, enter: "cmd.exe" as the File to Shell Run value and "runas" as the Shell Verb value, as shown below:

Windows User Access Control will ask for approval to run the shell command.

While the command shell is open, you can verify it has elevated (administrator) privileges by checking the Details tab in Windows Task Manager (you'll probably have to right-click in a column heading and add the Elevated column to the displayed information), as shown below:

You can examine Roland's code to learn how he accomplishes this and adapt it for your use. Good luck!

 Regards, John

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.