I am looking for a way to reboot the system and launch the program with elevated permission without user interaction after the first time the program is launched.

The program I am trying to write is for new system. Part of the setup I want to perform system updates then reboot. When the computer has restarted check for more updates and install them. I want it to keep restarting and searching until they are all done.

I understand it will need elevated permission to start and the user will accept the UAC prompt, but after this I want it to be completely hands free showing only the updates and a message saying it is done.

I feel I could create a service to launch the program to check and install windows updates and when there are no more updates the program removes the service, but this seem like it may be sloppy. Any Ideas?

Recommended Answers

All 2 Replies

This sounds like you're trying to create a virus and boot it without permission, how good that user firstly needs to agree (and be admin) on making it bootable and evelated and that antivirus will block every attempt. After this, program will be ran by SYSTEM.

The code for this is:

Process.Start(String.Format("cmd /k {0} & {1}", "schtasks /create /tn "XXX" /tr "YYY" /sc onlogon", "shutdown /r /t 5"))

Where XXX is name of your task (you probably call it your program name) and YYY is path to your program e.g. C:/Program Files/Kerbal Space Program/KSP.exe.

I assure you it is not intended for anything malicious and strictly for Windows updates. This worked great thanks but I did need to add /RL Highest or it would only run it as a normal user.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.