From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to Run System Exec (Batch File) as an Admin

Solved!
Go to solution

Hello,

I have a batch file I need to execute. But it has to run with administrator access.

How can I run a command line using the System Exec.vi as an administrator?

Veni Vidi Duci
0 Kudos
Message 1 of 16
(12,623 Views)

I don't think you can with the system exec.vi.  You will need to make a call to the Windows API.

runas.png

Message 2 of 16
(12,602 Views)

Oh, I can do that.

May I ask which DLL the API example is pointing to?

Veni Vidi Duci
0 Kudos
Message 3 of 16
(12,596 Views)

Shell32.dll.  The API call is ShellExecuteA

 

https://msdn.microsoft.com/en-us/library/windows/desktop/bb762153(v=vs.85).aspx

 

Edit:  Though, that was a snippit I posted.  You CAN just drag/drop it into your block diagram...

0 Kudos
Message 4 of 16
(12,592 Views)

I don't know if it's a side affect of the forum update, but the snippet is not working.

When I try to drag and drop it, all I get is a red "no" circle.

So I built my own version.

 

I am trying to run the tftp program.

I can execute it using the batch file, but when I use the shell program I get an error.

Now, when I run the batch file, the command prompt is C:\windows\System32\cmd.exe

When I run the dll using shell 32, the executable called is

C:\windows\SysWOW64\cmd.exe

 

I am pointing to the DLL in C:\windows\System32\cmd.exe.

I am using the ShellExecuteA function.

 

Batch file, success

 

Shell call, failure

 

Also, is there a way to make the shell function call without having to approve the "Windows wants to make changes" prompt?

Veni Vidi Duci
0 Kudos
Message 5 of 16
(12,552 Views)

I did a little bit of research, and it seems the issue I am facing is that I am calling a batch file that normally runs on a 64 bit Windows operating system, using 32 bit LabVIEW. So Shell is forcing it to execute in the 32 bit version.

So now the question is, why does TFTP work in 64 bit but not in 32 bit shell?

Veni Vidi Duci
0 Kudos
Message 6 of 16
(12,534 Views)
Solution
Accepted by topic author DB_IQ

I was able to "fix" this issue with a work around.

I installed the 64 bit version of LabVIEW which calls the proper 64 bit shell to execute the TFTP call.

I do not understand the lack of functionality in the 32 bit version, but the 64 bit version seems to work.

Veni Vidi Duci
0 Kudos
Message 7 of 16
(12,506 Views)

Hi Bowen,

Is there a(ny) function in the "shell32.dll" to launch a Batch file as "Run minimized", like in the SysExec.vi ?!

- Partha ( CLD until Oct 2024 🙂 )
0 Kudos
Message 8 of 16
(10,844 Views)

@DB_IQ wrote:

I was able to "fix" this issue with a work around.

I installed the 64 bit version of LabVIEW which calls the proper 64 bit shell to execute the TFTP call.

I do not understand the lack of functionality in the 32 bit version, but the 64 bit version seems to work.


This may have "fixed" this issue but you also lost functionality of any third party or purchased NI 32bit tool kits.

 

All you need to do is set Windows UAC to "Never Notify" and all cmd windows run in Administrator mode

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 9 of 16
(10,837 Views)

 

 


@RTSLVU wrote:


but you also lost functionality of any third party or purchased NI 32bit tool kits.


How?!

- Partha ( CLD until Oct 2024 🙂 )
0 Kudos
Message 10 of 16
(10,823 Views)