Reputation: 20354
I'm setting up a test node for a continuous integration server. It shall perform the GUI tests of the application. Therefore it gets the generated setup package and silently installs the application before running the other interactive tests. There is one problem though: UAC.
Since we don't want to disable UAC to maintain a realistic test environment, it needs to be bypassed once to setup the application. There are a number of ways to do that, a popular one seems to use the Windows task scheduler for that. Tasks can be added as normal user and configured to run as administrator with no further confirmation. I could use the schtasks /create
command for that but its parameters are unclear. Also, the parameter values in the /?
help seem to be translated into German on my system and I believe (and hope) that this is a bug and the values shall actually be specified in English.
Also, I only want to create the task to have it executed immediately once, then delete it and continue with my other activities (all in a batch file). How would a schtasks call look like for this? I'd start with something like this, but it's incomplete:
schtasks /create /tn "Testaufgabe" /tr "setup.exe" /sc EINMAL /it /np /z /rl /f
PS: Oh, and I need to wait until the started application has finished until I can continue with other tasks. So the program invokation must be synchronous, not in the background. I've searched the web for hours now but can't seem to find a way to accomplish this. UAC just seems to be unusable for this scenario. But we need it in the test case because that's what the user will have.
Update: You can't use the Task Scheduler API to register tasks that will run with highest privileges. This is only possible if you have admin privileges at the time creating the task, which is not useful in my situation. So I think I need to use schtasks.exe specifically.
Upvotes: 2
Views: 4501
Reputation: 20354
It doesn't work. I just figured out how to create a task from an XML definition file from the command line. It fails if the task wants to be executed with admin rights and registering it as no effective admin. So schtasks is no way around the UAC confirmation – only the Task Scheduler GUI is. In fact, the process behing this window, mmc.exe, is already started as admin (with no UAC confirmation), so it's obvious that creating such admin tasks is possible there.
I'm giving up on bypassing the UAC confirmation. Instead I'll just start the setup executable under a different local administrator account for which I do know the password (with psexec
probably). It won't have the test user's profile and environment and may do some details a bit different, but after all this is a way that should be working.
Upvotes: 3