execute 2 commands in File shortcut - windows

I am using Windows 7 professional.
I have auto generated file shortcut for the program.
I need to delete one folder before starting the program every time.
Can I automatize it without creating .bat file? e.g. using this command del \directory\path\* /g "C:\Program Files (x86)\program.exe" in the shortcut properties.

Yes you can do this:
C:\Windows\System32\cmd.exe /C "del \directory\path\* /Q & "C:\Program Files (x86)\program.exe"
The & sign tells the shell to run several commands in sequence.

Related

How to open all files in a directory from command prompt

I wan't to open up every excel file in a certain folder using the windows command prompt. I know I can do this if I know the name of each file, but I want to just open all as the file names might change. Thanks.
for %1 in (*.xlsx) do start excel "%%1"
In the command prompt, you can execute the above command which opens all the excel sheets in the current directory. You could store this as batch file by giving full path too
for %1 in (<path>\*.xlsx) do start excel "%%1"
Edit: As #CristiFati noted, if the excel is not there in the path,
for %1 in (<path>\*.xlsx) do "C:\Program Files (x86)\Microsoft Office\Office16\EXCEL.exe" "%%1"
Navigate to the folder in command prompt.
Then run the following command
FOR %F IN (*.*) DO START %F
Credit goes to here:
https://superuser.com/questions/1503993/cmd-command-to-open-all-files-in-a-subdirectory

Batch file wrapped as an IExpress executable does not run properly

I have used iexpress to wrap a .bat file within an .EXE file.
The .bat file contains commands to install my project on Windows.
I followed all the steps and I got an .exe file, but when run it shows a finished msg but nothing is done. (no command inside the bat file is running).
#echo off
echo %DATE% >> "C:\Users\gaubansa\Desktop\my.txt"
echo %PATH% >> "C:\Users\gaubansa\Desktop\my.txt"
Cotnets of the .SED file:
[Version]
Class=IEXPRESS
SEDVersion=3
[Options]
PackagePurpose=InstallApp
ShowInstallProgramWindow=1
HideExtractAnimation=0
UseLongFileName=0
InsideCompressed=0
CAB_FixedSize=0
CAB_ResvCodeSigning=0
RebootMode=N
InstallPrompt=%InstallPrompt%
DisplayLicense=%DisplayLicense%
FinishMessage=%FinishMessage%
TargetName=%TargetName%
FriendlyName=%FriendlyName%
AppLaunched=%AppLaunched%
PostInstallCmd=%PostInstallCmd%
AdminQuietInstCmd=%AdminQuietInstCmd%
UserQuietInstCmd=%UserQuietInstCmd%
SourceFiles=SourceFiles
[Strings]
InstallPrompt=Write
DisplayLicense=
FinishMessage=ho gya
TargetName=C:\Users\gaubansa\Desktop\my.EXE
FriendlyName=Write
AppLaunched=cmd.exe /c my_personal.bat
PostInstallCmd=<None>
AdminQuietInstCmd=
UserQuietInstCmd=
FILE0="my_personal.bat"
[SourceFiles]
SourceFiles0=C:\Users\gaubansa\Desktop\
[SourceFiles0]
%FILE0%=
According to the Iexpress directive (.SED) file you posted, the problem is that you configured Iexpress to store file names in the package using short file names so your batch file my_personal.bat will be stored in the package using its short file name MY_PER~1.BAT but you have specified cmd /c my_personal.bat to run your batch file so cmd can not find my_personal.bat.
To resolve that choose the option Store files using Long File Name inside Package in Iexpress. Alternatively you can edit the SED file and change the directive UseLongFileName=0 to UseLongFileName=1 then in Iexpress GUI select Open existing Self Extraction Directive file
Some additional advise
Although your batch file name does not contain spaces or other special characters it is always a good practice to enclose the file name in quotes. So you should change AppLaunched=cmd.exe /c my_personal.bat to AppLaunched=cmd.exe /d /c "my_personal.bat"
The /d switch is optional, it is to prevent cmd from executing commands that may be present cmd's AutoRun registry settings. You can get more information about it by typing CMD /? at command prompt.
A safer option would be use AppLaunched=cmd.exe /d /s /c ""my_personal.bat"" so in future if you ever decide to repackage your batch file and pass some quoted parameter to it, you can do that without the risk of essential quotation marks being removed by cmd.
for example: cmd.exe /d /s /c ""my_personal.bat" "Quoted Param1" "Quoted Param2" UnquotedParam3"

startup batch file hangs up on second command

