Launching an EXE in UFT as an Administrator (1300 Views)
Reply
Regular Visitor
CarlHudson
Posts: 5
Registered: ‎01-15-2014
Message 1 of 10 (1,300 Views)
Accepted Solution

Launching an EXE in UFT as an Administrator

Hi all.

I’m a fairly new user to UFT having recently upgraded from WR. Hopefully someone can quickly point me in the right direction with this one…

I am attempting to open an exe using SystemUtil.Run, however I need to run the application as an administrator.

The application is set to ‘Always run as Admin’ but when SystemUtil.Run launches the application the User Control Account dialog appears and UFT is not able to see this to click ‘Yes’.

Is anybody able to give me some advice as to what parameters I need to use in SystemUtil, or if there is an alternative way of launching the application from UFT that I should be using?

OS is Win8.1

Many Thanks 

HP Expert
Ana_Noncheva
Posts: 245
Registered: ‎08-06-2013
Message 2 of 10 (1,284 Views)

Re: Launching an EXE in UFT as an Administrator

Hello,

 

You can launch the AUT with SystemUtil.Run, manually after UFT, or from Record & Run settings.

Is UFT not able to spy/record on this message?

If not (which is most possible), you should consider either turning off UAC, not running the AUT as admin, or starting UFT as admin as well.

Following article explains the integrity levels (control by UAC): http://support.openview.hp.com/selfsolve/document/KM00454680

 

Regards,

Ana

“HP Support
If you find that this or any post resolves your issue, please be sure to mark it as an accepted solution.”
Regular Visitor
CarlHudson
Posts: 5
Registered: ‎01-15-2014
Message 3 of 10 (1,279 Views)

Re: Launching an EXE in UFT as an Administrator

Hi Ana,

 

Thanks for the reply. Unfortuantely UFT cannot record/spy this dialog as UFT becomes diabled once the UAC dialog has the focus.

 

Our internal IT policy restricts me from turning UAC to anything other than the default 'Notify me' setting.

 

UFT when run as admin does not affect how the appliction runs and the UAC message still appears.

 

For the testing I am carrying out it is a requirement that I am granted admin privilages for a certian part of the test so the application has to be run as admin for part of the testing.

 

I did of course try all of the above before posting a 'help me' message in the forum :)

 

Thanks

 

Carl

HP Expert
Ana_Noncheva
Posts: 245
Registered: ‎08-06-2013
Message 4 of 10 (1,274 Views)

Re: Launching an EXE in UFT as an Administrator

Ok,

 

Maybe you should then just try only disabling the UAC message as explained here: http://windows.microsoft.com/en-us/windows-vista/how-do-i-change-the-behavior-of-the-user-account-co...

Does this help?

 

I also find found following, which sounds promising (also applicable for Windows 7, as I read..): http://www.techrepublic.com/blog/windows-and-office/selectively-disable-uac-for-your-trusted-vista-a...#.

 

Note: if the first one helps, you can then add some vbs code to your UFT script prior to SystemUtil.Run statement to temprary apply the setting through Windows registry, and then - at the script end - revert back this setting.

I think this is only thing you can do from within UFT in this case.

But probably you wont be able to turn off temporary UAC itself this way because it would require system reboot in order to take effect.

 

Regards,

Ana

“HP Support
If you find that this or any post resolves your issue, please be sure to mark it as an accepted solution.”
Regular Visitor
CarlHudson
Posts: 5
Registered: ‎01-15-2014
Message 5 of 10 (1,263 Views)

Re: Launching an EXE in UFT as an Administrator

Hi Ana,

 

Thanks for your suggestions.

 

Altering the setting in the Local Security Policy - to change opening the application in administrator mode to 'Elevate without prompting' does work, and it seems in Win8.1 it doens't require a reboot.

 

You mention adding vbs code to temporarily apply the setting through the Windows registry, could you advise or point me in the direction of what code I should be using here? UFT cannot be run in record or spy mode on the Local Security Policy dialog.

 

Many Thanks

 

Carl

HP Expert
Ana_Noncheva
Posts: 245
Registered: ‎08-06-2013
Message 6 of 10 (1,257 Views)

Re: Launching an EXE in UFT as an Administrator

[ Edited ]

Hello Carl,

 

Its nice that this solution works for you. I did not have the chance to test it.

 

Regarding vbs code to add:

Following (external) article suggests that the corresponding registry value for this setting is

HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\ConsentPromptBehaviorAdmin

> http://www.techrepublic.com/blog/windows-and-office/temporarily-disable-user-account-control-prompts...#.

 

So you could try following sample vbs code to change it:

Note: This piece of code is provided out of courtesy and is not supported by HP!

 

'Disable UAC prompt at the beginning of your script:

Set oShell = CreateObject("WSCript.shell")
oShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\ConsentPromptBehaviorAdmin", "0", "REG_DWORD"

 

 

'Enable UAC prompt at the end of the script:

oShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\ConsentPromptBehaviorAdmin", <original_value>, "REG_DWORD"

Set oShell = Nothing

 

You can find more about the WScript object in UFT help.

 

Regards,

Ana

“HP Support
If you find that this or any post resolves your issue, please be sure to mark it as an accepted solution.”
HP Expert
Ana_Noncheva
Posts: 245
Registered: ‎08-06-2013
Message 7 of 10 (1,248 Views)

Re: Launching an EXE in UFT as an Administrator

Hello Carl,

 

Btw, besides above suggestion, you could also try following ways to address modal dialogs (i.e. without disbaling the UAC message): http://support.openview.hp.com/selfsolve/document/KM770741

 

Regards,

Ana

“HP Support
If you find that this or any post resolves your issue, please be sure to mark it as an accepted solution.”
Regular Visitor
CarlHudson
Posts: 5
Registered: ‎01-15-2014
Message 8 of 10 (1,243 Views)

Re: Launching an EXE in UFT as an Administrator

Ana,

 

Ah, this is what I think I am looking for!

 

I'll jump back onto UFT and give this a try early next week, but I think this looks like it is going to answer my issue.

 

Thanks for all of your help, advise and knowledge on this matter.

 

Regards

 

Carl

Regular Visitor
CarlHudson
Posts: 5
Registered: ‎01-15-2014
Message 9 of 10 (1,225 Views)

Re: Launching an EXE in UFT as an Administrator

Ana,

 

I've now got round to looking at this in a little more depth and have found a way of doing it that suits me better and thought you might like to know in case its of use to you (or others) in the future.

 

I've created a txt file with:

 

runas /user:<MachineName>\<LocalAdminLogon> /Savecred <C:\Application.exe>

 

Save and then change this .txt file to a .bat file and run this, the first time it is run enter the admin password in the cmd prompt

 

From the UFT script I can now use the line:

 

SystemUtil.Run "C:\Logon.bat", "","","open"

 

This will always then run the application as admin without prompting for credentials in the UAC

 

Thanks for all your help on this.

HP Expert
Ana_Noncheva
Posts: 245
Registered: ‎08-06-2013
Message 10 of 10 (1,194 Views)

Re: Launching an EXE in UFT as an Administrator

Hello Carl,

 

This is good to know, thank you for sharing!

 

Regards,

Ana

“HP Support
If you find that this or any post resolves your issue, please be sure to mark it as an accepted solution.”
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.