PC Review


Reply
Thread Tools Rate Thread

Batch file not working

 
 
Dave Nagalia
Guest
Posts: n/a
 
      24th Sep 2004
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.
 
Reply With Quote
 
 
 
 
Mark V
Guest
Posts: n/a
 
      24th Sep 2004
In microsoft.public.win2000.cmdprompt.admin Dave Nagalia wrote:

> 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\"
?

> 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.
>


 
Reply With Quote
 
Phil Robyn [MVP]
Guest
Posts: n/a
 
      24th Sep 2004
Dave Nagalia wrote:

> 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'

--
Phil Robyn
Univ. of California, Berkeley

u n z i p m y a d d r e s s t o s e n d e - m a i l
 
Reply With Quote
 
Matthias Tacke
Guest
Posts: n/a
 
      25th Sep 2004
"Phil Robyn [MVP]" wrote:
>Dave Nagalia wrote:
>> 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'


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

--
Greetings
Matthias________________________________________
For help on nt commands enter in a cmd window:
W2K>HH windows.chm::ntcmds.htm XP>HH ntcmds.chm
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Batch-file not working: PATH-problem? DaniëlRie Windows Vista General Discussion 3 11th Sep 2008 06:33 AM
mysql dump batch file stopped working. Rob Windows XP General 4 27th Mar 2008 03:17 AM
Script (batch file) working directories. Steve Daly Spyware Discussion 0 11th Jan 2005 03:51 PM
Batch file not working as a scheduled task David Microsoft Windows 2000 CMD Promt 2 8th Oct 2003 03:06 PM
Batch file not working as a scheduled task David Microsoft Windows 2000 1 8th Oct 2003 12:39 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:18 PM.