Gerhardpet
asked on
Add two commands to one batch file
How can I add these 2 commands to one batch file?
start notepad.exe
taskkill /F /IM notepad.exe
I want to run it on a schedule on a windows 2008 server RDP session so that it will not time out.
start notepad.exe
taskkill /F /IM notepad.exe
I want to run it on a schedule on a windows 2008 server RDP session so that it will not time out.
use taskkill /im notepad.exe to close notepad.exe (use /f if required)
in next line use notepad.exe to run it.
simple. If your requirement is something different then let me know.
in next line use notepad.exe to run it.
simple. If your requirement is something different then let me know.
or you can use attached VB script
it will open notepad and write hello and close it. Schedule it for require time ( 5/10/15/... sec)
command is
cscript /nologo script.vbs
script.vbs
it will open notepad and write hello and close it. Schedule it for require time ( 5/10/15/... sec)
command is
cscript /nologo script.vbs
script.vbs
What are you trying to accomplish by running these commands?
ASKER
I'm working on a win 2008 server for one of my customers using RDP and their IT manager has it set to log me out after 30 min of inactivity. He is not willing to change it in the GPO so I want to run the command and schedule it from 8-5 during work hours so that there is activity on the server.
Don't ask me why he is not willing to change it. I have tried to reason with him and not getting anywhere.
Don't ask me why he is not willing to change it. I have tried to reason with him and not getting anywhere.
so you can run the provided script in a schedule of 15 min. I hope you have tested it, its good.
ASKER
I will test it later on today!
okay you can test it in your machine, just run and be idle for 20 sec you will see the output.
ASKER
@pradeep08_81
When I run the script manually it works but when I schedule the task I don't get the proper results
I have set the command in a batch file calling the vbs script but can't get it to run from the command.
Also when I run the command manually from a dos prompt it works.
Can you help me with setting this up to run on schedule with the proper arguments?
When I run the script manually it works but when I schedule the task I don't get the proper results
I have set the command in a batch file calling the vbs script but can't get it to run from the command.
Also when I run the command manually from a dos prompt it works.
Can you help me with setting this up to run on schedule with the proper arguments?
you cannot schedule the vbs script directly - you need to create a simple batch file to call the vbs script and schedule that.
Example:
c:\temp\script.vbs
exit
Example:
c:\temp\script.vbs
exit
donothing.ps1
powershell donothing.ps1
do {
notepad.exe
start-sleep -seconds 2
taskkill /F /IM notepad.exe
Start-Sleep -Seconds (15*60)
} while (1 -eq 1)
powershell donothing.ps1
ASKER
@ve3ofa
Does not work. When running on schedule it just opens notepad with the script but does not work.
Can anyone help me make the solution work from @pradeep08_81
It works fine running it manually but not on a schedule in task scheduler
Does not work. When running on schedule it just opens notepad with the script but does not work.
Can anyone help me make the solution work from @pradeep08_81
It works fine running it manually but not on a schedule in task scheduler
You might want to have look at Caffeine; it's a small app (14KB) that simulates a keypress every 59 seconds. No need to schedule, just start it in your RDP session.
Zhorn Software > Caffeine
http://www.zhornsoftware.co.uk/caffeine/
Zhorn Software > Caffeine
http://www.zhornsoftware.co.uk/caffeine/
1) Make sure that the task is set to "configure for Windows Vista or Windows 2008" on the first page of the task properties (under the "general" tab)
2) Make sure that the task is set to "start in" the folder that contains the batch file: open the task properties, click on the "actions" tab, click on the action and then the "edit" button at the bottom. In the "Edit Action" Window there is a field for "start in (optional)" that you set to the path to the batch file.
3) Make sure that the task is running as an account that has explicit "Full access" permissions to all these things: The .bat file itself, the folder containing the .bat file, and the target files/folders that are affected by the .bat script. Inherited permissions didn't seem to work for me.
4) Make sure that the account running the task is a member of the local "administrators" group for this machine
5) Make sure that the task is set to "run whether logged on or not"
6) The Task should run successfully with expected output when you right-click on the task and select "run" If it does that then it will run successfully when you are logged off.
http://social.technet.microsoft.com/Forums/windowsserver/en-US/d47d116e-10b9-44f0-9a30-7406c86c2fbe/scheduled-task-wont-run-bat-file
2) Make sure that the task is set to "start in" the folder that contains the batch file: open the task properties, click on the "actions" tab, click on the action and then the "edit" button at the bottom. In the "Edit Action" Window there is a field for "start in (optional)" that you set to the path to the batch file.
3) Make sure that the task is running as an account that has explicit "Full access" permissions to all these things: The .bat file itself, the folder containing the .bat file, and the target files/folders that are affected by the .bat script. Inherited permissions didn't seem to work for me.
4) Make sure that the account running the task is a member of the local "administrators" group for this machine
5) Make sure that the task is set to "run whether logged on or not"
6) The Task should run successfully with expected output when you right-click on the task and select "run" If it does that then it will run successfully when you are logged off.
http://social.technet.microsoft.com/Forums/windowsserver/en-US/d47d116e-10b9-44f0-9a30-7406c86c2fbe/scheduled-task-wont-run-bat-file
It works fine on my computer! (I adjusted the sleep to 10 seconds)
http://screencast.com/t/5gtwzfca9zzE
http://blogs.technet.com/b/heyscriptingguy/archive/2012/08/11/weekend-scripter-use-the-windows-task-scheduler-to-run-a-windows-powershell-script.aspx
http://screencast.com/t/5gtwzfca9zzE
http://blogs.technet.com/b/heyscriptingguy/archive/2012/08/11/weekend-scripter-use-the-windows-task-scheduler-to-run-a-windows-powershell-script.aspx
ASKER
@ve3ofa
I'm confused in how to create the task with the proper argument or script to call.
How did you do that for the Action of the task?
I read this here but still can't figure it out
I'm confused in how to create the task with the proper argument or script to call.
How did you do that for the Action of the task?
I read this here but still can't figure it out
C:\Windows\System32\Window sPowerShel l\v1.0\pow ershell.ex e
-ExecutionPolicy remotesigned -noprofile -file c:\fso\donothing.ps1
http://screencast.com/t/TGZ1bLgjz0e
-ExecutionPolicy remotesigned -noprofile -file c:\fso\donothing.ps1
http://screencast.com/t/TGZ1bLgjz0e
ASKER
@ve3ofa
I got it to work but it still ends the RDP session.
Can anyone help me make the solution work from @pradeep08_81 to schedule it as I task?
I got it to work but it still ends the RDP session.
Can anyone help me make the solution work from @pradeep08_81 to schedule it as I task?
Gerhardpet,
I have given you a link for the task issues related to security.
can you verify that once.
I have given you a link for the task issues related to security.
can you verify that once.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I have not found way to make this work.
You might want to add a "ping.exe localhost -n 60" between the two commands, and (since it's RDP) add a check to only kill your own notepad process:
Open in new window
Though I somewhat doubt that this will prevent a session from showing up as idle.