Ветеран
Сообщения: 27449
Благодарности: 8086
|
Профиль
|
Отправить PM
| Цитировать
Скрытый текст
Код:
Option Explicit
Const ReadOnly = 1
Const Hidden = 2
Const System = 4
Dim strSourceFolder
Dim objFSO
Dim objFile
Dim strDesktopIniFile
If WScript.Arguments.Count = 1 Then
strSourceFolder = WScript.Arguments.Item(0)
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strSourceFolder) Then
strDesktopIniFile = objFSO.BuildPath(strSourceFolder, "desktop.ini")
For Each objFile In objFSO.GetFolder(strSourceFolder).Files
If StrComp(objFSO.GetExtensionName(objFile.Name), "ico", vbTextCompare) = 0 Then
objFile.Name = objFSO.GetBaseName(strSourceFolder) & ".ico"
objFile.Attributes = objFile.Attributes Or Hidden
If objFSO.FileExists(strDesktopIniFile) Then
With objFSO.GetFile(strDesktopIniFile)
.Attributes = .Attributes And Not (System Or Hidden)
End With
End If
With objFSO.CreateTextFile(strDesktopIniFile, True)
.WriteLine "[.ShellClassInfo]"
.WriteLine "IconResource=" & objFile.Name & ",0"
If Left(objFSO.GetFileVersion("C:\Windows\System32\ntdll.dll"), 2) <> "6." Then
.WriteLine "IconFile=" & objFile.Name
.WriteLine "IconIndex=0"
End If
.Close
End With
With objFSO.GetFile(strDesktopIniFile)
.Attributes = .Attributes Or (System Or Hidden)
End With
With objFSO.GetFolder(strSourceFolder)
.Attributes = .Attributes Or ReadOnly
End With
Exit For
End If
Next
Else
WScript.Echo "Can't find source folder [" & strSourceFolder & "]."
WScript.Quit 2
End If
Set objFSO = Nothing
Else
WScript.Echo "Usage: cscript.exe //nologo """ & WScript.ScriptName & """ <Source folder>"
WScript.Quit 1
End If
WScript.Quit 0
BOBAT, и тем не менее, правильнее будет всё же привязываться к ico-файлу, а не к фону папки.
C:\Program Files\Attach Icon to Folder\Attach Icon to Folder 2.vbs
Код:
Option Explicit
Const ReadOnly = 1
Const Hidden = 2
Const System = 4
Dim strIconFile
Dim strSourceFolder
Dim objFSO
Dim strDesktopIniFile
If WScript.Arguments.Count = 1 Then
strIconFile = WScript.Arguments.Item(0)
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strIconFile) Then
If StrComp(objFSO.GetExtensionName(strIconFile), "ico", vbTextCompare) = 0 Then
With objFSO.GetFile(strIconFile)
strSourceFolder = .ParentFolder.Path
.Attributes = .Attributes Or Hidden
End With
strDesktopIniFile = objFSO.BuildPath(strSourceFolder, "desktop.ini")
If objFSO.FileExists(strDesktopIniFile) Then
With objFSO.GetFile(strDesktopIniFile)
.Attributes = .Attributes And Not (System Or Hidden)
End With
End If
With objFSO.CreateTextFile(strDesktopIniFile, True)
.WriteLine "[.ShellClassInfo]"
.WriteLine "IconResource=" & objFSO.GetFileName(strIconFile) & ",0"
If Left(objFSO.GetFileVersion("C:\Windows\System32\ntdll.dll"), 2) <> "6." Then
.WriteLine "IconFile=" & objFSO.GetFileName(strIconFile)
.WriteLine "IconIndex=0"
End If
.Close
End With
With objFSO.GetFile(strDesktopIniFile)
.Attributes = .Attributes Or (System Or Hidden)
End With
With objFSO.GetFolder(strSourceFolder)
.Attributes = .Attributes Or ReadOnly
End With
Else
WScript.Echo "Icon file [" & strIconFile & "] contain not an <ico> extension."
WScript.Quit 3
End If
Else
WScript.Echo "Can't find icon file [" & strIconFile & "]."
WScript.Quit 2
End If
Set objFSO = Nothing
Else
WScript.Echo "Usage: cscript.exe //nologo """ & WScript.ScriptName & """ <Icon file>"
WScript.Quit 1
End If
WScript.Quit 0
Файл реестра для него:
Код:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\icofile\shell\Attach Icon to Folder 2]
@="Назначить выбранный значок папке"
"HasLUAShield"=""
[HKEY_CLASSES_ROOT\icofile\shell\Attach Icon to Folder 2\command]
@=hex(2):22,00,25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,\
00,25,00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,77,00,\
73,00,63,00,72,00,69,00,70,00,74,00,2e,00,65,00,78,00,65,00,22,00,20,00,22,\
00,25,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,46,00,69,00,6c,00,65,00,\
73,00,25,00,5c,00,41,00,74,00,74,00,61,00,63,00,68,00,20,00,49,00,63,00,6f,\
00,6e,00,20,00,74,00,6f,00,20,00,46,00,6f,00,6c,00,64,00,65,00,72,00,5c,00,\
41,00,74,00,74,00,61,00,63,00,68,00,20,00,49,00,63,00,6f,00,6e,00,20,00,74,\
00,6f,00,20,00,46,00,6f,00,6c,00,64,00,65,00,72,00,20,00,32,00,2e,00,76,00,\
62,00,73,00,22,00,20,00,22,00,25,00,31,00,22,00,00,00
Назначает указанный скрипт контекстному меню ico-файла.
|