Scripting Help

G

Guest

Guest
Archived from groups: microsoft.public.win2000.general (More info?)

Hello,

I'm trying to create basic .bat script that will copy a file from one place
to another. I can get it to work, but it's really slow depending on how I do
it and I want to speed it up. Let's just say I'm new to scripts but I have
made an honest effort looking through Technet's scripting site (without an
answer to my question)....

The file I want to copy is located on a different computer (computer 2, a
file server) than which I am trying to execute the script from (computer 1,
a client PC). And, the file is going from one folder to another on the same
remote computer (2). The purpose of this is to place a shortcut to the
script in the Windows startup folder of several client computers, so that
when a person logs on the script runs and automatically updates a file to the
newest version before the users get a chance to open it. Each user will have
their own script. This will save me time so I don't have to manually track
users down, ask them to back out of the file, copy the file, then tell them
it's ok to open back up. Instead, users will get the latest version simpy by
rebooting.

If I type the script to go to a local mapped drive on computer 1, the script
works, but it's REALLY slow to copy the file because it's doing it through my
own computer. If I move the script file to the remote computer 2 (a W2k
server), then the script runs nice and fast the way I want it to. However, I
don't know how to execute the script so that it runs on the remote computer 2
but executed from computer 1.

For example, I can execute the script from computer 1 with:

U:
cd.. subfolder1
cd.. subfolderA (so now I am in U:\subfolder1\subfolderA)
copy somefile.doc U:\subfolder2

where the "U" drive is a local mapped drive on computer 1 pointing to a
shared folder on the D drive of computer 2. This will work, but again it's
really slow. It copies U:\subfolder1\subfolderA\somefile.doc and places it
in U:\subfolder2\.

If I go straight to that server and modify the code so it runs locally on
computer 2 (w/o any interaction with computer 1):

D:
cd.. subfolder1
cd.. subfolderA (so now I am in U:\subfolder1\subfolderA)
copy somefile.doc D:\subfolder2

this code does the same thing, but it runs much faster!

I tried placing the .bat script file on computer 2, make a shortcut to it
and put it on computer 1. Then I modified the code so that it would try to
go to the UNC name of computer 2 when executed from computer 1 but the
command prompt apparently doesn't support that (an error message tells me
so).
\\computer2\D$
cd subfolder1
cd subfolderA
copy somefile.doc D:\subfolder2

If I get rid of "\\computer2\D$" line, then computer1 tries to go to it's
own drive D which computer 1 doesn't have and I get an error. Computer 2 has
the drive D, but I can't get the client computer 1 to recognize 2's D drive.


Clear as mud? Any help would be greatly appreciated!
--
Thanks,

MN4runner
 
G

Guest

Guest
Archived from groups: microsoft.public.win2000.general (More info?)

I have never done any of that sort on a network, but *.BAT files have an
issue with executing across shells. Each instance must execute in its own
shell, and with two machines you're bound to have it execute in two shells,
or have I become mixed-up? That may not be your problem - or it may not be
your entire problem. I think you could try having one script write another
script dynamically, and perhaps even using environment variables and finally
delete the second script before terminating. It's a bit like when you make
*.BAT files call itself recursively - only here, itself sits on a different
machine.

By which I mean: each machine gets to have it's own little script and the
two can communicate using env_vars. Might just work?

Tricky thing, BAT's. Rarely basic at all. But that's the challenge.

Tony. . .


"mn4runner" <mn4runner@discussions.microsoft.com> wrote in message
news:8861B98C-C476-4061-8119-9F92E5040978@microsoft.com...
> Hello,
>
> I'm trying to create basic .bat script that will copy a file from one
> place
> to another. I can get it to work, but it's really slow depending on how I
> do
> it and I want to speed it up. Let's just say I'm new to scripts but I
> have
> made an honest effort looking through Technet's scripting site (without an
> answer to my question)....
>
> The file I want to copy is located on a different computer (computer 2, a
> file server) than which I am trying to execute the script from (computer
> 1,
> a client PC). And, the file is going from one folder to another on the
> same
> remote computer (2). The purpose of this is to place a shortcut to the
> script in the Windows startup folder of several client computers, so that
> when a person logs on the script runs and automatically updates a file to
> the
> newest version before the users get a chance to open it. Each user will
> have
> their own script. This will save me time so I don't have to manually
> track
> users down, ask them to back out of the file, copy the file, then tell
> them
> it's ok to open back up. Instead, users will get the latest version simpy
> by
> rebooting.
>
> If I type the script to go to a local mapped drive on computer 1, the
> script
> works, but it's REALLY slow to copy the file because it's doing it through
> my
> own computer. If I move the script file to the remote computer 2 (a W2k
> server), then the script runs nice and fast the way I want it to.
> However, I
> don't know how to execute the script so that it runs on the remote
> computer 2
> but executed from computer 1.
>
> For example, I can execute the script from computer 1 with:
>
> U:
> cd.. subfolder1
> cd.. subfolderA (so now I am in U:\subfolder1\subfolderA)
> copy somefile.doc U:\subfolder2
>
> where the "U" drive is a local mapped drive on computer 1 pointing to a
> shared folder on the D drive of computer 2. This will work, but again
> it's
> really slow. It copies U:\subfolder1\subfolderA\somefile.doc and places
> it
> in U:\subfolder2\.
>
> If I go straight to that server and modify the code so it runs locally on
> computer 2 (w/o any interaction with computer 1):
>
> D:
> cd.. subfolder1
> cd.. subfolderA (so now I am in U:\subfolder1\subfolderA)
> copy somefile.doc D:\subfolder2
>
> this code does the same thing, but it runs much faster!
>
> I tried placing the .bat script file on computer 2, make a shortcut to it
> and put it on computer 1. Then I modified the code so that it would try
> to
> go to the UNC name of computer 2 when executed from computer 1 but the
> command prompt apparently doesn't support that (an error message tells me
> so).
> \\computer2\D$
> cd subfolder1
> cd subfolderA
> copy somefile.doc D:\subfolder2
>
> If I get rid of "\\computer2\D$" line, then computer1 tries to go to it's
> own drive D which computer 1 doesn't have and I get an error. Computer 2
> has
> the drive D, but I can't get the client computer 1 to recognize 2's D
> drive.
>
>
> Clear as mud? Any help would be greatly appreciated!
> --
> Thanks,
>
> MN4runner
 
