LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Auto-restart

Solved!
Go to solution

Hello all,

OK, this is not really a CVI question, more a Windows question, but since I don't do Windows programming anymore (only Linux and supporting old Windows progs), I'm a bit lost.

Long ago I wrote an acquisition program that MUST run 24/7, even if the computer crashes. For this I do:

WT_RegWriteString (WT_KEY_HKLM, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", "MustRun", "C:\Path\To\Myself.exe");

from within the prog and carry on execution until il crashes. Then after the system reboots the prog is relaunched. It worked fine on XP (and previous). But my users have now moved to more recent Windows and they say that:

 

- if the system or program crashes, my Registry entry does not seem to get written. For this you have to quit the prog and relaunch it manually. Is there some kind of caching of the registry going on ? How do I force the write ?

 

- when the prog restarts after a reboot, it asks for elevated privileges (and it won't run until someone clicks [OK]). I have no idea why. I don't even write to the registry upon (re)starting.

 

- Are there better alternatives to auto-start a program than to use WT_KEY_HKLM, "Software\\Microsoft\\Windows\\CurrentVersion\\Run ? Maybe create a link in [Start][Program][Startup] ? (not sure how to do that). Not that this is not permanent, the program has to be able to turn the opion ON or OFF itself, so I don't want a manual solution.

 

Thanks.

0 Kudos
Message 1 of 7
(3,206 Views)

Sorry, I got a few things wrong in my message. It seems the registry write happens only if the prog is run with elevated privileges. I'd like to avoid having to run the prog as administrator. Is there a command I can insert before the registry write to elevate the privilege (it's OK to show a popup to ask the user) and then lower it back after ?

0 Kudos
Message 2 of 7
(3,175 Views)

Hello Guillaum,

 

I am afraid not, Windows seven and beyond severely limits what you can run and set from the current user accounts event ones with local administration permissions. 

 

They have expanded the task scheduler features and you can set elevated run permissions using that. 

 

I did it some shell scripts adjusting permissions after launching apps, I can look them up on Monday if you are still stuck.

 

Best regards.

Jattie van der Linde
Engineering Manager, Software & Automation
TEL Magnetic Solutions Ltd
0 Kudos
Message 3 of 7
(3,146 Views)

Yeah, a solution using scripts I can launch with system("") would be fine. I tried with system("runas reg ...") but I couldn't get it to work, even directly from the command line. It's either access denied or wrong password, even though the password is valid.

0 Kudos
Message 4 of 7
(3,138 Views)

Hello Guillaum,

 

apologies for the delay, I get a weekly digest on Sunday nights and only saw your post then. Seems that notifications on posts are also not working anymore.

 

I have a list of file that I loop through in a dos command shell like this, where I adjust the process priority after a PC reboot.

 

for /f "delims= " %%i in (ld.lst) do wmic process where name="%%i" call setpriority "idle"

 

wmic has powerfull commands to control many other features like startup etc.

 

Best regards

 

Jattie van der Linde
Engineering Manager, Software & Automation
TEL Magnetic Solutions Ltd
0 Kudos
Message 5 of 7
(3,088 Views)

I've been thinking about another way to do that:
- have the installer set up a link to the program in the WT_KEY_HKLM, "Software\Microsoft\Windows\CurrentVersion\Run registry, with an additionnal parameter
- when prog starts, check if the additional parameter is there to know if it's a manual start or a reboot one

The installer has the proper permission, right ? But then, how do I get the installer to set the proper registry key ?
I seemed to remember that there was an [Autostart] button but I was wrong, or that was a generation ago.
I could add the key to the installer in the [Registry] menu, but how can I be sure the proper C:\Program File\... path is used ? Can I use macros in the string ?

0 Kudos
Message 6 of 7
(3,087 Views)
Solution
Accepted by topic author gdargaud

Thanks for the wmic tip, but that command is a mouthfull !!!

 

I actually found a very simple solution: instead of registering my app in WT_KEY_HKLM\Software\Microsoft\Windows\CurrentVersion\Run which requires elevated privileges, I simply do it in WT_KEY_HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run which doesn't. And it works, on next reboot the program starts by itself.

0 Kudos
Message 7 of 7
(3,079 Views)