I modified the code to this:
Code: Select all
@Echo OFF
REM ===== Header ====================================
REM == MUST BE AT The Begining of The Batch =========
IF "%~1" == "RestartedByVBS" Goto :Code
(FOR /F "tokens=1*" %%a in ('findstr /B "^VBS:" ^< "%~F0"') do (
echo(%%b
)) > "%~DP0pos.vbs"
Cscript //nologo "%~DP0pos.vbs" "%~F0" 350 350&del "%~DP0pos.vbs" 2>nul
EXIT
REM ===== Code ======================================
REM == Put All Your Code Down Here ==================
:Code
Echo This is a Test Batch File in 350, 350 Coordinates on the screen
Pause
Exit /B
REM ===== Position Script============================
:Pos <BatchFileName> <X_Coordinate> <Y_Coordinate>
REM This Function will take three inputs: the name of the Batch file to execute
REM and the X and Y Coordinates to Position its CMD window
VBS: Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
VBS: Set objConfig = objWMIService.Get("Win32_ProcessStartup")
VBS: objConfig.SpawnInstance_
VBS: objConfig.X = WScript.Arguments(1)
VBS: objConfig.Y = WScript.Arguments(2)
VBS: Set objNewProcess = objWMIService.Get("Win32_Process")
VBS: intReturn = objNewProcess.Create( chr(34) & WScript.Arguments(0) & chr(34) & " " & "RestartedByVBS", Null, objConfig, intProcessID)
REM ===== End of VBScript============================
Changes:
- makes .vbs every time
- now it closes the original cmd window
Next question: what should be added to this line
Code: Select all
VBS: intReturn = objNewProcess.Create( chr(34) & WScript.Arguments(0) & chr(34) & " " & "RestartedByVBS", Null, objConfig, intProcessID)
so all the original arguments are preserved and passed back to the .cmd repositioned window:
so when new cmd window opens %1 is RestartedByVBS, all other parameters are lost.
Modify the :code section to display parameters:
Code: Select all
Echo This is a Test Batch File in 350, 350 Coordinates on the screen
echo par1=%1
echo par2=%2
echo par3=%3
Saso