Copy shortcut to desktop in a batch file

D

Diane Walker

I use Installshield software to setup the executable file to install the
software. In that executable file, I setup a batch file to copy a
shortcut to the desktop. The executable file ran successfully. However,
the shortcut was not copied to the desktop. I got the error message "File
not found" for the shortcut command. Do you have any suggestions? Thanks.
 
A

AlmostBob

batch files cant contain spaces in file names, so
copy \program files\thisfile.ext \anydestination
fails
copy "\program files\thisfile.ext" "\anydestination in quotes around spaces"
proceeds

the copy may fail if you specify a desktop foldername, that does not exist
this pc has none of
C:\documents and settings\all users\desktop
C:\documents and settings\all users
C:\documents and settings
C:\documents and settings\user\desktop
C:\documents and settings\user

but %Homedrive%%Homepath%\desktop
works as does
%Homedrive%%allusersprofile%\desktop
windowsXP is on a virtual drive P: running as a toy in the background

batch files are unfriendly and expect you to code for all possibilities,

--
Adaware http://www.lavasoft.de
spybot http://www.safer-networking.org
AVG free antivirus http://www.grisoft.com
Etrust/Vet/CA.online Antivirus scan
http://www3.ca.com/securityadvisor/virusinfo/scan.aspx
Panda online AntiVirus scan http://www.pandasoftware.com/ActiveScan/
Catalog of removal tools (1)
http://www.pandasoftware.com/download/utilities/
Catalog of removal tools (2)
http://www3.ca.com/securityadvisor/newsinfo/collateral.aspx?CID=40387
Blocking Unwanted Parasites with a Hosts file
http://mvps.org/winhelp2002/hosts.htm
links provided as a courtesy, read all instructions on the pages before use

Grateful thanks to the authors and webmasters
_
 
P

Pegasus \(MVP\)

Your reply is basically correct but a little confusing - see below.

AlmostBob said:
batch files cant contain spaces in file names, so
*** Yes, they can.
copy \program files\thisfile.ext \anydestination fails
copy "\program files\thisfile.ext" "\anydestination in quotes around
spaces"
proceeds
*** This is because folder/file names that have embedded spaces
*** must be surrounded by double quotes. This is a requirement
*** of console commands and has nothing to do with batch files.
the copy may fail if you specify a desktop foldername, that does not exist
this pc has none of
C:\documents and settings\all users\desktop
C:\documents and settings\all users
C:\documents and settings
C:\documents and settings\user\desktop
C:\documents and settings\user
*** All of the above must be surrounded by double quotes.
but %Homedrive%%Homepath%\desktop
works as does
%Homedrive%%allusersprofile%\desktop
*** No, they do not, because %HomePath% and %AllUsersProfile%
*** have embedded spaces. They must be surrounded by double quotes.
windowsXP is on a virtual drive P: running as a toy in the background
*** Meaning?
batch files are unfriendly and expect you to code for all possibilities,
*** Batch files, same as console commands, require precise coding.
*** They have no safety net, as opposed to GUIs.
 
P

Pegasus \(MVP\)

Diane Walker said:
I use Installshield software to setup the executable file to install the
software. In that executable file, I setup a batch file to copy a
shortcut to the desktop. The executable file ran successfully. However,
the shortcut was not copied to the desktop. I got the error message "File
not found" for the shortcut command. Do you have any suggestions? Thanks.

Let's have a look at your batch file!
 
D

Diane Walker

Thank you very much all for your prompt response.

The batch file is
copy XXX.lnk "%allusersprofile\desktop"

The error message said "file not found". I interpret that the batch file
cannot find "XXX.lnk" file even though the shortcut "XXX.lnk" does exist.
Please let me know if you need additional information. Thanks.
 
B

Bill Sharpe

Diane said:
Thank you very much all for your prompt response.

The batch file is
copy XXX.lnk "%allusersprofile\desktop"
Add the full path to XXX.lnk,
e.g. copy "C:\My Install Directory\XXX.lnk"

Bill
 
P

