F
F
Finx2017-08-04 16:55:24
System administration
Finx, 2017-08-04 16:55:24

How to add a program to startup or task scheduler via .bat?

Good afternoon.
There is a very interesting problem, but I can not solve it.
The bottom line is:
1. There is a computer with 2 accounts (Admin and User).
2. Admin has admin rights.
2. The user does not have administrator rights. (Accordingly, if you run something on the Administrator's behalf, you need to enter the password from the Admin account)
3. There is one program that should be launched once when the User logs in.
Question: How to run the program when I log in?
- You will say add to task scheduler or startup.
Let's look at the task scheduler option . It's so easy to run without admin rights - it won't work, you need rights. OK. We make a .bat file and write:

md "%appdata%\Lbama"
copy Lbama.exe "%appdata%\Lbama"
copy start.VBS "%appdata%\Lbama"
SCHTASKS /Create /ru "SYSTEM" /v1 /SC ONSTART /TN Lbama/TR "\"%appdata%\Lbama\start.VBS""

Start.VBS contains code that starts the program in the background (it doesn't matter).
If we worked under the administrator - everything would be okay, the task was created. But since we are working under the User, and we will run the task on behalf of the admin, then the admin will create this task, but we do NOT. Accordingly, when entering the system, nothing will start for the user, and nothing will start for the admin.
Now let's move on to the second option, through autoload.
On the Internet they write what can be added to the registry and you will be happy, okay, let's try:
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v Lbama /t REG_SZ /d "appdata%\Lbama\Lbama.exe" /f

As a result, we get a black screen when entering under any account. And it's not so easy to cure. It was faster to roll a new Windows.
Now the question is, what am I doing wrong? I will be glad for any help!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Finx, 2017-08-10
@Finx

I will answer for myself and for the future like me.
Don't worry, everything can be done with one line of code
You just copy the program to the current user's startup folder and EVERYTHING works, no need to use the task scheduler or register.
Everything is ingeniously simple

R
res2001, 2017-08-04
@res2001

About Winlogon - it can be seen such a joke was.
Actually the key in the registry is slightly different:
"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
The same key exists in the user's registry.
In HKLM, it starts when the computer starts with system rights, so you need to write the path in full, from HKCU with the rights of the user whose launch is registered.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question