Batch file not working

D

Dave Nagalia

I have a script that is supposed to copy a shortcut from
my machine to all user's machines.

I have icon.bat, allusers.txt, and the icon.lnk file
located in a folder called "Scripts" in the root of C:. I
can run the script, but the icon does not copy. Here is my
script:

c:
cd c:\Scripts\
FOR /f "tokens=1 delims= " %%o in
(c:\Scripts\allusers.txt) do call :doit
%%o
goto end

:do it
set machine=%1
IF NOT EXIST c:\Scripts\icon.lnk copy c:\Scripts\icon.lnk
"\\%machine%\c$\Documents and Settings\All
Users\Desktop\icon.lnk"
goto end

:end

Any ideas on what went wrong? I have a feeling it may just
be an oversight, but I can't pinpoint it.
 
M

Mark V

In said:
I have a script that is supposed to copy a shortcut from
my machine to all user's machines.

I have icon.bat, allusers.txt, and the icon.lnk file
located in a folder called "Scripts" in the root of C:. I
can run the script, but the icon does not copy. Here is my
script:

c:
cd c:\Scripts\
FOR /f "tokens=1 delims= " %%o in
(c:\Scripts\allusers.txt) do call :doit
%%o
goto end

:do it
set machine=%1
IF NOT EXIST c:\Scripts\icon.lnk copy c:\Scripts\icon.lnk

But you said it *does* exist...
"\\%machine%\c$\Documents and Settings\All
Users\Desktop\icon.lnk"

Okay to just
COPY c:\Scripts\icon.lnk "\\%machine%\c$\Documents and Settings\All Users\Desktop\"
?
 
P

Phil Robyn [MVP]

Dave said:
I have a script that is supposed to copy a shortcut from
my machine to all user's machines.

I have icon.bat, allusers.txt, and the icon.lnk file
located in a folder called "Scripts" in the root of C:. I
can run the script, but the icon does not copy. Here is my
script:

c:
cd c:\Scripts\
FOR /f "tokens=1 delims= " %%o in
(c:\Scripts\allusers.txt) do call :doit
%%o
goto end

:do it
set machine=%1
IF NOT EXIST c:\Scripts\icon.lnk copy c:\Scripts\icon.lnk
"\\%machine%\c$\Documents and Settings\All
Users\Desktop\icon.lnk"
goto end

:end

Any ideas on what went wrong? I have a feeling it may just
be an oversight, but I can't pinpoint it.

':doit' is not the same as ':do it'
 
M

Matthias Tacke

':doit' is not the same as ':do it'

Hi Dave,

to add to that, if you don't pass an argument directly following the
call, %1 in the sub will be empty.
Looks like you retyped a script you didn't understand.
You iterate through a file allusers and name that argument machine?

Mark is right that the "if NOT EXIST" is nonsens. If the source doesn't
exist, you can't copy it.
If writing/posting code which exceeds a normal line length you should
insert the break character "^"

"tokens=1 and delims= " are standard and may be omitted.
In the nt line you may use the predefined label :eof and the last
command in a batch doesn't need goto :eof since it's at the end of file.

cd /D c:\Scripts\
FOR /f %%o in (allusers.txt) do call :doit %%o
goto :eof
:doit
set machine=%1
IF EXIST c:\Scripts\icon.lnk copy c:\Scripts\icon.lnk ^
"\\%machine%\c$\Documents and Settings\All Users\Desktop\icon.lnk"
goto :eof
 

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