Creating a cmd line shortcut - batch-file

I am completely new to Windows, as i am an OSX user.
I am having to run a task in the cmd line every day, is there any way i can create a shortcut on my desktop which automates this?
Task example, open cmd, then execute:
atomInstaller npm -view -Xmx8g -Xms3g
Thanks

You could just make a shortcut to cmd.exe and add command line switches:
https://superuser.com/questions/358565/adding-command-line-switches-to-windows-shortcuts
Or you can put commands into a batch file using notepad ( or a better text editor ):
#echo off
atomInstaller npm -view -Xmx8g -Xms3g
save it as npm.bat then double-click it..

You can use shortcutjs.bat:
call shortcutjs.bat -linkfile "%userprofile%\desktop\atominstaller.lnk" -target "C:\atomInstaller.bat" -adminpermissions yes -iconlocation "C:\Windows\System32\compstui.dll,3" -hotkey "Ctrl+Shift+M"
Here's the usage:
shortcutjs.bat -linkfile link -target target [-linkarguments linkarguments] [-description description] [-iconlocation iconlocation] [-hotkey hotkey] [-windowstyle 1|3|7] [-workingdirectory workingdirectory] [-adminpermissions yes|no]
You can add additional parameter with -linkarguments or start location with -workingdirectory

Related

Bat file for Windows 10 Custom Start Menu

I have a .bat file, (which makes a custom start menu from a custom .xml file), to deploy to a group of machines.
Here is what I got:
PowerShell.exe -Command "&Import-StartLayout –LayoutPath C:\Installs\StartMenu.xml –MountPath $env:SystemDrive\"
When I run the PowerShell command itself it works but for some reason I cannot get it to work from the .bat file.
Here are my comments, put together as an answer:
PowerShell -C "&{Import-StartLayout -LayoutPath C:\Installs\StartMenu.xml -MountPath %SystemDrive%\}"
I had to change my code to:
PowerShell.exe -Command "&{Import-StartLayout -LayoutPath C:\Installs\StartMenu.xml -MountPath $env:%SystemDrive%\}"
The suggestions from Compo seemed to work.

Windows 10 - Automatically exit batch script

This is my script:
SQLPLUS -S -M "HTML ON TABLE 'BORDER="2"'" username/pass#env #test.sql>test.html
After execution command prompt window stays open. How do I auto-close?
After your line of code add another line, like this:
exit
or
tskill cmd.exe
I hope I can help you.

ConEmu commands in task

I'm trying to get a Task in ConEmu to open several consoles, and for each run a batch-like script when opened. For example:
Open a Git Bash, name the console "X", set the current directory to "Y".
Open another Git Bash and run a set of commands, for example "cd A/B/C", "vagrant up"
Open a regular command window, run the command "cd D/E/F", "grunt watch"
I want the second and third consoles to appear alongside each other, but underneath the first console. So far I am stuck getting commands to run; I have a task that runs the following:
"%ProgramFiles(x86)%\Git\bin\sh.exe" --login -i "-cur_console:n:t:Git Bash" "-cur_console:d:C:\Users\Ole Vik\dev"
"%ProgramFiles(x86)%\Git\bin\sh.exe" --login -i "-cur_console:s1TVn:t:Vagrant"
cmd "-cur_console:s2THn:t:Third"
Reading the ConEmu wiki led me to the new_console and cur_console switches, but I'm having trouble figuring out if I can somehow enter commands in the Task setup, or maybe if I can have it run a .bat script on each console.
No colon is needed between switches (n & t for example).
cmd has /k switch to run commands.
I don't know the way to tell bash "run this command and stay in prompt". May be you need to run commands with &. I'm not sure about second line, you need to check it yourself.
"%ProgramFiles(x86)%\Git\bin\sh.exe" --login -i "-cur_console:nt:Git Bash" "-cur_console:d:C:\Users\Ole Vik\dev"
cmd -cur_console:s1TVnt:Vagrant /c vagrant up & "%ProgramFiles(x86)%\Git\bin\sh.exe" --login -i"
cmd -cur_console:s2THnt:Third /k cd /d "D\E\F" & grunt watch

.bat file to open executable within Console2

I am aiming to create a .bat launcher that will execute a command line .exe program within Console2.
My best guess would be that it should go something like:
#echo off
start "" Console.exe program.exe
but all that does it open Console2.
Please note that all .bat, and executables are all in the same folder.
Ok I looked in source for the Console.exe and drilled down into the compiled help.
You need a -r
So: Console.exe -r program.exe
Command line parameters
Console supports these command line parameters:
-c <configuration file>
Specifies a configuration file.
-w <main window title>
Sets main window title. This option will override all other main window title settings (e.g. 'use tab titles' setting)
-t <tab name>
Specifies a startup tab. Tab must be defined in Console settings.
-d <directory>
Specifies a startup directory. If you want to parametrize startup dirs, you need to specify startup directory parameter as "%1"\ (backslash is outside of the double quotes)
-r <command>
Specifies a startup shell command.
-ts <sleep time in ms>
Specifies sleep time between starting next tab if multiple -t's are specified.
I'd never heard of this program, but its source code
else if (wstring(argv[i]) == wstring(L"-r"))
{
// startup cmd
++i;
if (i == argc) break;
startupCmds.push_back(argv[i]);
}
makes it seem like you might want to try:
Console.exe -r program.exe

How do I run a .bat file from CMake?

How do I run a .bat file from CMake in a pre-link or a post-build event?
You could use add_custom_command, e.g.
if(WIN32)
add_custom_command(TARGET <Your target>
POST_BUILD
COMMAND cmd //C <path to .bat file> <ARGS> )
endif()
For full details about add_custom_command run
cmake --help-command add_custom_command
The following also works. In case you read or create a file inside the bat script don't forget to specify the exact path inside the bat script.
ADD_CUSTOM_TARGET(
myCustomTarget
COMMAND cmd /c E:/Myfiles/mytxt.bat
)
ADD_DEPENDENCIES(myTarget myCustomTarget)
myTarget will be executed after myCustomTarget.

Resources