Jump to content

Recommended Posts

Posted

Hi can anyone answer my question?

I am running this batch file in the computer startup GPO. It basically checks for the file 'sched.txt' exists and if it doesn't then simply copies it to the c:\windows directory.

It works perfectly if I run it in windows , it copies the file and if i run it again it detects the file and aborts.. all good

But in the computer startup it seems to skip the part where it copies the file and but runs the rest of the script , which is a problem because then it creates more and more AT tasks...

I'm certain this used to work in the computer startup before we changed our domain... Any ideas anybody?

I can't think why it would not be able to access the c: drive on computer startup or computer shutdown policies??

Here is the batch file:

@echo off

if exist c:\windows\Sched.txt GOTO END

xcopy %0\..\Sched.txt "c:\windows"

cscript %0\..\schedshutdown.vbs 0\..\

:END

ECHO "Shutdown Schedule Already Has Been Set"


Posted

Is the location of sched.txt and schedshutdown.vbs one level higher relative to the running batch file?

Why are you using xcopy, when a standard copy should do the job?

What is the exact parameter you are trying to pass to the vbscript?

Your script if ran from anywhere with spaces in the name would create two lines which looked like this

xcopy "X:\Top Level Folder\SecondLevel\Scripts\mybatch.cmd"\..\Sched.txt "c:\windows"
cscript "X:\Top Level Folder\SecondLevel\Scripts\mybatch.cmd"\..\schedshutdown.vbs 0\..\

Do they really reflect what you're wanting to do?

Posted

the files are all located in the same directory

like I said, if i run this in windows it works perfectly. It just doesn't want to work in the computer startup policy and I don't know why.. Is there any way I can pipe the results of the batch file to a text file to identify what the problem is?

Posted

Turns out it was some weird timing issue... I don't completely understand but what I did was put a vbs message pop up that appears for 10 seconds at computer startup. When the message box closed it then executed the rest of the code .. Seems to work now... I still cannot understand why it was skipping the line in the script where it checks for the file but the pause seems to sort it out.

Weird...

Anybody else heard of this before?

Posted

Well the code you posted is wrong, so I've no idea how it works!

As you haven't yet answered my reply

%0\..

could mean in this case:

"X:\Top Level Folder\SecondLevel\Scripts\mybatch.cmd"\..)

Also I was wondering why you would be passing this parameter

0\..\

to the vbs.

Did you forget to add another character before the `0`?

You should also be aware that the END label will be run regardless of whether or not the sched.txt file exists.

Guessing a little here but, what about:

@echo off
if not exist c:\windows\sched.txt (copy sched.txt c:\windows
cscript //nologo schedshutdown.vbs "%~dp0") else (
echo."Shutdown Schedule Already Has Been Set")

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...