This time, my problem is nearly impossible to solve (at least for me

Any help is greatly appreciated,
PaperTronics
Moderator: DosItHelp
Code: Select all
set /a "left=100, top=50"
set "oldpos="
for /f "tokens=3" %%i in ('2^>nul reg query "HKCU\Console" /v "WindowPosition"') do set "oldpos=%%i"
set /a "newpos=(top << 16) | left"
>nul reg add "HKCU\Console" /v "WindowPosition" /t REG_DWORD /d %newpos% /f
start cmd /k
>nul pathping 127.0.0.1 -n -q 1 -p 500
if defined oldpos (>nul reg add "HKCU\Console" /v "WindowPosition" /t REG_DWORD /d %oldpos% /f) else >nul reg delete "HKCU\Console" /v "WindowPosition" /f
Code: Select all
<# :
:: Based on https://gist.github.com/coldnebo/1148334
:: Converted to a batch/powershell hybrid via http://www.dostips.com/forum/viewtopic.php?p=37780#p37780
@echo off
setlocal
set "POWERSHELL_BAT_ARGS=%*"
if defined POWERSHELL_BAT_ARGS set "POWERSHELL_BAT_ARGS=%POWERSHELL_BAT_ARGS:"=\"%"
endlocal & powershell -NoLogo -NoProfile -Command "$_ = $input; Invoke-Expression $( '$input = $_; $_ = \"\"; $args = @( &{ $args } %POWERSHELL_BAT_ARGS% );' + [String]::Join( [char]10, $( Get-Content \"%~f0\" ) ) )"
goto :EOF
#>
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class Win32 {
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
}
public struct RECT
{
public int Left; // x position of upper-left corner
public int Top; // y position of upper-left corner
public int Right; // x position of lower-right corner
public int Bottom; // y position of lower-right corner
}
"@
# Start the desired application
$application_path = "C:\Windows\system32\cmd.exe"
Start-Process $application_path
# You wouldn't ordinarily need the [1], but running the script inherently opens a window,
# and you want to do things with the window that that window opens.
$h = (Get-Process | where {$_.Path -eq $application_path})[1].MainWindowHandle
$rcWindow = New-Object RECT
[Win32]::GetWindowRect($h,[ref]$rcWindow)
$win_width = 1280
$win_height = 720
$screen_x=0
$screen_y=0
[Win32]::MoveWindow($h, $screen_x, $screen_y, $win_width, $win_height, $true )
Unfortunately, I tried, and a normal window opened, but I got this and two follow-on errors in the originating window:ShadowThief wrote:Code: Select all
# You wouldn't ordinarily need the [1], but running the script inherently opens a window,
# and you want to do things with the window that that window opens.
$h = (Get-Process | where {$_.Path -eq $application_path})[1].MainWindowHandle
Code: Select all
Cannot index into a null array.
At line:46 char:60
+ $h = (Get-Process | where {$_.Path -eq $application_path})[ <<<< 1].MainWindowHandle
+ CategoryInfo : InvalidOperation: (1:Int32) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
ShadowThief wrote:Weird, it opens and move for me instantly.
I did not want to leave this hanging. Eventually, I refreshed my copy of your code.ShadowThief wrote:Try changing the [1] to [0].
PaperTronics wrote:Can you please describe how you fixed it? PaperTronics
Code: Select all
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\Zyltch>pushd ~scripts~
C:\Users\Zyltch\~Scripts~>CMDlayoutPShbd
True
True
C:\Users\Zyltch\~Scripts~>echo %cmdcmdline%
C:\Windows\system32\cmd.exe
C:\Users\Zyltch\~Scripts~>echo.Shortcut target: %windir%\system32\cmd.exe /E /K %comspec%
Shortcut target: C:\Windows\system32\cmd.exe /E /K C:\Windows\system32\cmd.exe
C:\Users\Zyltch\~Scripts~>echo.Shortcut Start in: %HOMEDRIVE%%HOMEPATH%
Shortcut Start in: C:\Users\Zyltch
Code: Select all
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\Zyltch\Desktop>rem 1st open window at default coordinates
C:\Users\Zyltch\Desktop>rem 2nd run moved this window
C:\Users\Zyltch\Desktop>rem 3rd run hard to tell - now moving window by dragging
C:\Users\Zyltch\Desktop>rem 4th run moved this window
C:\Users\Zyltch\Desktop>rem changing $Screen_y value in script
C:\Users\Zyltch\Desktop>rem changing $Screen_x value in script
C:\Users\Zyltch\Desktop>rem 5th run moved this window to updated location
thefeduke wrote:It appears similar whether I start the script by START command, by double-click in File Explorer, by a desktop shortcut or by storing the script file on the Desktop and opening it from there. How have you tried it and how do you actually want it to be used?
thefeduke wrote:I was mostly using Win7Pro. What is your software, please?
thefeduke wrote:By plugin, do you mean a non-Windows executable file? I ask because, I noticed that you have used this term to describe a useful DOS script file, as well.
Let me qualify that with: that are not native to Windows.PaperTronics wrote:When I say plugin, I mean any file that has an extension different than .bat
thefeduke wrote:This involves creating a temporary .exe file which you may reuse or recreate each run.