06-12-2013 12:29 PM
Hi there!
I'm pretty new to LabVIEW (started 2 months ago) and still have a long way ahead of me, so please forgive me if anything that I ask is too basic.
I'm trying to change the IP properties of the PC via LabVIEW for some bigger software I'm working on.
I can easily do it in Windows XP using the System Exec function to call cmd.exe and then use netsh commands, as previously explained for example here:
But then, since I want to run my software in Windows 7 (& by extension to any Windows OS), I have a problem: netsh asks for elevated rights.
So, the next problem is: how do I run cmd.exe (or any other programm?, by extension) as administrator (from LabVIEW)?. Note that I'm using an account with admin rights. But I would prefer not having to disable the User Account Control configuration, and I don't want to force the user to any interaction (clicking in pop-ups, or right-clicking in anything), I want it to be as automatized as possible.
I did a bit of research and couldn't find anyway to do it, neither any command to run with cmd, so the two similar solutions that came to my mind are very rudimentary and kind of dirty:
The conclusion is that I'm stuck with two possible solutions none of them working.
Thanks in advance for any tip or help!
Note: I titled the thread as Windows Vista, 7 & 8 since I assume all of them asks for admin rights when changing IPs. In case there are other people with the same problem, altough right now I'm only using XP & 7.
06-17-2013 12:57 PM
Any help would be appreciated
06-17-2013 02:19 PM
First question: Why do you have to change OS properties via a custom application? I know such requirements can exist (sigh...) but nevertheless it seems a little bit weird to me 😉
OK, now an idea:
Run cmd.exe via task scheduler. Here is a how to do it: http://maximumpcguides.com/windows-vista/run-a-program-with-administrative-privileges-without-uac-pr...
01-11-2016 11:28 AM
I just came across this discussion and tried to follow candidus' solution. It did not work for me. The command window would open and then immediately close.
I have a similar program where I need to do this. It is a program already written in LabVIEW which configures some hardware. To configure some modules on this hardware, it needs to change the computer's IP address to match the default IP address on the hardware, and then communicates with the hardware to configure a new IP address on the hardware, before changing the computer's IP address back to my company's domain. The UAC on my computer cannot be disabled to do this. This program worked fine on Windows XP, but will not work on Windows 7 because UAC does not allow it. The program needs to do this without any prompts for user names and/or passwords.
Thanks for any help anyone can give me.
01-12-2016 02:44 AM
Without any prompts is a bugger! If you can't disable UAC then the UAC dialog will pop up no matter what when trying to execute another program with elevated rights. Maybe there is a way to circumvent this with a shell script file (some sort of Visual Basic for the shell) but I'm not positive about that. It would mean that the username and password for the admin account are in an openly readable file on the computer, and that is exactly what UAC is trying to clamp down on.
01-12-2016 03:53 AM - edited 01-12-2016 03:54 AM
Few suggestions:
1) Get an extra NIC card (e.g. PCI / USB) and have it permanently configured to be on the default IP address of the hardware
2) Instead of configuring the IP address on your PC, get a configurable switch that allows you to change the IP address assigned to you by communicating with the switch
3) It might be possible with a manifest file to specify that your application requires elevation before running - if you can get that to work then it should only prompt for UAC when you launch the program, not each time it tries to do an operation which requires elevation.
4) I heard of a program called 'RunAs' which is supposed to be able to bypass the UAC prompt by pre-supplying the credentials - it's been a while since I looked at it so I might have it mixed up with something else.
If none of those work, then you need to talk to your IT department about disabling UAC for you (our team has laptops with UAC disabled as we do LabVIEW development), or providing you with a special laptop or something that doesn't have UAC.
01-13-2016 06:51 AM
Thanks for the suggestions. I think the idea with the extra NIC would work. The "runas" idea does not work. I tried several different ways of using it, but basically Windows has made it so that you cannot programmatically launch an administrator level command prompt (this is different than the command prompt you get even when logged in as an administrator). The only command prompt you can launch programmatically is a command prompt with no elevated rights.
Our solution looks like we are going to change our process such that we will use another process to change the IP address of the hardware to match the company subnet. Then we can do all the other hardware configuration things we need with the existing LabVIEW program.
Thanks again.