Help Automatating CMD Commands

Pedroc1999

Banned
Local time
3:59 PM
Messages
1,155
Location
Merthyr Tydfil, Wales
I need help making a CMD script that will...

Open a certain directory
clear the screen
run a command

and then it must stay open


how would i do this?
 

My Computer

Computer Manufacturer/Model Number
Packard Bell iMedia 2218 -- Has Been Running For Almost 7 Years!
OS
Windows 7 Ultimate x86
CPU
Intel Pentium D 925 @ 3.00GHz
Motherboard
Socket 775 MCP73VT-PM
Memory
1GB DDR2 667MHz
Graphics Card(s)
Overclocked Asus ATI Radeon X1600 Pro 512MB
Sound Card
Sound Blaster Audigy 570
Monitor(s) Displays
19" LCD Monitor; MW19E-AAA
Screen Resolution
1440 x 900
Hard Drives
500gb 7200rpm (Windows 7) ---
160gb 7200rpm (Backup) ---
1TB Iomega External Drive (7200rpm)
PSU
250w Packard Bell Standard
Case
Packard Bell standard
Cooling
Intel Socket 775 Air Cooler
Keyboard
Wired PS/2 Keyboard
Mouse
Dell Wireless USB Mouse
Internet Speed
Wireles --- Download - 6.63 Mbps Upload - 0.38 Mbps
Other Info
Currently Planning To Build New Computer --- Also Got A Samsung Galaxy Ace II (Plays All Games You Throw At It)
Hello Pedro,

You could use this in a .bat or .cmd file to do so. CLS will clear the screen in the command prompt. Pause will leave the command prompt open until you press a key to close it.

Code:
cd "[COLOR=red][B]full path of directory[/B][/COLOR]"
 
CLS
 
[B][COLOR=red]your command[/COLOR][/B]
 
pause

Hope this helps, :)
Shawn
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Self built custom
OS
64-bit Windows 11 Pro for Workstations
CPU
Intel i7-8700K OC'd to 5 GHz
Motherboard
ASUS ROG Maximus XI Formula Z390
Memory
64 GB (4x16GB) G.SKILL TridentZ RGB DDR4 3600 MHz
Graphics Card(s)
ASUS ROG-STRIX-GTX1080TI-O11G-GAMING
Sound Card
Integrated
Monitor(s) Displays
2 x Samsung Odyssey G7 27"
Screen Resolution
2560x1440
Hard Drives
1TB Samsung 990 PRO M.2,
4TB Samsung 990 PRO PRO M.2,
TerraMaster F8 SSD Plus NAS
PSU
Seasonic Prime Titanium 850W
Case
Thermaltake Core P3
Cooling
Corsair Hydro H115i
Keyboard
Logitech wireless K800
Mouse
Logitech MX Master 4
Internet Speed
2 Gb/s Download and 100 Mb/s Upload
Antivirus
Malwarebyte Anti-Malware Premium
Browser
Google Chrome
Other Info
Logitech Z625 speaker system,
Logitech BRIO 4K Pro webcam,
HP Color LaserJet Pro MFP M477fdn,
APC SMART-UPS RT 1000 XL - SURT1000XLI,
Galaxy S23 Plus phone
You can make a batch file

Cd (directory)
Start cmd.exe

This will open a new command prompt in the directory.
 

My Computer

OS
Windows 7 Ultimate x64
i got it anyway after a bit of fiddeling.

Code:
echo off
cd C:\android-sdk-windows\platform-tools
cls
adb devices
echo off
ping 1.0.0.0 -n 1 -w 5000 >NUL

how would i make a batch file that detects a usb flash drive
prompts me to copy files
copies files
reports back
and then closes
 

My Computer

Computer Manufacturer/Model Number
Packard Bell iMedia 2218 -- Has Been Running For Almost 7 Years!
OS
Windows 7 Ultimate x86
CPU
Intel Pentium D 925 @ 3.00GHz
Motherboard
Socket 775 MCP73VT-PM
Memory
1GB DDR2 667MHz
Graphics Card(s)
Overclocked Asus ATI Radeon X1600 Pro 512MB
Sound Card
Sound Blaster Audigy 570
Monitor(s) Displays
19" LCD Monitor; MW19E-AAA
Screen Resolution
1440 x 900
Hard Drives
500gb 7200rpm (Windows 7) ---
160gb 7200rpm (Backup) ---
1TB Iomega External Drive (7200rpm)
PSU
250w Packard Bell Standard
Case
Packard Bell standard
Cooling
Intel Socket 775 Air Cooler
Keyboard
Wired PS/2 Keyboard
Mouse
Dell Wireless USB Mouse
Internet Speed
Wireles --- Download - 6.63 Mbps Upload - 0.38 Mbps
Other Info
Currently Planning To Build New Computer --- Also Got A Samsung Galaxy Ace II (Plays All Games You Throw At It)
The adb app does not require the cd line and you might like pause better than ping... or not.

