Launch multiple programs with batch file - spaces in file path - windows

I am trying to make a batch file for launching multiple pieces of software, they are not located in C drive however, and some of the folders have spaces in the name.
So far I have this..Chrome is the only one working.
#echo off
cd C:\Program Files (x86)\Google\Chrome\Application
start chrome.exe
cd /d D:\WEBDEV\SourceTree
start SourceTree.exe
cd /d D:\WEBDEV\Sublime%%Text%%3
start sublime_text.exe
Thanks
Update - SourceTree works, sublime isn't because of the spaces in the name.
Update - I believe the underscore isn't working.
Last Update - Got it to work, if anyone was wondering.
#echo off
cd C:\Program Files (x86)\Google\Chrome\Application
start chrome.exe
cd /d D:\WEBDEV\SourceTree
start SourceTree.exe
cd /d D:\WEBDEV\"Sublime Text 3"
start sublime.exe

Got it to work, if anyone was wondering.
#echo off
cd C:\Program Files (x86)\Google\Chrome\Application
start chrome.exe
cd /d D:\WEBDEV\SourceTree
start SourceTree.exe
cd /d D:\WEBDEV\"Sublime Text 3"
start sublime.exe

Related

How to create a program that can rename an exe in program files and rename a folder in Windows registry

I'm new in this stuff! As far as I know when you install a program, the installer creates a folder in C:\Program Files with the contents of the application, and a folder appears in the windows registry with values it needs to work. I would like to create something like that that can rename an exe and rename a windows registry folder.
I already know how to rename an .exe with a .bat in the same folder:
#pushd "%~dp0" >nul 2>&1
#echo off
title Instalador
ren "Program1.exe" "Program2.exe"
#exit
And I tried using this line and opened regedit but idk how to change a folder's name with a command (for example renaming HKEY_LOCAL_MACHINE\SOFTWARE\Program1 to HKEY_LOCAL_MACHINE\SOFTWARE\Program2)
C:\Windows\regedit.exe
There is no rename command in regedit command line. All you can do is copy it to new name and then remove old one:
#echo off
echo Copying Program1 to Program2
ren path\to\program1.exe path\to\program2.exe
reg copy HKEY_LOCAL_MACHINE\SOFTWARE\Program1 HKEY_LOCAL_MACHINE\SOFTWARE\Program2 /s /f
reg delete HKEY_LOCAL_MACHINE\SOFTWARE\Program1 /f
/s means Copies all subkeys and values
/f means Forces the operation without prompt.

I am trying to change directory in CMD but it is not working. it will return to current directory, see this: [duplicate]

This question already has answers here:
how to change directory using Windows command line
(8 answers)
Closed 2 years ago.
C:\Users\vk Yadav>cd d:
D:\
C:\Users\vk Yadav>
Why it's happening?
cd means change directory. You don't use it to change drives. Typing cd D: tells you what the current directory is on drive D:.
To change drives, just type the new drive letter followed by :, as in D: and hit Enter.
To learn what cd does, type cd /? at a command prompt.
Reading cd /? help shows you that when changing directories to different drives requires /d option.
cd /d D:\
but using
cd /d D:
will only change to the drive with previous path, similar as standalone D: command
The command obviously works with appended folders.
cd /d "D:\Some Folder\"
If you only want to changes drives, then just doing
D:
Will change to the drive. But if you were in a specific directory on D: prior to swopping to C:\ then running D: will land you back in that dir. The following demonstrates this, you can test it yourself by copying it, add an actual directory name where I have Some Folder and paste into your cmd window.
echo off & cls
cd "%userprofile%"
cd
cd /d "D:\Some Folder\"
cd
D:
cd
C:
cd
cd /d D:
cd
cd /d C:
cd
cd /d D:\
cd
cd /d C:\
cd
Running the above on my system (note I use Z:\ instead of D:\)
So if you intend to only land exactly on the drive or drive\dir, then just use cd /d path
type D: and press enter. so you can move to D drive

How place file with bat command when ran from currenty directory

