prasiddutta
asked on
Write file in each Drive
Hi,
i want add "autorun.inf" in each drive with few attributes like faReadOnly or faHidden or faSysFile or faArchive. Anyoone can help me with source code? If previously "autorun.inf" exist in drive then also delete it and create new one.
Thanks
i want add "autorun.inf" in each drive with few attributes like faReadOnly or faHidden or faSysFile or faArchive. Anyoone can help me with source code? If previously "autorun.inf" exist in drive then also delete it and create new one.
Thanks
ASKER
Yes all autorun.inf same and it'll protect my all drive from autorun virus.
ASKER
I make some mistake in your code. Can you share Unit? or upload code elsewhere? Thanks
what do you mean you made some mistake ? Can't you copy the code I gave you ?
ASKER
give much error in your code. I use Delphi XE2
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Now I just call
Nice work man. You are great, your first code was a error related PChar and so on.
And I ask one thing. Suppose I insert a USB stck and autorun.inf is found with virus. I want to block instantly and remove inf file. Possible.
CreateAutorun;
Nice work man. You are great, your first code was a error related PChar and so on.
And I ask one thing. Suppose I insert a USB stck and autorun.inf is found with virus. I want to block instantly and remove inf file. Possible.
yes it's possible. Don't quite remind how to intercept removable drive insertion, but that exists.
Post a new question
Post a new question
ASKER
ASKER
Sometime I saw this error:
"Cannot create file "C:\AutoRun.inf". Access is denied." and program hanged.
"Cannot create file "C:\AutoRun.inf". Access is denied." and program hanged.
I suppose some process is locking that file just to stop you from erasing it... Virus ?
ASKER
no virus. I think it don’t got permission to delete.
Exception occur when I call
CreateAutorun;
Exception occur when I call
CreateAutorun;
I guess you'll have to find a way to change the permissions or remove lock, that's another problem.
In the meantime, here I improve the CreateAutorun function (tapping error, so that clean up is done correctly)
In the meantime, here I improve the CreateAutorun function (tapping error, so that clean up is done correctly)
for i:=1 to Length(DriveList) do
try
// fill Autorun here if file is specific to each drive
AutoRunFileName[1]:=DriveList[i];
AutoRun.SaveToFile(AutoRunFileName);
// set file attributes
FileSetAttr(AutoRunFileName, faReadOnly Or faHidden );
except
// manage here if you can't save the file
end;
ASKER
Thanks, this loop work well
What will be the content of this autorun ? Same for all drives ?
you'll have also to be able to list the drives you want.
Here it is all wrapped in
Open in new window