open multipule pings and send reboot cmds - windows

I am trying to open a few constant ping windows a certain size at certain positions and send reboot commands to each. Then rdp to another server and automatically reboot it(this server is not in the same domain and I can't ping it). All from a batch file.
This is what I have so far:
start cmd /k ping x.x.x.x -t
start cmd /k ping y.y.y.y -t
start cmd /k ping z.z.z.z -t
shutdown -r -f -m \x.x.x.x
shutdown -r -f -m \y.y.y.y
shutdown -r -f -m \z.z.z.z
mstsc c:\srv1.rdp
end
Right now these ping windows open on top of each other. And attempts to make srv1 reboot on its own have been unsuccessful. I have tried creating a batch file on srv1 then in the rdp file telling it to open this program, but couldn't get it to work.
Any ideas?

I can help you with the windows positioning. The other part doesn't sound batch related to me.
#echo off
setlocal
set "Server1=x.x.x.x"
set "Server2=y.y.y.y"
echo shutdown -r -f -m \\%server1%
call :PosWindows 0 100 %server1% "Pinging %server1%"
echo shutdown -r -f -m \\%server2%
call :PosWindows 0 500 %server2% "Pinging %server2%"
exit /b
:PosWindows xpos ypos serverip title
set /a "pos=(%2 << 16) + %1"
>nul reg add "hkcu\console\%~4" /v WindowPosition /t REG_DWORD /d "%pos%" /f
>%3.cmd echo.#echo off
>>%3.cmd echo.ping %3 -t
start "%~4" cmd /k "%3.cmd"
del /q "%3.cmd"
exit /b
Just add as many servers as you want and set the Ypos to a number greater than before.

Related

start ping www.google.si closes my cmd window

I need to open cmd window multiple times from a cmd window. Site address or ip would change, so i can ping router, pc, google,.. The problem is when i issue this command it closes my original window i can open more than i window like that. I have set the cmd windows to go to a menu to choose other options after that. I do have some parameters set, but its not working with or without them.
start ping 192.168.0.1
If nothing else, could i open .bat file with this command and change address and parameters somehow?
try to use a bat file with this code
start cmd /k PING TARGET_IP1 -n 1 -w 5000 >NUL
start cmd /k PING TARGET_IP2 -n 1 -w 5000 >NUL
start cmd /k PING TARGET_IP3 -n 1 -w 5000 >NUL
/k stay the window open
>nul is like #echo off
-w 5000 is just the timeout in miliseconds
I solved it. Not really sure when i solved the original cmd window closing but here is the code:
start cmd /c "color 0a & title ping %ip% %l% %t% %n% & cls & ping %ip% %l% %t% %n% & echo. & pause >nul | set /p = Press any key to EXIT.."
I used /c to issue more commands in a row. Now i can open cmd windows without getting main one closed, use parameters i want each time and keep it opened after it finnishes its job.

Windows batch file not working properly

My Batch file is not executing the START serial_new.exe, it only terminates serial_new.exe.
it also opens and closes immediately.
ECHO OFF
c:
cd C:\wamp\www\mobilesms\
START serial_new.exe
echo testing echo..
ping 1.1.1.1 -n 1 -w 5000 > nul
taskkill /F /IM serial_new.exe
Try
start "serial_new" serial_new.exe
The start command needs a title for the first argument.

Replacing multiline batch file with a for loop which reads a text file

I currently have a batch file that schedules chkdsk to run on multiple servers pending the next reboot-
c:\pstools\psexec \\server1 -d -u Domain\administrator cmd /c "echo Y | chkdsk c: /F"
c:\pstools\psexec \\server2 -d -u Domain\administrator cmd /c "echo Y | chkdsk c: /F"
c:\pstools\psexec \\server3 -d -u Domain\administrator cmd /c "echo Y | chkdsk c: /F"
c:\pstools\psexec \\server4 -d -u Domain\administrator cmd /c "echo Y | chkdsk c: /F"
c:\pstools\psexec \\server5 -d -u Domain\administrator cmd /c "echo Y | chkdsk c: /F"
I am trying to understand how to construct a FOR loop which will read from a txt file composed of -
server1
server2
server3
server4
The txt file will be located in the data folder on my local e: drive. Also, is there any way to not have to enter the password for the user ID more than once? Appreciate the guidance! Thx and a Happy New Year to all!
You could use a FOR, but you could also create a file named servers.txt that contains:
server1
server2
server3
server4
and run this command:
c:\pstools\psexec #servers.txt ...your command...
PsExec will execute the command on each of the computers listed in the file. Please see the psexec documentation here, and see the #file parameter.
Here's a for loop method:
#echo off
for /f "delims=" %%a in (servers.txt) do (
c:\pstools\psexec \\%%a -d -u Domain\administrator cmd /c "echo Y | chkdsk c: /F"
)

Windows Batch script leaves console window open

I'm trying to set up a friends Windows 7 computer to run Nginx & PHP5. I found a script online for starting and stopping Nginx & PHP, after adding the directory change line I was able to make it work. However, there seems to be an issue causing it to leave the second console window that starts PHP open. Is there a way to make that console window close?
Batch script:
#ECHO OFF
CD C:\nginx
tasklist /FI "IMAGENAME eq nginx.exe" | find /I "nginx.exe" > NUL && (
GOTO STOP
) || (
GOTO START
)
:START
ECHO Starting nginx
start nginx
ECHO Starting PHP
start php\php-cgi.exe -b 127.0.0.1:9000 -c c:\nginx\php\php.ini
GOTO DONE
:STOP
ECHO Stopping nginx
start nginx -s quit
ECHO Stopping PHP
taskkill /f /IM php-cgi.exe
:DONE
TIMEOUT 3
You could use the /b parameter on START to start the application without opening another cmd window
START /b php\php-cgi.exe -b 127.0.0.1:9000 -c c:\nginx\php\php.ini
Update:
It appears this is the behavior of php-cgi.exe. See this article for the full story and workaround. http://wiki.nginx.org/PHPFastCGIOnWindows
After being launched, php-cgi.exe will keep listening for connections
in a command prompt window. To hide that window, use the tiny utility
RunHiddenConsole
Basically, you just need to d/l and unzip RunHiddenConsole to your nginx directory, then change this line to:
RunHiddenConsole.exe php\php-cgi.exe -b 127.0.0.1:9000 -c c:\nginx\php\php.ini
You're looking for
start php\php-cgi.exe -b 127.0.0.1:9000 -c c:\nginx\php\php.ini
/exit b
To run a .BAT Invisible you can use a simple vbs script.
Put this in a .VBS file :
CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False
And then run your BAT like this :
wscript.exe "C:\invisible.vbs" "C:\YourBat.bat"

Shutdown a PC on LAN from another PC using a batch file in Windows 7

I'm just interested in knowing: can we shutdown a PC from another PC using a batch file if both are on the same LAN?
Yes, you can use the /m switch for shutdown like this
shutdown /s /m \\computer1 /t 0
Call the shutdown command from a batch running as a user with the correct permissions or use psshutdown.
Easiest way:
set computertoshutdown=COMPUTERNAME
set timetoshutdown =TIMEtoSHUTDOWN
set message=MESSAGE
shutdown -s -m \\%computertoshutdown% -t %timetoshutdown% -c "%message%"
This should work but you can shutdown any computer in your wifi range to find the name of the computer press the Win+Pause+Break keys all at the same time then go to computer name.
#Echo off
cd\
Echo Saman=Program
REM ****************************
REM * Program Variables *
REM ****************************
set varcomputer=[computername]
goto loop
:[computername]
Exit
REM ****************************
REM * Program *
REM ****************************
:loop
echo Shutting down %varcomputer%.
shutdown -s -m \\%varcomputer% -t 600 -c "The computer is shutting down. Please save your work."
goto %varcomputer

Resources