Reputation:
I have got the "Permission Denied" when i Opened my file to write somethings in it.
Dim CustomDriveIcon As String CustomDriveIcon = "CustomDriveIcon_" & txtDrive.Text & ".reg" Dim newFIle Dim FSO Set FSO = CreateObject("Scripting.FileSystemObject") Set newFIle = FSO.CreateTextFile(CustomDriveIcon)
DoEvents
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
And I get the error on line "Open CustomDriveIcon For Output As #iFileNo
" whats the problem?
Upvotes: 1
Views: 273
Reputation: 30398
You've opened the file twice, once with CreateTextFile and once with the Open statement. You can't open the file twice, so it fails on the second time.
Just delete these lines - you don't need them.
Dim newFIle Dim FSO
Set FSO = CreateObject("Scripting.FileSystem Object")
Set newFIle = FSO.CreateTextFile(CustomDriveIcon )
Upvotes: 3