Code:
echo off
cls
C:\android-sdk-windows\platform-tools\adb.exe devices
pause

...detect a usb drive via batch file?

Are you wanting this batch file to run all of the time? ...always watching for a usb drive?
Will it always be the same usb drive that this batch file is looking for?
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Employer provided Dell Latitude
OS
W7 Pro SP1 64bit
CPU
i7
Memory
8GB
Graphics Card(s)
Intel HD Graphics
Hard Drives
crappy SSD
Antivirus
Employer mandated Symantec Endpoint Protection
Browser
Pale Moon 64bit, IE11 64bit & Chrome 64bit
Ok i got it. I made this yesterday and it is quite complicated...
I will post the batch later for viewing purposes.

How would i make a batch file to ask the user for his username,drive lettrs etc. Then it would make a backup of the above file.it would then modify certain lines in the above files and replace them with the inputed username etc
 

My Computer

Computer Manufacturer/Model Number
Packard Bell iMedia 2218 -- Has Been Running For Almost 7 Years!
OS
Windows 7 Ultimate x86
CPU
Intel Pentium D 925 @ 3.00GHz
Motherboard
Socket 775 MCP73VT-PM
Memory
1GB DDR2 667MHz
Graphics Card(s)
Overclocked Asus ATI Radeon X1600 Pro 512MB
Sound Card
Sound Blaster Audigy 570
Monitor(s) Displays
19" LCD Monitor; MW19E-AAA
Screen Resolution
1440 x 900
Hard Drives
500gb 7200rpm (Windows 7) ---
160gb 7200rpm (Backup) ---
1TB Iomega External Drive (7200rpm)
PSU
250w Packard Bell Standard
Case
Packard Bell standard
Cooling
Intel Socket 775 Air Cooler
Keyboard
Wired PS/2 Keyboard
Mouse
Dell Wireless USB Mouse
Internet Speed
Wireles --- Download - 6.63 Mbps Upload - 0.38 Mbps
Other Info
Currently Planning To Build New Computer --- Also Got A Samsung Galaxy Ace II (Plays All Games You Throw At It)
Helping you might be simpler if you would detail what your plans are. I can only assume that you want to copy files from a usb stick to a user's "my doc..." area.

~~~
How would i make a batch file to ask the user for his username,drive letters etc....
Code:
echo off
set /p SomeName=
echo %SomeName%
pause
You could also just use the variable %username% which will return the name of the person currently logged on.
Code:
echo off
echo %username%
pause
Be aware that people can change their username.
I can be logged on as Fred and my files are under C:\Users\Bob\...
The variable %username% will return Fred...
...but you might want Bob for the path info.

You might find this code more useful:
Code:
echo off
echo %homepath%
pause
Also be aware that some usernames have spaces in them:
C:\Users\Tony the Tiger\...
Which means that you should put quotation marks around the path even if you don't need them for most users.


~~~
Then it would make a backup of the above file.it would then modify certain lines in the above files and replace them with the inputed username etc
Code:
echo %SomeName% > test.bat
echo SomeInfo >> test.bat
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Employer provided Dell Latitude
OS
W7 Pro SP1 64bit
CPU
i7
Memory
8GB
Graphics Card(s)
Intel HD Graphics
Hard Drives
crappy SSD
Antivirus
Employer mandated Symantec Endpoint Protection
Browser
Pale Moon 64bit, IE11 64bit & Chrome 64bit
ok so this is the long version

i am trying to make a batch file to backup all the files on my phone to my documents - i have finished this bit, tested and all is working

i want to publicate this batch so everyone can use it.That means making a 'setup.cmd' that will edit the actual backup batch to suit the users needs. the %username% command you suggested will be used to determin the actual username, but i need a way for the user to specify where his internal sdcard and external sdcard are and adjusting the file accordinly. i will upload the file so you can view it
 

Attachments

My Computer

