I have the following line in a BAT file, it does not work, how do I make it work? The shortcut is in the same directory as the BAT file, I have to move it to the desktop.
MOVE "MyShortCut.Ink" C:\
shortcut files have a .LNK extension ("LINK"). You've got INK as in "my pen broke and spilled ink all over my shirt".
In Windows, C:\ is not the the desktop. C:\Users\[Username]\Desktop is usually what you're looking for.
There is an environment variable for C:\Users\[Username] for the currently logged in user which is %USERPROFILE%.
If your running it from another directory, switch to the bat files executing path first;
CD %~dp0
MOVE "MyShortCut.Lnk" "%USERPROFILE%\Desktop"
Related
I have a batch file that's in my desktop and it works properly when I execute it using double click. But when I execute it using a task scheduler or run as administrator, the working directory changes to C:\Windows\system32 and it doesn't work properly.
What's the reason why it happens and how do I retain the working directory?
Put this line at the top of your bat file:
pushd %~dp0
See this post for details
Difference between "%~dp0" and ".\"?
I'm attempting to write a batch file that will move to the specified directory and then run the command to open my desired program. Specifically I want it to run the command HardwareSimulator so it will open the software nand2tetris provides.
I've gotten it to move to the directory I want, but the opening is my issue. Code is displayed below. I'm guessing start isn't the correct command since when I run, it just runs an infinite loop of opening cmd prompts.
My second question would be: can I only go into sub-directories of where my batch file is already stored? It would be easier to store it in my desktop, so I can just click it whenever, but I can't seem to make it back out of a directory and then go down into another.
start cmd
pushd \nand2tetris\projects\P1Codes
start HardwareSimulator
pause
You can use ..\ to go back a directory.
For instance, if you had nand2tetris in your downloads folder you could get to it from the desktop with this script. Also make sure to to include the file extension.
pushd ..\Downloads\nand2tetris\projects\P1Codes
start HardwareSimulator.exe
pause
how to run application which has .lnk extension with .bat script?
(I have an application and short of that is .lnk extension and want to run it using .bat)
error is that its not running
A file with .lnk extension is just a shortcut to a file.
To launch the executable that the shortcut targets to, just write the shortcut filename in the same way as you will do to run a executable file, as follows:
#Echo OFF
"C:\path yo tour shortcut.lnk"
Exit
Or also:
#Echo OFF
Start /Wait "" "C:\path yo tour shortcut.lnk"
Exit
I know I'm kinda late, but for anyone coming here:
If the shortcut is on the desktop, check whether it is on "your" desktop or on the public one - in batch you access the public one through %public%\Desktop
If you want to run multiple links, use this: start /b \your\path
dont forget the quotation marks if the path has spaces in it!
I know from a desktop I can have a bat file that runs an executable with specific parameters and starts in the same path on the network where the executable exists, but how can I accomplish the same thing when calling the bat file assuming is in same folder as executable from another application?
For example:
\My-Network\app\PR8.exe /noload
I want to start specifically in \My-Network\app (same folder where PR8.exe exists) but not where it defaults to which seems to be c:\windows somehow. I can't seem to do a cd on a UNC path and I don't want to use any path letters as the application also detects as to which server it is executing from as well.
It isn't possible to set a UNC working directory for Windows batch files without network mapping drives. However, in Windows 2000 and later, you can use the PUSHD and POPD commands to change the working directory to a UNC share when running your script.
Wikipedia gives us the example of creating a shortcut to your batch file where the Target is set to the following:
%COMSPEC% /E:ON /C "PUSHD """\\My-Network\app\""" & C:\PATH\TO\BATCHFILE.BAT & POPD"
In this case the Working directory attribute of the shortcut is ignored, as the PUSHD and POPD commands will change it to the path specified.
I want to write simple Batch file will click on the batch file
I should go to my directory path should be D:\DS\Install
At present i am doing every 1hr go to
RUN command and typing to cmd and connect to D:\DS\Install
Instead of this I want short cut option.. :-)
If I understand your question correctly,
You want a shortcut on desktop which will open a command prompt and change directory to D:\DS\Install
This is pretty straight forward:
Go to C:\windows\system32 and copy cmd.exe to D:\DS\Install folder
Now right click on the cmd.exe in D:\DS\Install folder and send it to desktop create shortcut.
You will have a shortcut on desktop which will take you to the required folder everytime..
Just FYI... cmd.exe will always open from the directory where it is placed.
Just create a shortcut in your desktop, and when asked for the location, type this command
cmd.exe /k "cd /d "d:\ds\install""
This shortcut will call cmd to execute the cd to change the drive/folder and keep the window open to continue working with it.
You can also make a batch file called ds.bat and put it in c:\windows or any other folder that is on the path.
You can then use the WIN+R hotkey and type ds and enter.
#echo off
cd /d "d:\ds\install"
cmd /k
#echo off
cd /d "d:\ds\install"
cmd /k