Link to home
Start Free TrialLog in
Avatar of brgdotnet
brgdotnetFlag for United States of America

asked on

How to specify notepad text file location when opened through the command file

If I run the commands below the first one opens a notepad text file in a maximized notepad window. The second one opens the same file but the notepad window is minimized.
So I am wondering two things.

1. Is there a way to open the notepad window so that it is half or fractionally open? Like 1/2 the normal size.
2. Is there a way to specify the location of the notepad window when it initially opens? Like left of center?
    I ask this because I will open a two notepad windows and do not want them to all be in the same location/coords. I would prefer
    that the last window open is displayed slightly to the right of the first notepad text file displayed.



1. C:\cmd.exe /c start /max notepad.exe c:\mySampleFile.txt

1. C:\cmd.exe /c start /min notepad.exe c:\mySampleFile.txt
Avatar of Bill Prew
Bill Prew

There's no "easy way" to do this from a command prompt, none of the tools to launch a windowed program include the ability to set location and size at the same time.

There are a number of ways to try and work around this, using either Powershell and it's window positioning / sizing capability, or utils like CMDOW and Auto Hot KEY (AHK).

If you want more info on those let me know which, but wasn't sure if that would be acceptable.  The fact that you're loading multiple notepad windows makes it a little trickier too I suspect, but as long as the windows have different titles that you can count on then it might work out.

EDIT: A quick search turned up these discussions, might help explain what I was referring to a bit...


»bp
Following up on Bill's comment, if you're interested in an AutoHotkey solution, I can probably help you with such a script. Regards, Joe
ASKER CERTIFIED SOLUTION
Avatar of Darrell Porter
Darrell Porter
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Notepad stores its location in the registry and starts a new instance with the sizes saved there, so here's a batch solution to start Notepad with a customized size and position:
@echo off
setlocal
set /a OffsetX = 40
set /a OffsetY = 0

set /a n1.PosX = 20
set /a n1.PosY = 20
set /a n1.SizeX = 500
set /a n1.SizeY = 500

set /a n2.PosX = n1.PosX + OffsetX
set /a n2.PosY = n1.PosY + OffsetY
set /a n2.SizeX = 500
set /a n2.SizeY = 500

call :StartNotepad %n1.PosX% %n1.PosY% %n1.SizeX% %n1.SizeY% "First.txt"

call :StartNotepad %n2.PosX% %n2.PosY% %n2.SizeX% %n2.SizeY% "Second.txt"

REM ================================================================================
REM No changes below this line
REM ================================================================================
REM Restore the original position
call :StartNotepad %iWindowPosX% %iWindowPosY% %iWindowPosDX% %iWindowPosDY%
goto :eof

:StartNotepad PosX, PosY, SizeX, SizeY, Path
REM Backup the original position
if not defined iWindowPosX for /f "tokens=1-3" %%a in ('reg.exe query HKEY_CURRENT_USER\Software\Microsoft\Notepad ^| find /i "REG_DWORD"') do set /a %%a = 1 * %%c

reg.exe add HKEY_CURRENT_USER\Software\Microsoft\Notepad /t REG_DWORD /v iWindowPosX /d %~1 /f >NUL
reg.exe add HKEY_CURRENT_USER\Software\Microsoft\Notepad /t REG_DWORD /v iWindowPosY /d %~2 /f >NUL
reg.exe add HKEY_CURRENT_USER\Software\Microsoft\Notepad /t REG_DWORD /v iWindowPosDX /d %~3 /f >NUL
reg.exe add HKEY_CURRENT_USER\Software\Microsoft\Notepad /t REG_DWORD /v iWindowPosDY /d %~4 /f >NUL
if not "%~5"=="" (
	start "" notepad.exe "%~5"
)
goto :eof

Open in new window

Avatar of brgdotnet

ASKER

Thanks Experts. It sounds like PowerShell is the way to go. I won't use that solution but thank you all kindly for the help.
@brgdotnet,

Are you all set with this now, or do you need more help?  If all set, could you please close it out now.  If you need help with the question close process take a look at:



»bp