ADO DOT NET Posted December 2, 2009 Posted December 2, 2009 Hi everybody :) I wanna create a folder in My Documents, named "My Information" for example! And customize its ICON by placing a "Desktop.ini" file into that. So I wrote this code which works perfect, but I don't know why it does not show the ICON as expected :( 'Create Directory If Not My.Computer.FileSystem.DirectoryExists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\My Information") Then System.IO.Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\My Information") End If 'Create File Dim FileContent As String = "[.ShellClassInfo]" + vbNewLine + "IconFile=%ProgramFiles%\Company\Product\Program.exe" + vbNewLine + "IconIndex=0" + vbNewLine + "InfoTip=Information collected using our application" If Not My.Computer.FileSystem.FileExists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\My Information\Desktop.ini") Then My.Computer.FileSystem.WriteAllText(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\My Information\Desktop.ini", FileContent, False) End If Dim FileDetail As IO.FileInfo = My.Computer.FileSystem.GetFileInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\My Information\Desktop.ini") FileDetail.Attributes = IO.FileAttributes.Hidden + IO.FileAttributes.System Quote
Administrators PlausiblyDamp Posted December 2, 2009 Administrators Posted December 2, 2009 Try setting the folder to ReadOnly and see if that fixes the problem, I am sure I read something about this once but haven't tried it myself. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
ADO DOT NET Posted December 2, 2009 Author Posted December 2, 2009 Hi PlausiblyDamp, Thank you very much for your tip. However, it won't work :( I really don't know what should I do. Even if I use Windows to Customize this folder for me, it will create the same file as me! When Windows creates it, it works! :confused: Please help me :( Quote
Administrators PlausiblyDamp Posted December 2, 2009 Administrators Posted December 2, 2009 Declare Auto Function PathMakeSystemFolder Lib "shlwapi.dll" Alias "PathMakeSystemFolder" (ByVal pszPath As String) As Integer Call the above function passing the folder path as an argument - that sorts out the attributes correctly. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
ADO DOT NET Posted December 3, 2009 Author Posted December 3, 2009 Well, thanks :) This code must work now, but it's not :( Declare Auto Function PathMakeSystemFolder Lib "shlwapi.dll" Alias "PathMakeSystemFolder" (ByVal pszPath As String) As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Create Directory If Not My.Computer.FileSystem.DirectoryExists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\My Information") Then System.IO.Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\My Information") End If PathMakeSystemFolder(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\My Information") 'Create File Dim FileContent As String = "[.ShellClassInfo]" + vbNewLine + "IconFile=%ProgramFiles%\Company\Product\Program.exe" + vbNewLine + "IconIndex=0" + vbNewLine + "InfoTip=Information collected using our application" If Not My.Computer.FileSystem.FileExists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\My Information\Desktop.ini") Then My.Computer.FileSystem.WriteAllText(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\My Information\Desktop.ini", FileContent, False) End If Dim FileDetail As IO.FileInfo = My.Computer.FileSystem.GetFileInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\My Information\Desktop.ini") FileDetail.Attributes = IO.FileAttributes.Hidden + IO.FileAttributes.System End Sub Quote
Administrators PlausiblyDamp Posted December 3, 2009 Administrators Posted December 3, 2009 Try removing the line FileDetail.Attributes = IO.FileAttributes.Hidden + IO.FileAttributes.System from the end as it might reseting the attributes set by PathMakeSystemFolder call. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
ADO DOT NET Posted December 4, 2009 Author Posted December 4, 2009 Hi, Thank you very much for your help :) So this final code still does not work on XP: Declare Auto Function PathMakeSystemFolder Lib "shlwapi.dll" Alias "PathMakeSystemFolder" (ByVal pszPath As String) As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Create Directory If Not My.Computer.FileSystem.DirectoryExists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\My Information") Then System.IO.Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\My Information") End If 'Create File Dim FileContent As String = "[.ShellClassInfo]" + vbNewLine + "IconFile=%ProgramFiles%\Company\Product\Program.exe" + vbNewLine + "IconIndex=0" + vbNewLine + "InfoTip=Information collected using our application" If Not My.Computer.FileSystem.FileExists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\My Information\Desktop.ini") Then My.Computer.FileSystem.WriteAllText(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\My Information\Desktop.ini", FileContent, False) End If PathMakeSystemFolder(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\My Information") End Sub :( Quote
Administrators PlausiblyDamp Posted December 4, 2009 Administrators Posted December 4, 2009 No idea then, just tried it on my pc and other than changing the path in the line Dim FileContent As String = "[.ShellClassInfo]" + vbNewLine + "IconFile=%ProgramFiles%\Company\Product\Program.exe" + vbNewLine + "IconIndex=0" + vbNewLine + "InfoTip=Information collected using our application" to point to an executable that exists on my hard drive it worked perfectly. I am running windows 7 but that shouldn't make a difference as the API has been in existence since NT 4 with IE 4! Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.