Computer Manufacturer/Model Number
Packard Bell iMedia 2218 -- Has Been Running For Almost 7 Years!
OS
Windows 7 Ultimate x86
CPU
Intel Pentium D 925 @ 3.00GHz
Motherboard
Socket 775 MCP73VT-PM
Memory
1GB DDR2 667MHz
Graphics Card(s)
Overclocked Asus ATI Radeon X1600 Pro 512MB
Sound Card
Sound Blaster Audigy 570
Monitor(s) Displays
19" LCD Monitor; MW19E-AAA
Screen Resolution
1440 x 900
Hard Drives
500gb 7200rpm (Windows 7) ---
160gb 7200rpm (Backup) ---
1TB Iomega External Drive (7200rpm)
PSU
250w Packard Bell Standard
Case
Packard Bell standard
Cooling
Intel Socket 775 Air Cooler
Keyboard
Wired PS/2 Keyboard
Mouse
Dell Wireless USB Mouse
Internet Speed
Wireles --- Download - 6.63 Mbps Upload - 0.38 Mbps
Other Info
Currently Planning To Build New Computer --- Also Got A Samsung Galaxy Ace II (Plays All Games You Throw At It)
Ok i done it now and will publish tomorow. I am on my phone so i havnt got the file here.this is my first batch i make and it turned out to be 3500+words so i started big.now my phone is safely backed up. I still need a way to access the system folder for complete backup
 

My Computer

Computer Manufacturer/Model Number
Packard Bell iMedia 2218 -- Has Been Running For Almost 7 Years!
OS
Windows 7 Ultimate x86
CPU
Intel Pentium D 925 @ 3.00GHz
Motherboard
Socket 775 MCP73VT-PM
Memory
1GB DDR2 667MHz
Graphics Card(s)
Overclocked Asus ATI Radeon X1600 Pro 512MB
Sound Card
Sound Blaster Audigy 570
Monitor(s) Displays
19" LCD Monitor; MW19E-AAA
Screen Resolution
1440 x 900
Hard Drives
500gb 7200rpm (Windows 7) ---
160gb 7200rpm (Backup) ---
1TB Iomega External Drive (7200rpm)
PSU
250w Packard Bell Standard
Case
Packard Bell standard
Cooling
Intel Socket 775 Air Cooler
Keyboard
Wired PS/2 Keyboard
Mouse
Dell Wireless USB Mouse
Internet Speed
Wireles --- Download - 6.63 Mbps Upload - 0.38 Mbps
Other Info
Currently Planning To Build New Computer --- Also Got A Samsung Galaxy Ace II (Plays All Games You Throw At It)
'sleep' is not recognized as an internal or external command, operable program or batch file.

I would use %homepath% instead of %username%.

Using dates for the folders is good - but I would create a path more like:

...\year\month\day-time
or
...\year-month-day-time

Those folder structures will sort better.

I do not want to discourage you from learning/using command line batch files, but if you are going to be giving this to others, you might want to learn a scripting language like AutoHotKey or AutoIt.
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Employer provided Dell Latitude
OS
W7 Pro SP1 64bit
CPU
i7
Memory
8GB
Graphics Card(s)
Intel HD Graphics
Hard Drives
crappy SSD
Antivirus
Employer mandated Symantec Endpoint Protection
Browser
Pale Moon 64bit, IE11 64bit & Chrome 64bit

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Employer provided Dell Latitude
OS
W7 Pro SP1 64bit
CPU
i7
Memory
8GB
Graphics Card(s)
Intel HD Graphics
Hard Drives
crappy SSD
Antivirus
Employer mandated Symantec Endpoint Protection
Browser
Pale Moon 64bit, IE11 64bit & Chrome 64bit
Thank you. I got the sleep command from windows resource kit tools which i found is a must.my batch will check for its existance and let you continue the backup if you have it and launch the installer if it isnt found.i have to ask what ste those extra tools for.....i have some understanding of LUA is it possible to run lua commands from cmd
 

My Computer

Computer Manufacturer/Model Number
Packard Bell iMedia 2218 -- Has Been Running For Almost 7 Years!
OS
Windows 7 Ultimate x86
CPU
Intel Pentium D 925 @ 3.00GHz
Motherboard
Socket 775 MCP73VT-PM
Memory
1GB DDR2 667MHz
Graphics Card(s)
Overclocked Asus ATI Radeon X1600 Pro 512MB
Sound Card
Sound Blaster Audigy 570
Monitor(s) Displays
19" LCD Monitor; MW19E-AAA
Screen Resolution
1440 x 900
Hard Drives
500gb 7200rpm (Windows 7) ---
160gb 7200rpm (Backup) ---
1TB Iomega External Drive (7200rpm)
PSU
250w Packard Bell Standard
Case
Packard Bell standard
Cooling
Intel Socket 775 Air Cooler
Keyboard
Wired PS/2 Keyboard
Mouse
Dell Wireless USB Mouse
Internet Speed
Wireles --- Download - 6.63 Mbps Upload - 0.38 Mbps
Other Info
Currently Planning To Build New Computer --- Also Got A Samsung Galaxy Ace II (Plays All Games You Throw At It)
here is the near final version.