I created a startup bat file that looks like this
taskkill /im RemoteDesktopManager.exe
C:\Users\kheradmand\AppData\Local\Google\Chrome\Application\chrome.exe
"C:\Program Files (x86)\JetBrains\PhpStorm 7.1.2\bin\PhpStorm.exe"
"C:\Program Files\Mozilla Firefox\firefox.exe"
it does the first and second, but won't go any further, they all exist
how can I fix this?
update : I tried suggestion provided by #phd443322 and wrote this:
taskkill /im RemoteDesktopManager.exe
start "" /w C:\Users\kheradmand\AppData\Local\Google\Chrome\Application\chrome.exe
start "" /w "C:\Program Files (x86)\JetBrains\PhpStorm 7.1.2\bin\PhpStorm.exe"
start "" /w "C:\Program Files\Mozilla Firefox\firefox.exe"
intrestingly each command still waits for that program to be closed to continue to the next.
so why still not working?
Below there is a working Batch file, as first advised by phd443322:
taskkill /im RemoteDesktopManager.exe
start "" C:\Users\kheradmand\AppData\Local\Google\Chrome\Application\chrome.exe
start "" "C:\Program Files (x86)\JetBrains\PhpStorm 7.1.2\bin\PhpStorm.exe"
start "" "C:\Program Files\Mozilla Firefox\firefox.exe"
Batch files wait for programs to exit unlike interactive. These are the rules documented in the Start command.
If Command Extensions are enabled, external command invocation
through the command line or the START command changes as follows:
non-executable files may be invoked through their file association just
by typing the name of the file as a command. (e.g. WORD.DOC would
launch the application associated with the .DOC file extension).
See the ASSOC and FTYPE commands for how to create these
associations from within a command script.
When executing an application that is a 32-bit GUI application, CMD.EXE
does not wait for the application to terminate before returning to
the command prompt. This new behavior does NOT occur if executing
within a command script.
When executing a command line whose first token is the string "CMD "
without an extension or path qualifier, then "CMD" is replaced with
the value of the COMSPEC variable. This prevents picking up CMD.EXE
from the current directory.
When executing a command line whose first token does NOT contain an
extension, then CMD.EXE uses the value of the PATHEXT
environment variable to determine which extensions to look for
and in what order. The default value for the PATHEXT variable
is:
.COM;.EXE;.BAT;.CMD
Notice the syntax is the same as the PATH variable, with
semicolons separating the different elements.
When searching for an executable, if there is no match on any extension,
then looks to see if the name matches a directory name. If it does, the
START command launches the Explorer on that path. If done from the
command line, it is the equivalent to doing a CD /D to that path.

Running vbscript from batch file

I just need to write a simple batch file just to run a vbscript. Both the vbscript and the batch file are in the same folder and is in the SysWOW64 directory as the vbscript can only be execute in that directory. Currently my batch file is as follows:
#echo off
%WINDIR%\SysWOW64\cmd.exe
cscript necdaily.vbs
But the vbscript wasn't executed and just the command prompt is open. Can anyone tell me how can i execute the vbscript when i run this batch file?
You can use %~dp0 to get the path of the currently running batch file.
Edited to change directory to the VBS location before running
If you want the VBS to synchronously run in the same window, then
#echo off
pushd %~dp0
cscript necdaily.vbs
If you want the VBS to synchronously run in a new window, then
#echo off
pushd %~dp0
start /wait "" cmd /c cscript necdaily.vbs
If you want the VBS to asynchronously run in the same window, then
#echo off
pushd %~dp0
start /b "" cscript necdaily.vbs
If you want the VBS to asynchronously run in a new window, then
#echo off
pushd %~dp0
start "" cmd /c cscript necdaily.vbs
This is the command for the batch file and it can run the vbscript.
C:\Windows\SysWOW64\cmd.exe /c cscript C:\Windows\SysWOW64\...\necdaily.vbs
Just try this code:
start "" "C:\Users\DiPesh\Desktop\vbscript\welcome.vbs"
and save as .bat, it works for me
Batch files are processed row by row and terminate whenever you call an executable directly.
- To make the batch file wait for the process to terminate and continue, put call in front of it.
- To make the batch file continue without waiting, put start "" in front of it.
I recommend using this single line script to accomplish your goal:
#call cscript "%~dp0necdaily.vbs"
(because this is a single line, you can use # instead of #echo off)
If you believe your script can only be called from the SysWOW64 versions of cmd.exe, you might try:
#%WINDIR%\SysWOW64\cmd.exe /c call cscript "%~dp0necdaily.vbs"
If you need the window to remain, you can replace /c with /k
Well i am trying to open a .vbs within a batch file without having to click open but the answer to this question is ...
SET APPDATA=%CD%
start (your file here without the brackets with a .vbs if it is a vbd file)
You should put your .bat file in the same folder as your .vbs file and call the following code inside the .bat file.
start cscript C:\filePath\File.vbs

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