07-27-2016 04:47 PM - edited 07-27-2016 04:48 PM
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?
Solved! Go to Solution.
07-27-2016 05:13 PM
I don't think you can with the system exec.vi. You will need to make a call to the Windows API.
07-27-2016 05:18 PM
Oh, I can do that.
May I ask which DLL the API example is pointing to?
07-27-2016 05:20 PM - edited 07-27-2016 05:21 PM
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...
07-28-2016 09:31 AM - edited 07-28-2016 09:57 AM
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.
Also, is there a way to make the shell function call without having to approve the "Windows wants to make changes" prompt?
07-28-2016 02:44 PM
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?
07-29-2016 09:37 AM
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.
12-07-2017 01:08 PM
Hi Bowen,
Is there a(ny) function in the "shell32.dll" to launch a Batch file as "Run minimized", like in the SysExec.vi ?!
12-07-2017 03:56 PM - edited 12-07-2017 03:58 PM
@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
12-08-2017 12:01 AM
@RTSLVU wrote:
but you also lost functionality of any third party or purchased NI 32bit tool kits.
How?!