So I am trying to create a bat/exe installer for regjump. I am using a bat compiler so I can attach the "regjump.exe" to the installer.exe; so when the installer is ran, it will put regjump in the current directory of the installer.exe. I know I can use xcopy to place the file but I need help with the first half of the command. What is "local directory\regjump.exe" syntax?
cd C:\
xcopy "WHEREVER THE INSTALLER IS RAN FROM\regjump.exe" "C:\Windows\System32" /q /y /r
I want the syntax to be able to be ran from anywhere i.e. removable F:
Try this. You will need to execute as admin to write to "C:\Windows\System32", so this checks for that.
openfiles >nul 2>&1 || echo(You must execute this command as Administrator. & pause & goto :eof
set "SourceDir=%CD%
cd C:\
xcopy "%SourceDir%\regjump.exe" "C:\Windows\System32" /q /y /r

How to solve "The directory is not empty" error when running rmdir command in a batch script?

I am making a batch script and part of the script is trying to remove a directory and all of its sub-directories. I am getting an intermittent error about a sub-directory not being empty. I read one article about indexing being the culprit. I disabled WSearch but I eventually got the error again. Here's the command:
rmdir /S /Q "C:\<dir>\"
I experienced the same issues as Harry Johnston has mentioned. rmdir /s /q would complain that a directory was not empty even though /s is meant to do the emptying for you! I think it's a bug in Windows, personally.
My workaround is to del everything in the directory before deleting the directory itself:
del /f /s /q mydir 1>nul
rmdir /s /q mydir
(The 1>nul hides the standard output of del because otherwise, it lists every single file it deletes.)
I'm familiar with this problem. The simplest workaround is to conditionally repeat the operation. I've never seen it fail twice in a row - unless there actually is an open file or a permissions issue, obviously!
rd /s /q c:\deleteme
if exist c:\deleteme rd /s /q c:\deleteme
I just encountered the same problem and it had to do with some files being lost or corrupted. To correct the issue, just run check disk:
chkdsk /F e:
This can be run from the search windows box or from a cmd prompt. The /F fixes any issues it finds, like recovering the files. Once this finishes running, you can delete the files and folders like normal.
enter the Command Prompt as Admin and run
rmdir /s <FOLDER>
I had a similar problem, tried to delete an empty folder via windows explorer. Showed me the not empty error, so I thought I try it via admin cmd, but none of the answers here helped.
After I moved a file into the empty folder. I was able to delete the non empty folder
As #gfullam stated in a comment to #BoffinbraiN's answer, the <dir> you are deleting itself might not be the one which contains files: there might be subdirectories in <dir> that get a "The directory is not empty" message and the only solution then would be to recursively iterate over the directories, manually deleting all their containing files... I ended up deciding to use a port of rm from UNIX. rm.exe comes with Git Bash, MinGW, Cygwin, GnuWin32 and others. You just need to have its parent directory in your PATH and then execute as you would in a UNIX system.
Batch script example:
set PATH=C:\cygwin64\bin;%PATH%
rm -rf "C:\<dir>"
Im my case i just moved the folder to root directory like so.
move <source directory> c:\
And then ran the command to remove the directory
rmdir c:\<moved directory> /s /q
I had "C:\Users\User Name\OneDrive\Fonts", which was mklink'ed ( /D ) to "C:\Windows\Fonts", and I got the same problem. In my case
cd "C:\Users\User Name\OneDrive"
rd /s Fonts
Y (to confirm the action)
helped me. I hope, that it helps you too ;D
What worked for me is the following. I appears like the RMDir command will issue “The directory is not empty” nearly all the time...
:Cleanup_Temporary_Files_and_Folders
Erase /F /S /Q C:\MyDir
RMDir /S /Q C:\MyDir
If Exist C:\MyDir GoTo Cleanup_Temporary_Files_and_Folders
The reason rd /s refuses to delete certain files is most likely due to READONLY file attributes on files in the directory.
The proper way to fix this, is to make sure you reset the attributes on all files first:
attrib -r %directory% /s /d
rd /s %directory%
There could be others such as hidden or system files, so if you want to play it safe:
attrib -h -r -s %directory% /s /d
rd /s %directory%
Windows sometimes is "broken by design", so you need to create an empty folder, and then mirror the "broken folder" with an "empty folder" with backup mode.
robocopy - cmd copy utility
/copyall - copies everything
/mir deletes item if there is no such item in source a.k.a mirrors source with
destination
/b works around premissions shenanigans
Create en empty dir like this:
mkdir empty
overwrite broken folder with empty like this:
robocopy /copyall /mir /b empty broken
and then delete that folder
rd broken /s
rd empty /s
If this does not help, try restarting in "recovery mode with command prompt" by holding shift when clicking restart and trying to run these command again in recovery mode
one liner:
if exist folder rmdir /Q /S folder
I'm using this in a NPM script like so (Javascript) :
//package.json
"scripts": {
"start": "parcel --no-cache",
"clean": "if exist dist rmdir /Q /S dist",
"deploy": "npm run clean && parcel build --no-source-maps && firebase deploy"
},
Open CMD as administrator
chkdsk c: /F /R
Press the “Y” key if asked to check your disk the next time your system restarts.
Restart the machine. After that just delete the folder.
The easiest way I found to do this is:
rm -rf dir_name
it worked on zsh - macOS, it should work on windows cmd as well.
if you need to delete a folder on Windows with a batch file you will need to use PowerShell and this is how it is done:
rmdir .\directory_name\ -Recurse
Similar to Harry Johnston's answer, I loop until it works.
set dirPath=C:\temp\mytest
:removedir
if exist "%dirPath%" (
rd /s /q "%dirPath%"
goto removedir
)
Force delete the directory (if exists)
Delete.bat
set output_path="C:\Temp\MyFolder"
if exist %output_path% (
echo Deleting %output_path%
attrib -r /s /d %output_path%
rd /s /q %output_path%
)
I've fixed this before my making sure there wasn't extra whitespace in the name of the directory I was deleting. This is more of a concern when I had the directory name contained within a variable that I was passing to RD. If you're specifying your directly in quotes then this isn't helpful, but I hope that someone like me comes along with the same problem and sees this. RD /S /Q can work, as I noticed the issue started happening when I changed something in my batch script.
I can think of the following possible causes:
there are files or subdirectories which need higher permissions
there are files in use, not only by WSearch, but maybe by your virus scanner or anything else
For 1.) you can try runas /user:Administrator in order to get higher privileges or start the batch file as administrator via context menu. If that doesn't help, maybe even the administrator doesn't have the rights. Then you need to take over the ownership of the directory.
For 2.) download Process Explorer, click Find/Find handle or DLL... or press Ctrl+F, type the name of the directory and find out who uses it. Close the application which uses the directory, if possible.

