creating an icon of a shortcut of a batch file using nsis installer - installation

I need to set an icon for my batch file OR for the shortcut of my batch file , using the nsis installer.
Can an icon be set only of a shortcut , or can i set the icon of the main batch file whose shortcut needs to be created.
The following code isn't working:
I have a folder MyAccountSoftware, my installer will compile the files of this folder into the exe file.
This folder has these two files :-
---MyAccountSoftware
|______Account.BAT
|______Account.ico
SetOutPath $INSTDIR\
File "MyAccountSoftware\Account.BAT"
CreateShortCut "$INSTDIR\Account.lnk" "$INSTDIR\Account.BAT" "$INSTDIR\Account.ico"
This code, just copies the file Account.BAT into the required $INSTDIR, and creates a shortcut -
Account.Ink in the $INSTDIR, but doesn't set the icon of the Shortcut.
Please help.

Batch files cannot have custom icons. When creating the shortcut, even if you don't need a parameter you still need to provide a empty string:
CreateShortCut "$INSTDIR\Account.lnk" "$INSTDIR\Account.BAT" "" "$INSTDIR\Account.ico"

Related

How to create a link without .lnk extension?

If I have a file named "C\Test\mypic.jpg", can I create a shortcut with path "C\Test2\mypic.jpg"? Windows always seems to add a ".lnk" suffix, which is unwanted in my case.
Link in this case can mean several things but we can unpack all the possible scenarios:
A shortcut (.lnk file). These files must have the .lnk extension because the file extension is how Windows decides which handler to invoke when you double-click/execute the file. If you create a shortcut to a jpg file the real name can be link.jpg.lnk but the user will see the name as link.jpg in Explorer because .lnk is a special extension that is hidden.
A symbolic link (symlink). These are links on the filesystem level and can have any extension. mklink "c:\mylink.jpg" "c:\file.jpg"
A hardlink. This is another name for the same file (alias), it does not create a shortcut. mklink /H "c:\anothername.jpg" "c:\file.jpg"

Can a Windows batch file determine its "invoked" filename when invoked with shortcut?

Can a Windows batch file determine its invoked filename when invoked through a shortcut?
For example, I create real.bat, and create its shortcut named phony.bat (.lnk?)
And invoke phony by double-click on it.
Can this batch file detect the name phony.bat instead of real.bat?
Of course I can just copy it to another name, but when I edit one of them, I have to manually sync the content to all files.
The question is related to Can a Windows batch file determine its own file name?, but different.
As in your you mentioned that you've created the shortcut I assume you can create the with any properties you want.
So right click on your lnk file and change the the target line to:
C:\Windows\System32\cmd.exe /c "set "lnk_call=1"&"C:\PATH\TO\your.bat" "
This will change the icon of the link so to set back to batch file cog click on change icon and find the bat file icon in :
%SystemRoot%\System32\SHELL32.dll
Finally in your bat put this line:
if defined lnk_call echo triggered from lnk file
the lnk_call now can be used to determine if your file is called from double clicking on a .lnk file. I don't think it is possible to detect this from a shortcut that anyone else created.
Oh yeah, I found hardlink useful in this case:
mklink /h <link-name> <source-file>
I can create many hardlinks with different name, and they all points to the same file, so I can freely edit any one of them without manually sync their content.

Shortcut Ghost: Running a Shortcut as the File?

I'm attempting to generate a shortcut that will run an executable file called WAVistaWin7.exe. Whenever the shortcut generates, I'll double-click it, and it will say "WAVistaWin7.exe cannot find 'wa.exe'." wa.exe is inside of the folder that it belongs. I then attempt to put a Batch file called run.bat containing two lines:
#echo off
WAVistaWin7.exe
I redirect the shorcut to run this file, and the Batch file states that it cannot find WAVistaWin7.exe. It's becoming evident that the shortcut is running independently of the file. Note that whenever I run either WAVistaWin7.exe or run.bat inside of the folder directly it works. How can I get the shortcut to run as the file?
It looks like you need to set your working directory. In the shortcut properties, you can set the "Start in" folder.
Alternatively, in your batch file you can change to the appropriate folder:
#echo off
pushd C:\Program Files\WA
WAVistWin7.exe

BAT file to open CMD in current directory

