Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBscript permission

Status
Not open for further replies.

cjkenworthy

Programmer
Sep 13, 2002
237
GB
I have some identical vbscript in two files, in the same directory, with the same file attributes, yet one runs fine, the other gives a permission denied:

Dim varPath
varPath = "\\PDC01\docs\new_dir_name"

set objFS = Server.CreateObject("Scripting.FileSystemObject")
set objDirectory = objFS.CreateFolder(varPath)

set objDirectory = nothing
set objFS = nothing

The code runs fine in isolation in one file, but as one of many operations in another file, it fails. The 'other functions' in that file work fine, but I get the permission denied in there - at the 'objFS.CreateFolder(varPath)' line.

Any ideas? I'd be happy to post the complete file which fails.
 
I know it is an obvious one but do you have the correct permissions to 'varPath' both through the share and at NTFS level?
 
Yes, thats what's really wierd, if it was a permissions issue, then the code would not work at all.


The fact that it does work in a seperate file is what is confusing, thus the permisions must be correct.
 
if you post the rest of your code then I am happy to take a look and see if I can spot anything...............
 
I have decided that it is something to do with the server it is run on, as the code works fine on a different server. But here it is, to see if there are any obvious errors.

It is safe to assume that the recordsets are returning the correct values, and that incoming variables are correct as I have checked them a million times!

This is a seperate file which is included in another ASP file

'Function to create actual directory
'Author: C.Kenworthy
'Date: 11/03/03

Dim varclient_id
varclient_id = Request.QueryString("client_id")

Dim varFullPath, varNewDirName, varCompany

'Declare recordsets
Dim dir
Dim dir_numRows

'Get choice of dir name from radio group
varNewDirName = Request.Form("dirname")

if varNewDirName = "other_specified_value" then
varNewDirName = Request.Form("txtother")
end if

if Session("current_location") = "Add a client" then

'If adding a client set default root directory and new client directory name
varFullPath = "\\PDC01\client_docs\" & varNewDirName & "\"

'Update client table with folder directory
set clientdir = Server.CreateObject("ADODB.Command")
clientdir.ActiveConnection = MM_client_projects_STRING
clientdir.CommandText = "UPDATE dbo.client SET shared_folder = '" & varfullpath & "' WHERE client_id = '" & varclient_id & "'"
clientdir.CommandType = 1
clientdir.CommandTimeout = 0
clientdir.Prepared = true
clientdir.Execute()

'Get company name for log
Set dir = Server.CreateObject("ADODB.Recordset")
dir.ActiveConnection = MM_client_projects_STRING
dir.Source = "SELECT company FROM dbo.client WHERE client_id = '" & varclient_id & "'"
dir.CursorType = 0
dir.CursorLocation = 2
dir.LockType = 1
dir.Open()

dir_numRows = 0

varCompany = dir("company")

dir.Close()
Set dir = Nothing

elseif Session("current_location") = "Add a client project" then

'If adding a project, retrieve root directory of client and append client project directory

'Get root directory and company name aswell for log
Set dir = Server.CreateObject("ADODB.Recordset")
dir.ActiveConnection = MM_client_projects_STRING
dir.Source = "SELECT company, shared_folder FROM dbo.client WHERE client_id = '" & varclient_id & "'"
dir.CursorType = 0
dir.CursorLocation = 2
dir.LockType = 1
dir.Open()

dir_numRows = 0

varFullPath = dir("shared_folder") & varNewDirName & "\"
varCompany = dir("company")

dir.Close()
Set dir = Nothing

'Update shared folder of project
set projdir = Server.CreateObject("ADODB.Command")
projdir.ActiveConnection = MM_client_projects_STRING
projdir.CommandText = "UPDATE dbo.project SET shared_folder = '" & varfullpath & "' WHERE client_id = '" & varclient_id & "'"
projdir.CommandType = 1
projdir.CommandTimeout = 0
projdir.Prepared = true
projdir.Execute()

end if

'Create the shared directory
Dim objFS, objDirectory
set objFS = Server.CreateObject("Scripting.FileSystemObject")

Dim FolderDoesExist
FolderDoesExist = "0"

'Check if directory already exists
if objFS.FolderExists(varFullPath) = "True" then

'Do not create directory, raise flag to indicate error
FolderDoesExist = "1"

else
'Create directory if it doesn't already exist

'Cut off the \ at the end of the directory name
Dim strLength, strTrimDirname
strLength = Len(varFullPath)
strTrimDirname = Left(varFullPath, strLength-1)

set objDirectory = objFS.CreateFolder(strTrimDirname)
set objDirectory = nothing

'Append to activity log
Dim Filename
set Filename = objFS.OpenTextFile(Server.MapPath("../logs/activity.txt"), 8, true)

Filename.WriteLine(Date & " " & Time & " - Directory CREATED: " & varFullPath)

'Add line depending on operation
if Session("current_location") = "Add a client" then

Filename.WriteLine("This CLIENT directory was created for client: '" & varCompany & "'")

elseif Session("current_location") = "Add a client project" then

Filename.WriteLine("This PROJECT directory was created for client: '" & varCompany & "'")

end if

Filename.Close
set Filename = nothing

set objFS = nothing

end if
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top