I was helping a friend write some VBscript the other day. I was trying to write a simple copy function and I kept getting permission denied. However I was logged in locally as the administrator so that could not be it.
My code looked something like:
Sub CopyFile(source, destination) set filesys=CreateObject("Scripting.FileSystemObject") If filesys.FileExists(source) Then filesys.CopyFile source, destination End If End Sub
The Solution is: add “\” add the end of any of your path names like
Dim destinationpath
destinationpath = “C:\” & myfolder & “\”
Hope this helps someone else.
You must be a freaking genius!!! Thank you!
fso.CopyFile “\IrfanView\i-view32.ini”, “C:\Windows\”
^ Note backslash
see
http://www.tek-tips.com/viewthread.cfm?qid=62827&page=590
Saved the day – stupid error forgetting the last “\”.. Cheers!
Thanks mate. Been sitting here for the last half an hour wondering why…
Very helpful post. Thanks a mill
Very helpful, thank you!!
Finally! I was editing a 200+ vbs login script and got stuck on this error. Everything seemed fine, but the “Permission denied”. Even checked the permissions on both the source and destination folders, no good.
Then I found this post and VOILA!!! Everything is good again and I’m a happy camper!!
THANK YOU SO MUCH!
Thank you, your post moved me off dead center.
Thanks. I lost 2 hours trying to figure out what was wrong.
Hi, please help me as I am getting the same error message, the script9to get patch information on multiple servers) is as follows :
Option Explicit
Dim objFSO, objTextFile, RootDir, FileOutput, strComputer, objWMIService, Count
Const ForReading = 1
Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set objTextFile = objFSO.OpenTextFile(“C:\scripts\input.txt”, ForReading)
Dim strHotFix
strHotFix = inputbox(“2667402”)
set FileOutput = objFSO.CreateTextFile(“C:\scripts\Pat_Install_Status_KB.htm”,true,false)
fileOutput.WriteLine(“Installed Patches Information”)
fileOutput.WriteLine(“”)
fileOutput.WriteLine(“”)
fileOutput.WriteLine(“Computer NameDescriptionHotfix IDInstall StatusInstalled OnInstalled By”)
Do Until objTextFile.AtEndOfStream
strComputer = objTextFile.Readline
Count = 0
‘Query command
Set objWMIService = GetObject(“winmgmts:” & “{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2”)
Dim QFEs
Set QFEs = objWMIService.ExecQuery (“Select * from win32_QuickFixEngineering”)
Dim strOutput
Dim QFE
For Each QFE in QFEs
if QFE.HotFixID = strHotFix then
strOutput = “”
strOutput = strOutput + “” & strComputer & “” &_
“” & QFE.Description & “” &_
“” & QFE.HotFixID & “” &_
“” & “Installed” & “” &_
“” & QFE.InstalledOn & “” &_
“” & QFE.InstalledBy & “”
Count= Count + 1
fileOutput.WriteLine(strOutPut)
fileOutput.WriteLine(“”)
end if
‘ strOutPut=””
Next
if Count = 0 then
strOutput = “”
strOutput = strOutput + “” & strComputer & “” &_
“” & “-” & “” &_
“” & strHotfix & “” &_
“” & “Not Installed” & “” &_
“” & “-” & “” &_
“” & “-” & “”
fileOutput.WriteLine(strOutPut)
fileOutput.WriteLine(“”)
end if
Loop
fileOutput.WriteLine(“”)
wscript.echo “Result saved in Pat_Install_Status_KB.html file at specified location in line no 15 of this script”
WScript.Quit
thx alot, really helped
Works perfectly! Thanks a lot!~ 🙂
Thanks! very helpful!
Thank you – realy helpful hint
Samuel Haddad, Thanks a lot for the solution!
thats awesommmm!!!! thanks a ton.. 🙂
Meu querido!!! Olha, vlw msm!!! detalhe fundamental!!!
I’ve been searching different articles for hours. This is the only one I found with this solution and it worked like a charm! Thanks!
Great post.
For the ones of you who user server.mappath(“/folder/”)
that WILL NOT work!
you should use: server.mappath(“/folder”)&”/”
since server.mappath will remove your last “/”
Hope that helps 🙂
I have a website which has links to .xml files.. i need to save the the files which came in today. is ther a way i can accomplish this using VB script?
Yes! It helped a lot! Thanks
Thank you! You saved me a ton of grief.
Really…you are a Genius!
Thanks…that helps a lot.
This one worked for me, thanks mate!
Brilliant – thank you
Your Awesome! All that headache for a slash….
thanks man, you save my head 🙂
We are getting the same error. here is my line 19 that gets the error
Set objlogfile = fso.OpenTextFile(fTMP & “\” & ScriptLogName, 2, True)
Thanks, it worked for me.