LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

set vi or exe to run as admin

I am communicating to parker motor controllers through the Ethernet (parker sample code). Apparently since it is Ethernet based, the code uses socket, where the sockets require admin rights (another discussion about ethernet based and admin rights). In order for my VI to connect to the controller I need to run LabView as an administrator. The problem is I am making this program into an executable for production work.

 

When I create the executable it will not connect to the controller unless I am running the application as an administrator. As this program will be used in production I want it to be as simple as possible to perform. I don't think there is a simple way to change the environment to run without the need to run application as an admin. Are there any ideas to either change the executable to run as an administrator through the application builder? My plan is to create an installer through the application builder.

 

Some ideas that I had is to create an installer file and create the executable. Change the privilege level of the executable (properties>compatibility>privilege level>run this program as an administrator). Use a batch file to install drivers and application, then replace application with the one with the elevated privilege level. Another idea I had is use a batch file to do a runas command to run application as an admin. I cannot get either method to work. Does anyone have ideas?

 

 

0 Kudos
Message 1 of 7
(10,267 Views)

You should be able to build the exe, change the priviledge level I(properties) and then build the installer (that includes the exe).

 

The installer build doesn't rebuild the exe, it just grabs the last exe built.  Thus it should have the elevated priviledge level.

 

At least I think...

Chris
Certified LabVIEW Architect
Certified TestStand Architect
0 Kudos
Message 2 of 7
(10,254 Views)

I changed the privilege and rebuilt the installer. No change. The applications' elevated privilege didn't install.

0 Kudos
Message 3 of 7
(10,226 Views)

Hello Olsen7,

 

Awesome question!  Currently, there is no way to set administrator privilege requirements using the application builder in LabVIEW.  You had some really good ideas about making this work!  There are a couple of options I've found that you can also try.  One way to ensure that the user is running the executable as an administrator is to provide a check within the program for administrator rights.  This can be accomplished in Windows by reading the registry for specific values.  With this optionthe program could be set to display a warning about administrative privileges being necessary and then closing before the user could try and perform tasks within the program as a non-administrator.  A good reference for this is shown here:

 

How Can I Programmatically Determine if a Windows User Has Administrator Privileges?

 

If this is not preferable, another option is to have a wrapper executable run your executable with administrative privileges.  Basically, you would have a wrapper VI that calls a Windows function to run a program as a different user, which then runs your main program.  A method for running a program as another user can be seen in a previous forum post, shown here:

 

LabVIEW program use administrator rights 

 

You can give this a try by pointing the wrapper VI to run your installed executable.  If it works, add the wrapper VI to your project and make it the main executable, then rebuild your application and test it out.  There is also the option of using that "runas" batch file you were talking about, but I am not familiar enough with Windows batch file commands to provide support for that.  Give those options a try and see if any of them will work for you!  

| Zach J. | Systems Engineer, HIL and Test Cells | National Instruments |
0 Kudos
Message 4 of 7
(10,216 Views)
hi,

I cannot find the reference now but I know I have achieved this in the past by embedding a manifest file along side then.exe. This contains a line to tell Windows to request elevation of privileges when someone tries to run it.

Cheers,
James Mc
========
CLA and cRIO Fanatic
My writings on LabVIEW Development are at devs.wiresmithtech.com
0 Kudos
Message 5 of 7
(10,209 Views)

@James_McN wrote:
hi,

I cannot find the reference now but I know I have achieved this in the past by embedding a manifest file along side then.exe. This contains a line to tell Windows to request elevation of privileges when someone tries to run it.


This is what James is talking about: http://helpware.net/VistaCompat.htmCreate the app.exe.manifest with the content it mentions and then your built app will request permissions when it starts. if you include this file in the installer or build spec it will get included when it's installed on the runtime machine.

0 Kudos
Message 6 of 7
(10,200 Views)

Hi,

 

I am bit new to LV but I have tried to make a VI for this. I have just followed the steps shown here:

 

UAC, Digital Sinal and Manifests

 

 

I just call this VI after each build of exe, changes its manifest file and store back..!! You may have to change the path of mt.exe according to your system. Hope it will help you.

0 Kudos
Message 7 of 7
(9,591 Views)