How to connect to adb using a batch file? - windows

I want to create a batch file which will open command prompt and connect to adb after changing the directory. My current code opens command prompt and change the directory but does not executes the last command of connecting to adb. If anyone can help me in this direction, it would be great.
#ECHO OFF
cmd.exe /K "cd C:\Users\SAM\AppData\Local\Android\sdk\platform-tools"
adb connect 192.168.200.25:5555

cmd /k starts a command prompt process that runs a command and does not quit afterwards. Why are you using cmd.exe at all?
#echo off
cd /d c:\users\sam\appdata\local\android\sdk\platform-tools\
adb connect 192.168.200.25:5555

Related

windows cmd - execute commands in shortcut

I want to understand how I can run 2 .bat commands in a shortcut.
This are the 2 commands:
cd my_programm\startscripts\windows
start designer.cmd
How do I have to convert these commands to run from a shortcut?
I know I can run cmd with it:
%windir%\system32\cmd.exe /c "" ...
/c to execute the commands and then close the command line
"" to start in the current directory, because I use a relative path
But how do I have to write the two commands to use them as start parameters?

Running a UNC path using PSexec through CMD

I got this code below, it will run the LS-PrePost-3.0-Win32_setup.exe using cmd.
My psexec is in c:\psexec. And I put put my batch file and the exe file in the same folder.
c:\psexec\psexec -d \\%%M cmd /c start /wait "%~dp0LS-PrePost-3.0-Win32_setup.exe" /quiet /silent /norestart
My code seems does nothing. It execute the code but the exe file didnt run the the remote PC.
Edit: I changed the directory of Psexec.
You can try with something like
c:\psexec\psexec \\%%M -d -c "%~dp0LS-PrePost-3.0-Win32_setup.exe" /quiet /silent /norestart
As you are not waiting (-d) you don't need the start /wait
As you are starting a executable file not an internal command, you don't need the cmd /c.
The file is executed in the remote machine, so, it must be available in the remote machine. Copy it (-c)
From psexec help
-c Copy the specified program to the remote system for
execution. If you omit this option the application
must be in the system path on the remote system.
-d Don't wait for process to terminate (non-interactive).
cmd Name of application to execute.
arguments Arguments to pass (note that file paths must be
absolute paths on the target system).
You can use pushd and popd to pass the the command through psexec for UNC paths.
psexec.exe //FQDN -d cmd /c "pushd \\UNCFOLDER\ && file2execute.exe && popd"

How to hide command prompt windows using ExecDos command

I want to execute three bat files in my script, the problem is when i run these .bat files directly using execwait, command windows gets open, I want to hide these command windows but its not working. My code is of just 3 lines.
ExecDos::exec '"catalina_start.bat"'
ExecDos::exec '"mysql_start.bat"'
ExecDos::exec '"apache_start.bat"'
I also tried this nsExec command but still no solution:
nsExec::Exec "cmd /C catalina_start.bat"
nsExec::Exec "cmd /C mysql_start.bat"
nsExec::Exec "cmd /C apache_start.bat"
A little background on these .bat files, Actually these are files of xampp setup, xampp internally uses these files to start tomcat, mysql, and apache.
The problem I am facing is that only first bat file gets executed, i. e. tomcat gets started (I can see that in xampp console), but then script dosen't move ahead, sql and apache is not getting started.
Does the batch-file contain pause or something else that prevents it from completing?
You should start off just by using something like ExecWait '"cmd.exe" /k "$InstDir\catalina_start.bat"' (or /c) so you can see the text written to the console including any errors. Once it works correctly you can switch to one of the exec plugins that hides the console...
You can change command windows from cmd /C catalina_start.bat to start /Min cmd /c catalina_start.bat it will hide command windows

Batch file doesn't continue until after I exit psexec remote connection

I'm trying to make a batch file to run a script on remote server. If I enter the commands below in the cmd prompt seperately it works fine but it seems to hang after I enter the psexec commands. It only continues the rest of the batch file when I exit the psexec remote connection. The rest of the commands are run on my local computer(which I don't want). Anyone have any ideas or suggestions?
psexec \\ServName -u DOMAIN\UserName -p password cmd.exe
pause
cd c:\Users\UserName
pause
cscript \\NetworkName\filepath\blankTest.vbs
You can bundle the commands into one batch file and then execute that using one line:
psexec \\ServName -u DOMAIN\UserName -p password cmd.exe -c mybatchfile.bat
That will cause the file to be copied to the remote machine first.
Alternatively if you have problems with that, copy the file first, then execute it; note the different parameter, /c vs -c:
copy mybatchfile.bat \\ServName\Admin$
psexec \\ServName -u DOMAIN\UserName -p password cmd.exe /c mybatchfile.bat
Personnaly if I want to start a background process in a batch I use this :
start /B cmd /C "mycommand" which in your case should give :
start /B cmd /C "psexec \\ServName -u DOMAIN\UserName -p password cmd.exe"

open command prompt window and change current working directory

I'm terribly new to scripting on windows. Using windows 7 64.
I'm trying to make a .bat file that I can double click, and have it open a command prompt and automatically cd me to a certain directory.
I tried making a .bat file with
#ECHO OFF
cmd "cd C:\my\destination"
Which opens what looks like a command prompt, but doesn't seem to let me type any commands.
I then tried:
#ECHO OFF
start cmd "cd C:\my\destination"
But this just sent me into a loop opening tons and tons of prompts until my computer crashed :) The .bat file was located in the destination directory if that matters.
This works for me:
#ECHO OFF
cmd.exe /K "cd C:\my\destination && C:"
The quoted string is actually two commands (separated by a double ampersand): The first command is to change to the specified directory, the second command is to change to the specified drive letter.
Put this in a batch (.BAT) file and when you execute it you should see a Command Prompt window at the specified directory.
Use the /K switch:
#ECHO OFF
start cmd.exe /K "cd C:\my\destination"
But IMHO, the most useful switch is /?.
Starts a new instance of the Windows XP command interpreter
CMD [/A | /U] [/Q] [/D] [/E:ON | /E:OFF] [/F:ON | /F:OFF] [/V:ON | /V:OFF]
[[/S] [/C | /K] string]
/C Carries out the command specified by string and then terminates
/K Carries out the command specified by string but remains
/S Modifies the treatment of string after /C or /K (see below)
/Q Turns echo off
...
And only if it does not work, then Google it, as #Neeraj suggested :D
This could be done like that:
#ECHO OFF
cd /D "C:\my\destination"
cmd.exe
If you need to execute a file or command after you open the cmd you can just replace the last line with:
cmd.exe /k myCommand
#ECHO OFF
%comspec% /K "cd /D d:\somefolder"
The /D will change folder and drive and works on 2000+ (Not sure about NT4)
If you take a look at Vista's open command here, it uses cmd.exe /s /k pushd \"%V\" but I don't think %V is documented. Using pushd is a good idea if your path is UNC (\\server\share\folder) To get UNC current directory working, you might have to set the DisableUNCCheck registry entry...
Why so complicated? Just create an alias to cmd.exe, right click on the alias and navigate to its settings. Change the "execute in" to the path you want to have as standard path. It will always start in this path.
just open a text editor and type
start cmd.exe
cd C:\desired path
Then save it as a .bat file. Works for me.
You can create a batch file "go-to-folder.bat" with the following statements:
rem changes the current directory
cd "C:\my\destination"
rem changes the drive if necessary
c:
rem runs CMD
cmd

Resources