Sendkeys API & the FOR loop

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Boombox
Posts: 80
Joined: 18 Oct 2012 05:51

Sendkeys API & the FOR loop

#1 Post by Boombox » 07 Nov 2012 06:11

.
Okay.

I was playing with VBscript... Saved my .vbs and recieved a virus warning.

Be careful with this one!

It is reported as: 'Medium Severity' by Microsoft Security Essentials. Lol.

I'm trying to send keystrokes via a for loop from a text file.

Code: Select all

@ECHO OFF
FOR /F "delims=" %%A IN (message.txt) DO Call :Viral %%A

:viral
(
echo Set Text = Wscript.CreateObject^("WScript.Shell"^)
echo Do
echo Wscript.Sleep 1000
echo Text.Sendkeys "%~1"
echo Loop
)>"Virus.vbs"

Start Notepad.exe
Virus.vbs

Pause


I would like each line from message.txt, sent in turn to the Sendkeys api (Notepad window)

NOTE: Wscript.Sleep 1000 = 1 second interval

Increase this delay or have another batch file watch for instances of wscript.exe (Beforehand) e.g

Code: Select all

@echo off
:top
cls
wmic process where name="wscript.exe" delete
timeout /t 10
goto top


I should probably recommend that you close any important windows & save your work.

Thanks.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Sendkeys API & the FOR loop

#2 Post by foxidrive » 07 Nov 2012 06:33

What does message.txt contain?

There are quotes and a goto missing.

Boombox wrote:.
@ECHO OFF
FOR /F "delims=" %%A IN (message.txt) DO Call :Viral "%%A"

goto :EOF

:viral

Boombox
Posts: 80
Joined: 18 Oct 2012 05:51

Re: Sendkeys API & the FOR loop

#3 Post by Boombox » 07 Nov 2012 06:37

.
The message.txt could contain anything I wanted it to...

Hello %username%,
I can see you...
What's your favourite scary movie?
You have seven days to live...

Or something more constructive.

Thanks Foxi.

Post Reply