Delete all .svn and .project files using windows registry

A the moment I have a registry file which delete the .svn files when right clicking over directory. I would like to extend this windows registry file to also delete some temporary files created from Zend Studio:
.buildpath
.project
.settings (directory)
Following the answers from this question: Windows batch file to delete .svn files and folders
I have:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\DeleteSVN]
#="Delete SVN Folders"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\DeleteSVN\command]
#="cmd.exe /c \"TITLE Removing SVN Folders in %1 && COLOR 9A && FOR /r \"%1\" %%f IN (.svn) DO RD /s /q \"%%f\" \""
I think this is what you are looking for. I only made changes to the last line.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\DeleteSVN]
#="Delete SVN Folders"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\DeleteSVN\command]
#="cmd.exe /c \"TITLE Removing SVN Folders in %1 && color 9A && for /r \"%~1\" %%F in (.) do (rd /s /q \"%%~fF\.svn\" \"%%~fF\.settings\" & del \"%%~fF\.buildpath\" \"%%~fF\.project\")2>nul \""
This solution is similar to what Laf was describing, except he suggested using && before the last command. I think that could give you problems because the next command would only execute if the RD was successful. But your current algorithm attempts to remove the directory from all subdirectories, even when it is not there. I used & so that the next command (DEL) always executes, regardless of the outcome of the RD. I extended the RD to delete both directories, and the added DEL command deletes both files.
I redirected stderr to nul so that you don't see a bunch of error messages. The algorithm is very inefficient and can generate a lot of error messages depending on the number of subdirectories.
If your requirements get any more complicated, or if you want to develop a more efficient script, you might be better off creating a batch file that does the work, and call the batch file from your registry entry. It's a bit messy to read and maintain a complicated set of commands on a single line. The escape sequences also become tiresome in the registry.
Some details on the command currently implemented:
cmd.exe /c: will call a new command interpreter, and execute the command that follows, then will quit (that's what /C does). The rest of the command (between the first and the last \" is the command that will be carried out by the command interpretter)
TITLE Removing SVN Folders in %1: Changes the title of the command interpreter to "Removing SVN Folders in folder".
COLOR 9A: changes the color scheme of your command interpreter
FOR /r \"%1\" %%f IN (.svn) DO RD /s /q \"%%f\": will delete all folders named .svn in the current folder.
%1 represent the folder on which you have right-clicked. The && between the commands means that the command interpreter will execute all three commands one after another. What you should do is to add your own command at the end of the command-line, like:
#="cmd.exe /c \"TITLE Removing SVN Folders in %1 && COLOR 9A && FOR /r \"%1\" %%f IN (.svn) DO RD /s /q \"%%f\" && *MyCommand*\""
where MyCommand is the command you need to delete the temporary files.

Resources