1

当我打开我的文件在其中写一些东西时,我得到了“权限被拒绝”。

    Dim CustomDriveIcon As String
    CustomDriveIcon = "CustomDriveIcon_" & txtDrive.Text & ".reg"
     Dim newFIle
     Dim FSO
     Set FSO = CreateObject("Scripting.FileSystemObject")
     Set newFIle = FSO.CreateTextFile(CustomDriveIcon)

做事件

Dim sFileText As String
Dim iFileNo As Integer
  iFileNo = FreeFile
Open CustomDriveIcon For Output As #iFileNo
 Print #iFileNo, "Windows Registry Editor Version 5.00"
 Print #iFileNo, ""
 Print #iFileNo, "[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\C\DefaultIcon]"
 Print #iFileNo, "@=" & Chr(34) & "\" & Chr(34) & txtIconPath & "\" & Chr(34) & Chr(34) '@="\"C\""
Close #iFileNo

我在“”线上得到错误是Open CustomDriveIcon For Output As #iFileNo什么问题?

4

1 回答 1

3

您已打开文件两次,一次使用 CreateTextFile,一次使用 Open 语句。您无法两次打开该文件,因此第二次失败。

只需删除这些行 - 你不需要它们。

Dim newFIle Dim FSO
Set FSO = CreateObject("Scripting.FileSystem Object") 
Set newFIle = FSO.CreateTextFile(CustomDriveIcon )
于 2013-06-01T16:01:29.647 回答