0

I want to start my application automatically with adminrights on user logon. I've found this question: How to run a program automatically as admin on Windows startup? but it does not solve my problem. If i use schtasks there are two problems: The first is that it won't run on the user desktop on vista, xp,...(see comments of the 2nd answer). The second problem is this description of the onlogon parameter

The task runs whenever a user (any user) logs on. You can specify a date, or run the task the next time the user logs on.

See http://technet.microsoft.com/en-us/library/bb490996.aspx. I want to create a settings interface which allows every user to turn starting on logon on and off.

So are there any better solutions out there which will also work on windows xp?

Community
  • 1
  • 1
Florian
  • 5,918
  • 3
  • 47
  • 86

1 Answers1

0

Schtasks /Create /TN admin /RU SYSTEM /SC ONLOGON /TR C:\admin\admin.bat
is approaching the best that can be done for the scheduled task itself. It is possible that running the task as a user administrator instead of SYSTEM will display the UI, like so: Schtasks /Create /TN admin /RU "<administrator username>" /SC ONLOGON /TR C:\admin\admin.bat.

There is a lot of flexibility to be had in any batch file that is launched by the task.

If "C:\admin\admin.bat" is

set there=0
for /F %%G in ('find "%username%" C:\access\users.txt') do if ("%%G") EQU ("%username%") set there=1
if ("%there%") EQU ("1") start "real" "cmd" "/C "C:\admin\real.bat""

and "C:\admin\real.bat" contains whatever you really want to execute (hence the name), this script should solve the problem of letting the users choose if the program launches or not by adding or removing themselves from "C:\access\users.txt".

To explain, the for /F line parses the "users.txt" file for the current user's name and sets "there" to 1 if the user's username is listed verbatim on a single line. Next, the "if" line detects if the username was indeed in the file and only launches the second batch file if it was.

Evan
  • 566
  • 1
  • 6
  • 15