G

Guest

Guest
Archived from groups: microsoft.public.win2000.general (More info?)

"mn4runner" <mn4runner@discussions.microsoft.com> wrote in message
news:8861B98C-C476-4061-8119-9F92E5040978@microsoft.com...
> Hello,
>
> I'm trying to create basic .bat script that will copy a file from one
place
> to another. I can get it to work, but it's really slow depending on how I
do
> it and I want to speed it up. Let's just say I'm new to scripts but I
have
> made an honest effort looking through Technet's scripting site (without an
> answer to my question)....
>
> The file I want to copy is located on a different computer (computer 2, a
> file server) than which I am trying to execute the script from (computer
1,
> a client PC). And, the file is going from one folder to another on the
same
> remote computer (2). The purpose of this is to place a shortcut to the
> script in the Windows startup folder of several client computers, so that
> when a person logs on the script runs and automatically updates a file to
the
> newest version before the users get a chance to open it. Each user will
have
> their own script. This will save me time so I don't have to manually
track
> users down, ask them to back out of the file, copy the file, then tell
them
> it's ok to open back up. Instead, users will get the latest version simpy
by
> rebooting.
>
> If I type the script to go to a local mapped drive on computer 1, the
script
> works, but it's REALLY slow to copy the file because it's doing it through
my
> own computer. If I move the script file to the remote computer 2 (a W2k
> server), then the script runs nice and fast the way I want it to.
However, I
> don't know how to execute the script so that it runs on the remote
computer 2
> but executed from computer 1.
>
> For example, I can execute the script from computer 1 with:
>
> U:
> cd.. subfolder1
> cd.. subfolderA (so now I am in U:\subfolder1\subfolderA)
> copy somefile.doc U:\subfolder2
>
> where the "U" drive is a local mapped drive on computer 1 pointing to a
> shared folder on the D drive of computer 2. This will work, but again
it's
> really slow. It copies U:\subfolder1\subfolderA\somefile.doc and places
it
> in U:\subfolder2\.
>
> If I go straight to that server and modify the code so it runs locally on
> computer 2 (w/o any interaction with computer 1):
>
> D:
> cd.. subfolder1
> cd.. subfolderA (so now I am in U:\subfolder1\subfolderA)
> copy somefile.doc D:\subfolder2
>
> this code does the same thing, but it runs much faster!
>
> I tried placing the .bat script file on computer 2, make a shortcut to it
> and put it on computer 1. Then I modified the code so that it would try
to
> go to the UNC name of computer 2 when executed from computer 1 but the
> command prompt apparently doesn't support that (an error message tells me
> so).
> \\computer2\D$
> cd subfolder1
> cd subfolderA
> copy somefile.doc D:\subfolder2
>
> If I get rid of "\\computer2\D$" line, then computer1 tries to go to it's
> own drive D which computer 1 doesn't have and I get an error. Computer 2
has
> the drive D, but I can't get the client computer 1 to recognize 2's D
drive.
>
>
> Clear as mud? Any help would be greatly appreciated!
> --
> Thanks,
>
> MN4runner

You write "If I move the script file to the remote computer 2 (a W2k
server), then the script runs nice and fast." This is incorrect. It does
not matter in the least where the script ***resides***. What matters
is where the script commands ***execute***.

Here are two examples that will run at the same speed, assuming
that "SomeScript.bat" is one and the same batch file and that you
are invoking both batch files from a Command Prompt on the
same machine:

c:\SomeFolder\SomeScript.bat (resides locally)
\\SomeServer\SomeShare\SomeScript.bat (resides on a server)

I cannot spend sufficient time to work through your lengthy post
to figure out exactly what you're trying to achieve. Here are two
pointers:

a) The commands
cd subfolder1
cd subfolderA
are wasteful and fragile. Wasteful because they bloat your batch
file, and fragile because you assume that you are currently in the
parent folder of subfolder1. If you're not then the batch file will
fail! Here is a robust way to do the same thing:
cd /d c:\subfolder1\subfolderA

b) To ***execute*** commands on a remote machine:
1. Place your batch file into a location that is accessible by
all machines, e.g. into \\MyServer\SomeShare\SomeBatch.bat
2. Type this command from your own PC:
psexec \\SomePC -u DomainName\JSmith \\MyServer\SomeShare\SomeBatch.bat
This will do the following:
- The command will ***execute*** on \\SomePC, not on your own PC.
- It will run under the domain account of JSmith.
- It will run the commands stored in \\MyServer\SomeShare\SomeBatch.bat

You can download psexec.exe from www.sysinternals.com.