I have many scripts which I interact with from the command line. Everytime I need to use them, I have to open a command line window and copy+paste and CD to the path to the directory they are in. This is tedious (they are in a rather deep file system, so typing out the full path is a pain, copy+paste is better but not much). I tried to create a .BAT file that I could double-click on that would open a new command-line window in the folder the .bat file exists in but it does not work. It opens a new window, but the working directory is not the directory that .bat file is in. Here's what I've got after much googling (My cmd skills ain't so great):
cd %CD%
cmd.exe
I know from when I used Linux that Konqueror had a "Command-line window here" feature, and that's the effect I'm trying to get on Windows.
you probably want to do this:
cd /d %~dp0
cmd.exe
this will set your current directory to the directory you have the batch file in
Create a file named open_dos_here.cmd with the following lines:
%~d1
cd "%~p1"
call cmd
Put this file at any folder.
Then, go to your Send To folder (Win+E; Alt+D;shell:sendto;Enter).
Create a shortcut to point to this open_dos_here.cmd
Then, in any folder, select any file or sub-folder. Right-click and select "Send To" and then select open_dos_here.cmd to open the DOS in that folder.
You can just enter cmd into the address bar in Explorer and it starts up in that path. Likewise for PowerShell.
There's a simpler way -
start /d "folder path"
As a more general solution you might want to check out the Microsoft Power Toy for XP that adds the "Open Command Window Here" option when you right-click: http://www.microsoft.com/windowsxp/downloads/powertoys/xppowertoys.mspx
In Vista and Windows 7, you'll get that option if you hold down shift and right-click (this is built in).
I'm thinking that if you are creating a batch script that relies on the Current Directory being set to the folder that contains the batch file, that you are setting yourself up for trouble when you try to execute the batch file using a fully qualified path as you would from a scheduler.
Better to add this line to your batch file too:
REM Change Current Directory to the location of this batch file
CD /D %~dp0
unless you are fully qualifying all of your paths.
Another solution is to use a shortcut file to cmd.exe instead of a batch file.
Edit the shortcut's start in property to %~dp0.
You achieve the same thing, except it has the Cmd icon (and you can change this).
Some people don't like clicking on batch files without knowing what's in them, and some corporate network drives have a ban on .bat files...
The simplest command to do this:
start
You can always run this in command line to open new command line window in the same location. Or you can place it in your .bat file.
Most simple way in explorer is to Shift + right mouse click on the folder or on an empty space in the folder and click on Open command prompt here.
CMD will then start in that folder
I must say, I'm not sure if it works for Windows Vista and below, but it surely works for Windows 7, 8, 8.1 and 10.
Referring to answer of #Chris,
We can also go to parent directory of batch file and run commands using following
cd /d %~dp0..
<OTHER_BATCH_COMMANDS>
cmd.exe
To understand working of command cd /d %~dp0.. please refer below link
What does it mean by command cd /d %~dp0 in Windows
You could add a context menu entry through the registry:
Navigate in your Registry to
HKEY_LOCAL_MACHINE/Software/Classes/Folder/Shell
and create a key called "Command Prompt" without the quotes.
Set the default string to whatever text you want to appear in the right-click menu.
Create a new key within your newly created command prompt named "command," and set the default string to
cmd.exe /k pushd %1
You may need to add %SystemRoot%\system32\ before the cmd.exe if the executable can't be found.
The changes should take place immediately. Right click a folder and your new menu item should appear.
Also see http://www.petri.co.il/add_command_prompt_here_shortcut_to_windows_explorer.htm
When you are in the desired folder , just type CMD in your address bar
A bit late to the game but if I'm understanding your needs correctly this will help people with the same issue.
Two solutions with the same first step:
First navigate to the location you keep your scripts in and copy the filepath to that directory.
First Solution:
Click "Start"
Right-click "Computer" (or "My Computer)
Click "Properties"
On the left, click "Advanced System Settings"
Click "Environment Variables"
In the "System Variables" Box, scroll down and select "PATH"
Click "Edit"
In the "Variable Value" field, scroll all the way to the right
If there isn't a semi-colon (;) there yet, add it.
Paste in the filepath you copied earlier.
End with a semi-colon.
Click "OK"
Click "OK" again
Click "OK" one last time
You can now use any of your scripts as if you were already that folder.
Second Solution: (can easily be paired with the first for extra usefulness)
On your desktop create a batch file with the following content.
#echo off
cmd /k cd "C:\your\file\path"
This will open a command window like what you tried to do.
For tons of info on windows commands check here: http://ss64.com/nt/
Create a new file startCmdLine.bat in your directory and put this line in it
call cmd
That is it. Now double click on the .bat file. It works for me.
You can replace call with start, it will also work.
this code works for me
name it cmd.bat
#echo off
title This is Only A Test
echo.
:Loop
set /p the="%cd%"
%the%
echo.
goto loop
you can try:
shift + right click
then, click on Open command prompt here
Inside given folder click on the top Adddress Bar and type cmd and click enter
It will open command prompt with current folder address.
You can simply create a bat file in any convenient place and drop any file from the desired directory onto it.
Haha. Code for this:
cmd

Variables in batch and registry edit for right-click support

I have this batch file which needs to do some stuff in a folder.
This is what i want:
-A shortcut when you right-click. (shell32 i think you should edit with the registry or so...? Can somebody say so?)
-If that shortcut is pressed, the batch is opened, and it locates the folder were was right-clicked. It should set this as a variable, %folder%.
Thanks.
For the registry file:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Folder\shell\TEXT_TO_SHOW_IN_EXPLORER_CONTEXT]
[HKEY_CLASSES_ROOT\Folder\shell\TEXT_TO_SHOW_IN_EXPLORER_CONTEXT\command]
#="C:\\Path\\to\\batch.cmd \"%1\""
For the batch file:
set folder=%1
:: remove the " from the variable
set folder=%folder:"=%
echo %folder%
Comment out line 3 of the batch file if you want to keep "'s around the folder path.

Resources