在我的代码段中,当我编写文件名脚本时,它在以下行给了我一个拒绝的权限:
Set objTextFile = objFSO.OpenTextFile(strDirectory & strFile, ForAppending, True)这是脚本
'output log info
Function OutputToLog (strToAdd)
Dim strDirectory,strFile,strText, objFile,objFolder,objTextFile,objFSO
strDirectory = "c:\eNet"
strFile = "\weeklydel.bat"
'strText = "Book Another Holiday"
strText = strToAdd
' Create the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Check that the strDirectory folder exists
If objFSO.FolderExists(strDirectory) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFolder = objFSO.CreateFolder(strDirectory)
'WScript.Echo "Just created " & strDirectory
End If
If objFSO.FileExists(strDirectory & strFile) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFile = objFSO.CreateTextFile(strDirectory & strFile)
'Wscript.Echo "Just created " & strDirectory & strFile
End If
set objFile = nothing
set objFolder = nothing
' OpenTextFile Method needs a Const value
' ForAppending = 8 ForReading = 1, ForWriting = 2
Const ForAppending = 2
Set objTextFile = objFSO.OpenTextFile(strDirectory & strFile, ForAppending, True)
' Writes strText every time you run this VBScript
objTextFile.WriteLine(strText)
objTextFile.Close
End Function我已经分配了VBScript域管理员权限。有什么想法吗?
提前感谢
发布于 2008-12-15 18:33:28
我不认为这与文件权限本身有关。这与您使用以下命令创建文件的事实有关:
Set objFile = objFSO.CreateTextFile(strDirectory & strFile)创建带有对该文件(objFile)的引用的file...and
然后,在销毁引用之前不关闭该文件
...
'Missing objFile.Close here
Set objFile = nothing
Set objFolder = nothing
...因此,您销毁了引用,但使文本流在内存中打开,从而锁定了您的文件。
然后,您将继续尝试在文件已经“打开”的情况下重新打开文件。这有点长篇大论,你在创建文件后已经有了一个引用--直接写入这个文件比在创建另一个引用之前销毁引用要容易得多。
发布于 2009-12-01 21:22:51
不管它的价值是什么。
我确信我有一个权限错误,因为下面这行:
Set LogFile = LogFSO.OpenTextFile(LogFileName, ForWriting, True)因为这就是“权限被拒绝”错误所指向的行。但实际上,我的权限错误是再往下几行:
WshShell.AppActivate(ScreensToRemove(i))
WshShell.SendKeys ("~")
WScript.Sleep(1000)屏幕上没有这样的标题,所以SendKeys是没有权限的。
当然,解决方案是:
If WshShell.AppActivate(ScreensToRemove(i)) = True Then
WshShell.SendKeys ("~")
WScript.Sleep(1000)
End if希望这能有所帮助。
发布于 2015-05-19 08:47:27
另外,确保你没有在Excel中打开文件(我在.csv文件中遇到了这个问题)……
https://stackoverflow.com/questions/369242
复制相似问题