当我运行vbscript时,它说(在Windows脚本主机中):
C:\Users\admin\Desktop\Test.vbs
行: 34
第一章:1
错误:进程无法访问该文件,因为它正被另一个进程使用。
代码: 80070020
资料来源:(null)
我怎么才能解决这个问题?还有剧本..。
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFSO, objFolder, objShell, objFile
Dim strDirectory, strFile
strDirectory = "c:\Folder"
strFile = "\Hidden.bat"
If objFSO.FolderExists(strDirectory) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFolder = objFSO.CreateFolder(strDirectory)
End If
If objFSO.FileExists(strDirectory & strFile) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFile = objFSO.CreateTextFile(strDirectory & strFile)
End If
set objFolder = nothing
set objFile = nothing
Const fsoForAppend = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objTextStream
Set objTextStream = objFSO.OpenTextFile("C:\Folder\Hidden.bat", fsoForAppend)
objTextStream.WriteLine "attrib ""Folder"" +s +h"
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run """C:\Folder\Hidden.bat"""
Set objShell = Nothing发布于 2016-08-07 09:41:16
而不创建任何用于隐藏文件夹的批处理文件:
Option Explicit
Dim objFSO,objFolder,strDirectory,Command,Result,objShell
Set objFSO = CreateObject("Scripting.FileSystemObject")
strDirectory = "C:\Folder"
If objFSO.FolderExists(strDirectory) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFolder = objFSO.CreateFolder(strDirectory)
End If
set objFolder = nothing
Command = "Cmd /c Attrib +s +h "& DblQuote(strDirectory) &""
Set objShell = CreateObject("WScript.Shell")
Result = objShell.Run(Command,0,True)
Set objShell = Nothing
'****************************************************************
Function DblQuote(str)
DblQuote = Chr(34) & Str & Chr(34)
End Function
'****************************************************************发布于 2016-08-07 06:44:00
关闭打开的TextStream文件。 object.Close
不需要帮助。
在使用之前,您需要在写完它之后关闭它。
https://stackoverflow.com/questions/38811042
复制相似问题