Re: "Access Denied" error when copying a file to a remote computer
- From: "Jason" <flajason@xxxxxxxxx>
- Date: 31 Jul 2006 09:38:45 -0700
Howdy BeatleManiac,
A common error when using the FileSystemObject to open a file for
reading or writing and then trying to perform a move, copy or delete
method on it will result in a permission denied error if you don't
close the object first.
Here's an example:
Set fso = CreateObject("Scripting.FileSystemObject")
Set testfile = fso.OpenTextFile("C:\Test.txt", 2, True)
testfile.WriteLine "This is a test..."
Set testfile = Nothing
fso.DeleteFile "C:\Test.txt"
The above script will work just fine. It will create and write to a
text file, and then delete the file. If the line "Set testfile=nothing"
is not incuded, you will receive a permission denied error. If in your
helper script, you are reading the file but not closing it by setting
it to Nothing, your copy and delete processes will fail with a
permission denied error.
Hope that helps...
- Jason
BeatleManiac wrote:
Hello.
I am in the process of rewriting my company's login script in VBScript. I
have most of the code done, but I'm having an issue with access to a remote
file system. One of the features I wrote is the ability of the script to
copy files from a network share to a local folder on the pc running the
script. For instance, if the url to our intranet site changes, I want to be
able to "push" the shortcut with the new address to every pc that runs the
login script. This feature needs to include the ability to push to
"protected" folders like %systemroot%\System32. During my testing, I've
noticed that if I run the script as a local admin, everything works fine.
However, running it as a general user (non-admin) generates an "Access
Denied" error when the script tries to copy the file from the network share.
Understandable, since a user is, by design, not allowed to modify anything in
System32. My solution to this is to have the login script create a text file
in a freely accessable hiden network share. That file is created with the
same name as the pc that ran the script. Within the file, I write the source
and destination paths, as well as the name of the file to be copied. I then
wrote "helper" script that runs on one of our domain controllers as a
recurring scheduled task using an account that has local admin rights to the
pc in question. That script will read and parse the text file, perform the
copy with elevated privlidges, and delete the file. Doing it this way will
allow me to access restricted folders without hard-coding an admin account
and password in a script.
Now, to the actual problem (sorry about the long set-up):
From the DC, any attempt to copy the file to the remote user pc from the
script generates an "Access Denied" error. I've tried running the script
under various accounts, including the Domain Admin account, but get the error
in every case. I have tried using the Admin share on the pc (C$) as well as
a regular share with wide open permissions. I CAN, however, copy the file
manually while signed in as the pc local admin account. I'm using the
FileSystemObject to get a handle to the desired file and paths.
Is there some special security in place that prevents VBScript from being
used in this way? If so, is there a viable work-around? I can provide code
samples, if necessary.
Thanks in advance.
BeatleManiac
Floyds Knobs, IN
.
- Follow-Ups:
- Re: "Access Denied" error when copying a file to a remote computer
- From: BeatleManiac
- Re: "Access Denied" error when copying a file to a remote computer
- Prev by Date: Re: Vbscript control
- Next by Date: Re: Problem with CDO.Message and attachments
- Previous by thread: Return target directory for user's My Documents folder
- Next by thread: Re: "Access Denied" error when copying a file to a remote computer
- Index(es):
Relevant Pages
|