作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有这个功能可以写入我的日志文件。它在默默地失败。因为这个函数没有引发错误,它只是无法创建或写入文件。我正在尝试写信给 %TEMP%\myappname.log
.它也在 %USERPROFILE%\Desktop\myappname.log
中失败.服务器是 Windows Server 2008 R2 标准版。
我在用其他程序写入应用程序文件夹时遇到过这种情况,因此转向写入 %TEMP%
目录,这解决了它。但是这个系统甚至不让我写信给%TEMP%
目录。
是的,我也尝试以管理员身份运行,但没有帮助。
在这种情况下,%TEMP% 通过 ExpandEnvironmentStrings
解析至 C:\Users\sa\AppData\Local\Temp\2
所以 g_strLogPath 是 C:\Users\sa\AppData\Local\Temp\2\myappname.log
.
Public Function LogMessage(ByVal strInput As String, Optional ByVal blnDate As Boolean = False) As Boolean
Dim intFileNumber As Integer
On Error GoTo ErrorHandler
If g_lngLogLevel <> 1 Then
Exit Function
End If
If Len(g_strLogPath) = 0 Then
SetLogPath
End If
If blnDate Then
strInput = Format(Now, cstrLogDateFormat) & " : " & strInput
End If
intFileNumber = FreeFile
Open g_strLogPath For Append As #intFileNumber
Print #intFileNumber, strInput
Close #intFileNumber
LogMessage = True
Exit Function
ErrorHandler:
MsgBox _
"Error: " & Err.Number & vbCrLf & _
"Location: Module1.LogMessage" & vbCrLf & _
"Line: " & Erl & vbCrLf & _
Err.Description, vbExclamation + vbOKOnly
End Function
最佳答案
尝试这个
Sub GetTmpPath()
'This will give the Temp Path
MsgBox IIf(Environ$("tmp") <> "", Environ$("tmp"), Environ$("temp"))
End Sub
Ret = IIf(Environ$("tmp") <> "", Environ$("tmp"), Environ$("temp"))
g_strLogPath = Ret & "\Sample.Log"
Open g_strLogPath For Append As #intFileNumber
关于vba - 在 %TEMP% 中写入文件无声无息地失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10438855/
我是一名优秀的程序员,十分优秀!