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.
LVL 1
GerhardpetAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
You just take these commands, paste them into Notepad, and save it as "Whatever.cmd" add the double quotes if your explorer is configured to hide extensions, otherwise it will save as "cmd.txt").
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:
start notepad.exe
ping.exe localhost -n 60
taskkill /F /IM notepad.exe /FI "USERNAME eq %UserName%"

Open in new window

Though I somewhat doubt that this will prevent a session from showing up as idle.
0
Pradeep DubeyConsultantCommented:
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.
0
Pradeep DubeyConsultantCommented:
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
0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

Ben Personick (Previously QCubed)Lead Network EngineerCommented:
What are you trying to accomplish by running these commands?
0
GerhardpetAuthor Commented:
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.
0
Pradeep DubeyConsultantCommented:
so you can run the provided script in a schedule of 15 min. I hope you have tested it, its good.
0
GerhardpetAuthor Commented:
I will test it later on today!
0
Pradeep DubeyConsultantCommented:
okay you can test it in your machine, just run and be idle for 20 sec you will see the output.
0
GerhardpetAuthor Commented:
@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?
0
Michael DyerSenior Systems Support AnalystCommented:
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
0
David Johnson, CD, MVPOwnerCommented:
donothing.ps1

do {
notepad.exe
start-sleep -seconds 2
taskkill /F /IM notepad.exe
Start-Sleep -Seconds (15*60)
} while (1 -eq 1)

Open in new window


powershell donothing.ps1
0
GerhardpetAuthor Commented:
@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
0
oBdACommented:
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/
0
Pradeep DubeyConsultantCommented:
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
0
GerhardpetAuthor Commented:
@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
0
David Johnson, CD, MVPOwnerCommented:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

-ExecutionPolicy  remotesigned -noprofile -file c:\fso\donothing.ps1

http://screencast.com/t/TGZ1bLgjz0e
0
GerhardpetAuthor Commented:
@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?
0
Pradeep DubeyConsultantCommented:
Gerhardpet,

I have given you a link for the task issues related to security.
can you verify that once.
0
GerhardpetAuthor Commented:
@pradeep08_81

I give up!!!

I have spent about 2 hour now on the link you provided and nothing is working for me. Too frustrating to continue wasting my time.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GerhardpetAuthor Commented:
I have not found way to make this work.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2008

From novice to tech pro — start learning today.