1.

Solve : Makeing a batch exicute a text?

Answer»

hello im a bit new to batch files. OK is there any way to make it so that after i make the batch open notepad it enters a text into the notepad.
i did do a lot of searching to see if anyone has posted about this but no luck on my end
thank you for your help.
You can make the text first and then make Notepad open it

Code: [Select]echo Title>sample.txt
echo Next line>>sample.txt
echo Last line>>sample.txt
Notepad sample.txt
right i UNDERSTAND that. but is there any way to first open the notepad.exe then have the batch create a line in the notepad. like
  Code: [Select]echo off
start notepad.exe
(now some way to enter a code that adds text to the notepad)
Quote

right i understand that. but is there any way to first open the notepad.exe then have the batch create a line in the notepad. like

No. Notepad is a WINDOWS application. You'll need to use a language that can grab a handle to a window.

VBScript sample:
Code: [Select]Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "notepad"
WScript.Sleep 100
WshShell.AppActivate "Untitled - Notepad"
WScript.Sleep 100
WshShell.SendKeys "This is line 1"
WScript.Sleep 500
WshShell.SendKeys "~"
WScript.Sleep 500
WshShell.SendKeys "This is line 2"
WScript.Sleep 500
WshShell.SendKeys "~"
WScript.Sleep 500
WshShell.SendKeys "This is line 3"
WScript.Sleep 500
WshShell.SendKeys "~"
WScript.Sleep 2500

Save script with a VBS EXTENSION and run from the command line as wscript scriptname.vbs

Good luck.


Discussion

No Comment Found