Pegasus \(MVP\)

Instead of writing

copy XXX.lnk "%allusersprofile\desktop", try this:
copy /y XXX.lnk "%allusersprofile%\desktop"

You'll notice the missing "%". The "/y" switch will ensure
that there will be no prompt in case the file already exists.

Furthermore, to make your batch file robust, add the full path
to your source file, e.g. like so:

xcopy /y /d "U:\Some Folder\XXX.lnk" "%allusersprofile%\desktop"

Using xcopy.exe with the /d switch will prevent mindless
copying of the same file each time the use command is
invoked.
 
D

Diane Walker

Thank you very much for your prompt response and suggestions. I still got
the same error message.
 
T

Terry R.

The date and time was 7/21/2008 5:00 PM, and on a whim, Diane Walker
pounded out on the keyboard:
Thank you very much for your prompt response and suggestions. I still got
the same error message.

Hi Diane,

Combining the suggestions of Bill and Pegasus should resolve your issue.
You need to include the full path of XXX.lnk as I doubt the batch file
is in the same folder as the LNK file.

--
Terry R.

***Reply Note***
Anti-spam measures are included in my email address.
Delete NOSPAM from the email address after clicking Reply.
 
T

Terry R.

The date and time was 7/21/2008 11:40 AM, and on a whim, Pegasus (MVP)
pounded out on the keyboard:
Instead of writing

copy XXX.lnk "%allusersprofile\desktop", try this:
copy /y XXX.lnk "%allusersprofile%\desktop"

You'll notice the missing "%". The "/y" switch will ensure
that there will be no prompt in case the file already exists.

Furthermore, to make your batch file robust, add the full path
to your source file, e.g. like so:

xcopy /y /d "U:\Some Folder\XXX.lnk" "%allusersprofile%\desktop"

Using xcopy.exe with the /d switch will prevent mindless
copying of the same file each time the use command is
invoked.

Sorry Pegasus, I didn't see that you also suggested adding the path to
the source when I replied to Diane.

--
Terry R.

***Reply Note***
Anti-spam measures are included in my email address.
Delete NOSPAM from the email address after clicking Reply.
 
P

Pegasus \(MVP\)

Diane Walker said:
Thank you very much for your prompt response and suggestions. I still got
the same error message.

Same answer as before: Let's see your current command.
Remember - we can't see your machine! You should also
report how you're running your batch file:
- By double-clicking a shortcut;
- By running it from a Command Prompt;
- By invoking it via the Task Scheduler;
- Other.
 
D

Diane Walker

Sorry for not giving me enough information. Thanks very much for your
prompt response. The batch file is
copy /Y "%temp%\XXX.lnk" "%ALLUSERSPROFILE%\desktop"

Thanks.
 
P

Pegasus \(MVP\)

The command works perfectly well on my machine - provided that
the file "%temp%\xxx.lnk" exists.

I note that you did not answer my question about hour method
for invoking this command. Furthermore, if you embed it in a
batch file then perhaps the error is generated by a different
command. You should post the whole batch file, not just a fragment.
 
B

Bill Sharpe

Diane said:
Sorry for not giving me enough information. Thanks very much for your
prompt response. The batch file is
copy /Y "%temp%\XXX.lnk" "%ALLUSERSPROFILE%\desktop"

Thanks.


Are you sure that XXX.lnk exists in your %temp% directory?
You can run
dir %temp% XXX.lnk
from a command window to check.
I, of course, get "file not found" when I do so.

Bill
 
D

Diane Walker

Thank you for your prompt response, again. Sorry for not answering your
question. I put the command in a batch file (install.bat). Then, I use the
Installshield software to make the batch file become an executable file
(install.exe). Then, I run file "install.exe". That is why I got the
error about shortcut link. Please let me know if you need additional
information or I miss anything.

Thanks.
 
D

Diane Walker

Thanks for the tip, Bill. I do not see XXX.lnk in the %temp% directory. I
will go back to my batch file and see why the shortcut link did not copy to
the %temp% directory. Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top