download the 2 files
rename batch to .cmd (this is only because sevenfroums wont let me upload .cmd files
put the 2 files in one folder
run the cmd file (previously batch)



how woudl i do the day-month-year-time thing?
 

My Computer

Computer Manufacturer/Model Number
Packard Bell iMedia 2218 -- Has Been Running For Almost 7 Years!
OS
Windows 7 Ultimate x86
CPU
Intel Pentium D 925 @ 3.00GHz
Motherboard
Socket 775 MCP73VT-PM
Memory
1GB DDR2 667MHz
Graphics Card(s)
Overclocked Asus ATI Radeon X1600 Pro 512MB
Sound Card
Sound Blaster Audigy 570
Monitor(s) Displays
19" LCD Monitor; MW19E-AAA
Screen Resolution
1440 x 900
Hard Drives
500gb 7200rpm (Windows 7) ---
160gb 7200rpm (Backup) ---
1TB Iomega External Drive (7200rpm)
PSU
250w Packard Bell Standard
Case
Packard Bell standard
Cooling
Intel Socket 775 Air Cooler
Keyboard
Wired PS/2 Keyboard
Mouse
Dell Wireless USB Mouse
Internet Speed
Wireles --- Download - 6.63 Mbps Upload - 0.38 Mbps
Other Info
Currently Planning To Build New Computer --- Also Got A Samsung Galaxy Ace II (Plays All Games You Throw At It)
im sorry but i cant upload the files because they are too big
 

My Computer

Computer Manufacturer/Model Number
Packard Bell iMedia 2218 -- Has Been Running For Almost 7 Years!
OS
Windows 7 Ultimate x86
CPU
Intel Pentium D 925 @ 3.00GHz
Motherboard
Socket 775 MCP73VT-PM
Memory
1GB DDR2 667MHz
Graphics Card(s)
Overclocked Asus ATI Radeon X1600 Pro 512MB
Sound Card
Sound Blaster Audigy 570
Monitor(s) Displays
19" LCD Monitor; MW19E-AAA
Screen Resolution
1440 x 900
Hard Drives
500gb 7200rpm (Windows 7) ---
160gb 7200rpm (Backup) ---
1TB Iomega External Drive (7200rpm)
PSU
250w Packard Bell Standard
Case
Packard Bell standard
Cooling
Intel Socket 775 Air Cooler
Keyboard
Wired PS/2 Keyboard
Mouse
Dell Wireless USB Mouse
Internet Speed
Wireles --- Download - 6.63 Mbps Upload - 0.38 Mbps
Other Info
Currently Planning To Build New Computer --- Also Got A Samsung Galaxy Ace II (Plays All Games You Throw At It)
You might want to consider setting up variables at the beginning with constants. That way you have just one place to change the values.
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
HP Pavillion dv6 (dv6-6165dx)
OS
Windows 7 Home Premium x64
CPU
AMD Vision A8-3500M 4 Core
Motherboard
AMD
Memory
8Gb
Graphics Card(s)
AMD Radeon HD 6620G
Screen Resolution
1366x768
Hard Drives
Hitachi Travelstar 500Gb
Internet Speed
Realtek RTL8188CE 802.11b/g/n
I have done that. Il have to upload it mediafire so you guys can see it
 

My Computer

Computer Manufacturer/Model Number
Packard Bell iMedia 2218 -- Has Been Running For Almost 7 Years!
OS
Windows 7 Ultimate x86
CPU
Intel Pentium D 925 @ 3.00GHz
Motherboard
Socket 775 MCP73VT-PM
Memory
1GB DDR2 667MHz
Graphics Card(s)
Overclocked Asus ATI Radeon X1600 Pro 512MB
Sound Card
Sound Blaster Audigy 570
Monitor(s) Displays
19" LCD Monitor; MW19E-AAA
Screen Resolution
1440 x 900
Hard Drives
500gb 7200rpm (Windows 7) ---
160gb 7200rpm (Backup) ---
1TB Iomega External Drive (7200rpm)
PSU
250w Packard Bell Standard
Case
Packard Bell standard
Cooling
Intel Socket 775 Air Cooler
Keyboard
Wired PS/2 Keyboard
Mouse
Dell Wireless USB Mouse
Internet Speed
Wireles --- Download - 6.63 Mbps Upload - 0.38 Mbps
Other Info
Currently Planning To Build New Computer --- Also Got A Samsung Galaxy Ace II (Plays All Games You Throw At It)
....i have to ask what ste those extra tools for.....i have some understanding of LUA is it possible to run lua commands from cmd
If you use a scripting tool like AutoIt (or AutoHotKey) you can write a script to do what you want without the user dealing with a command line interface.

For instance - your script can start when Windows starts and run all of the time (always watching for the phone to be connected). Once the phone connects, a tray tip (balloon) could popup reminding the user to backup the phone's files.... prompting the user to press a certain key combo to start the backup process.

LUA is not normally used as part of an AutoIt script. You don't need to know anything about LUA to use AutoIt. LUA is used by AutoIt devs to customize how the SCiTE editor supports writing and debugging the AutoIt code as you write/test your script. You don't have to use SCiTE - you can use Notepad to write scripting code if you want.

Again, I don't want to point you away from working with the command line interface (CLI) - too few people are learning that interface these days... but once you have things working as desired via CLI, consider recoding it using AutoIt or AutoHotKey to make your backup tool more user friendly.
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Employer provided Dell Latitude
OS
W7 Pro SP1 64bit
CPU
i7
Memory
8GB
Graphics Card(s)
Intel HD Graphics
Hard Drives
crappy SSD
Antivirus
Employer mandated Symantec Endpoint Protection
Browser
Pale Moon 64bit, IE11 64bit & Chrome 64bit
is there some sort of tool that can convert my batch into a autoitfile without having to write the script out again
 

My Computer

Computer Manufacturer/Model Number
Packard Bell iMedia 2218 -- Has Been Running For Almost 7 Years!
OS
Windows 7 Ultimate x86
CPU
Intel Pentium D 925 @ 3.00GHz
Motherboard
Socket 775 MCP73VT-PM
Memory
1GB DDR2 667MHz
Graphics Card(s)
Overclocked Asus ATI Radeon X1600 Pro 512MB
Sound Card
Sound Blaster Audigy 570
Monitor(s) Displays
19" LCD Monitor; MW19E-AAA
Screen Resolution
1440 x 900
Hard Drives
500gb 7200rpm (Windows 7) ---
160gb 7200rpm (Backup) ---
1TB Iomega External Drive (7200rpm)
PSU
250w Packard Bell Standard
Case
Packard Bell standard
Cooling
Intel Socket 775 Air Cooler
Keyboard
Wired PS/2 Keyboard
Mouse
Dell Wireless USB Mouse
Internet Speed
Wireles --- Download - 6.63 Mbps Upload - 0.38 Mbps
Other Info
Currently Planning To Build New Computer --- Also Got A Samsung Galaxy Ace II (Plays All Games You Throw At It)
Not that I know of.
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Employer provided Dell Latitude
OS
W7 Pro SP1 64bit
CPU
i7
Memory
8GB
Graphics Card(s)
Intel HD Graphics
Hard Drives
crappy SSD
Antivirus
Employer mandated Symantec Endpoint Protection
Browser
Pale Moon 64bit, IE11 64bit & Chrome 64bit
ok, if i do stick with batch (which i might as learning a new language isnt exactly easy) Is there a program that can at least give it a gui so it looks a bit better?
 

My Computer

Computer Manufacturer/Model Number
Packard Bell iMedia 2218 -- Has Been Running For Almost 7 Years!
OS
Windows 7 Ultimate x86
CPU
Intel Pentium D 925 @ 3.00GHz
Motherboard
Socket 775 MCP73VT-PM
Memory
1GB DDR2 667MHz
Graphics Card(s)
Overclocked Asus ATI Radeon X1600 Pro 512MB
Sound Card
Sound Blaster Audigy 570
Monitor(s) Displays
19" LCD Monitor; MW19E-AAA
Screen Resolution
1440 x 900
Hard Drives
500gb 7200rpm (Windows 7) ---
160gb 7200rpm (Backup) ---
1TB Iomega External Drive (7200rpm)
PSU
250w Packard Bell Standard
Case
Packard Bell standard
Cooling
Intel Socket 775 Air Cooler
Keyboard
Wired PS/2 Keyboard
Mouse
Dell Wireless USB Mouse
Internet Speed
Wireles --- Download - 6.63 Mbps Upload - 0.38 Mbps
Other Info
Currently Planning To Build New Computer --- Also Got A Samsung Galaxy Ace II (Plays All Games You Throw At It)
Back
Top