2011-04-12 7 views
0

이 스크립트의 전체 목표 : 직원에게 보내고 각 랩톱에 즐겨 찾기 모음 (웹 폴더)을 추가하십시오. 지금까지 필자는 모든 폴더를 즐겨 찾기에 추가하는 스크립트를 작성 (소스 화 및 적용)했지만 끝에 즐겨 찾기 목록에 추가되었습니다..vbs 즐겨 찾기 목록을 정렬하려면

날짜별로 즐겨 찾기 목록을 정렬하거나 목록의 맨 위에 폴더를 삽입하는 것이 더 나은 방법으로 현재 사용자 즐겨 찾기의 순서를 변경하지 않으려합니다.

이 그들이 인트라넷 모든

'Create Network Folder******************************************* 


Option Explicit 
MsgBox("Click OK to begin installing all of the Web Folders under My Network Places.") 


Sub CreateNetworkFolder(siteURL, siteName) 

Dim iRes, jRes, MT, TT 
Dim SH, newPath 
Dim objFso, f, fs, g 

Dim bString 
Dim ltrIndex 
Dim nameLength, urlLength, urlCutoff 
Dim aFile 
Dim filesys 

'ForWriting (2) is the attribute to be set when writing to a file. 
Const ForWriting = 2 

nameLength = Len(siteName) 
urlLength = Len(siteURL) 
'44 seems to be the length where we have to change a 00 to a 01. 
urlCutoff = 44 

Set objFso = CreateObject("Scripting.FileSystemObject") 

Set SH = WScript.CreateObject("WScript.Shell") 

'Create the folder under Favorites that will hold the target.lnk file 
newPath = SH.SpecialFolders("Favorites") & "\" & "BCKM" & "\" 

'Creating the housing folder for BCKM 
Set filesys = CreateObject("Scripting.FileSystemObject") 

If filesys.FolderExists(newPath) Then 
    'msgbox "File esists" 
    else 
    'msgbox "file does not exist" 
    objFso.CreateFolder(newPath) 
End If 



'Create the webfolder for each section 
newPath = SH.SpecialFolders("Favorites") & "\" & "BCKM" & "\" & siteName 
objFso.CreateFolder(newPath) 

'We ceate a Desktop.ini file 
Set fs = CreateObject("Scripting.FileSystemObject") 
aFile = newPath & "\Desktop.ini" 

Set f = fs.OpenTextFile(aFile, ForWriting, True) 

'Write the data lines that will make this a folder shortcut. 
f.WriteLine "[.ShellClassInfo]" 
f.WriteLine "CLSID2={0AFACED1-E828-11D1-9187-B532F1E9575D}" 
f.WriteLine "Flags=2" 
f.WriteLine "ConfirmFileOp=0" 



f.Close 

'We make Desktop.ini a system-hidden file by assigning it attribute of 6 
Set fs = CreateObject("Scripting.FileSystemObject") 
Set g = fs.GetFile(newPath & "\Desktop.ini") 
g.Attributes = 6 

'We make the folder read-only by assigning it 1. 
Set fs = CreateObject("Scripting.FileSystemObject") 
Set g = fs.GetFolder(newPath) 
g.Attributes = 1 

'This is where we construct the target.lnk file byte by byte. Most of 
'the lines are shown in 16 byte chunks, 
'mostly because that is the way I saw it in the Debug utility I was 
'using to inspect shortcut files. 

'Line 1, 16 bytes 
bString = Chr(&H4C) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H01) & Chr(&H14) & Chr(&H02) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&HC0) & Chr(&H00) & Chr(&H00) & Chr(&H00) 

'Line 2, 16 bytes 
bString = bString & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H46) & Chr(&H81) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) 

'Line 3, 16 bytes 
bString = bString & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) 

'Line 4., 16 bytes. 13th byte is significant. 
bString = bString & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H01) & Chr(&H00) & Chr(&H00) & Chr(&H00) 

'Line 5. 13th byte is significant. 
bString = bString & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) 

'When I was analyzing the next byte of shortcuts I created, I found 
'that it is set to various values, 
'and I have no idea what they are referring to. In desperation I tried 
'substituting some values. 
'00 caused a crash of Explorer. FF seeems to work fine for all. 
'If anyone can get back to me on what this byte is or why FF works, 
'please contact me. 
bString = bString & Chr(&HFF) 

'This byte is 00 if the URL is 44 characters or less, 01 if greater. 
If urlLength > urlCutoff Then 
bString = bString & Chr(&H01) 
Else 
bString = bString & Chr(&H00) 
End If 

bString = bString & Chr(&H14) & Chr(&H00) 

'Line 6, 16 bytes 
bString = bString & Chr(&H1F) & Chr(&H50) & Chr(&HE0) & Chr(&H4F) & Chr(&HD0) & Chr(&H20) & Chr(&HEA) & Chr(&H3A) & Chr(&H69) & Chr(&H10) & Chr(&HA2) & Chr(&HD8) & Chr(&H08) & Chr(&H00) & Chr(&H2B) & Chr(&H30) 

'Line 7, 16 bytes 
bString = bString & Chr(&H30) & Chr(&H9D) & Chr(&H14) & Chr(&H00) & Chr(&H2E) & Chr(&H00) & Chr(&H00) & Chr(&HDF) & Chr(&HEA) & Chr(&HBD) & Chr(&H65) & Chr(&HC2) & Chr(&HD0) & Chr(&H11) & Chr(&HBC) & Chr(&HED) 

'Line 8, 16 bytes 
bString = bString & Chr(&H00) & Chr(&HA0) & Chr(&HC9) & Chr(&H0A) & Chr(&HB5) & Chr(&H0F) & Chr(&HA4) 

'This byte is 00 if the URL is 44 characters or less, 01 if greater. 
If urlLength > urlCutoff Then 
bString = bString & Chr(&H01) 
Else 
bString = bString & Chr(&H00) 
End If 

bString = bString & Chr(&H4C) & Chr(&H50) & Chr(&H00) & Chr(&H01) & Chr(&H42) & Chr(&H57) & Chr(&H00) & Chr(&H00) 

'Line 9, 16 bytes 
bString = bString & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H10) & Chr(&H00) 

'Line 10, 2 bytes 
bString = bString & Chr(&H00) & Chr(&H00) 

'The next byte represents the length of the site name. 
bString = bString & Chr(nameLength) 

'Take the site name, and write each letter, preceeded by a "00" 
'character. 

For ltrIndex = 1 to nameLength 
bString = bString & Chr(&H00) & Mid(siteName, ltrIndex, 1) 
Next 

'Middle line, separates the Folder Name from the URL. 3 bytes. 
bString = bString & Chr(&H00) & Chr(&H00) & Chr(&H00) 

'The next byte represents the length of the site URL. 
bString = bString & Chr(urlLength) 

'Take the site URL, and write each letter, preceeded by a "00" 
'character. 
For ltrIndex = 1 to urlLength 
bString = bString & Chr(&H00) & Mid(siteURL, ltrIndex, 1) 
Next 

'Last line, 13 bytes 
bString = bString & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&H00) 

'Let's create the target.lnk file. 
Set fs = CreateObject("Scripting.FileSystemObject") 
aFile = newPath & "\target.lnk" 
'aFile = newPath & "\vb.sss" 
Set f = fs.OpenTextFile(aFile, ForWriting, True) 
f.Write bString 
f.Close 

End Sub 

'This is where you specify the folders to add 

CreateNetworkFolder "http://collaboration.au.xxx.com/dav/1.11.685732/", "Clients" 
CreateNetworkFolder "http://collaboration.au.xxx.com/dav/1.11.685930/", "Workspaces" 
CreateNetworkFolder "http://collaboration.au.xxx.com/dav/1.11.685941/", "Practice Management" 
CreateNetworkFolder "http://collaboration.au.xxx.com/dav/1.11.685945/", "Tips" 
CreateNetworkFolder "http://collaboration.au.xxx.com/dav/1.21.8015/", "Discussion Board" 


MsgBox("All Web Folders Added Succesfully. Please check Favorites to Confirm. Press OK") 

답변

0

처음에 있기 때문에 내가 지금까지 링크가 왜 그런 기괴한 방식으로 바로 가기를 만들려면 어떻게해야합니까, 일을 못해 한 무엇인가? WshShell.CreateShortcut을 호출하고 결과로 표시되는 WshShortcut 개체의 속성을 설정하면 훨씬 쉽게 처리 할 수 ​​있습니다.


지금 당신의 정렬 질문. 즐겨 찾기의 상태를 관리하는 두 개의 레지스트리 키가 있습니다.

  • HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder\Favorites - Internet Explorer에 표시된 즐겨 찾기에 해당합니다.
  • HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder\Favorites - Windows 시작 메뉴> 즐겨 찾기에 표시되는 즐겨 찾기에 해당합니다.

즐겨 찾기의 정렬 순서는이 키의 DWORD Order 값에 저장됩니다. 즐겨 찾기에있는 각 폴더에는 Order 값을 가진 해당 하위 키가 있습니다. Order 값의 내부 구조는 문서화되어 있지 않지만 this article은 분석과 설명을 제공합니다.

따라서 정렬 순서를 변경하려면 스크립트에서이 값을 수정 해보십시오 (예 : WMI StdRegProv.GetDWORDValueStdRegProv.SetDWORDValue 메서드 사용). 그러나, 그것은 다소 까다로울 것 같아요.

위의 키를 레지스트리에서 삭제하면 sort Favorites in alphabetical order (옵션 인 경우)해야합니다.

2

Helen의 답변에 따라 레지스트리 키의 "문서화되지 않은 데이터"는 .lnk 파일이 디스크에 저장된 폴더에 상대적인 PCUITEMID_CHILD (MSDN 참조)의 이진 형식입니다. 이를 위해서는 C++와 같은 COM 인터페이스에 액세스 할 수있는 언어를 사용해야합니다.

레지스트리 키에 기사에 설명 된대로 헤더가 있지만 기록은 단순히 레코드 길이 (DWORD), '주문'값 (DWORD) 및 PCUITEMID_CHILD 데이터입니다.

typedef struct _FAV_ORDERED_HEADER_ 
{ 
    DWORD dwFormatValue; // Typically 8 for known Windows versions that use this 
    DWORD dwSubFormatValue; // Typically 2 for known Windows that use this 
    DWORD dwTotalDataLen; // Total bytes in all data 
    DWORD dwReserved;  // No known use 
    DWORD dwNumRecords;  // Number of records 
} FAV_ORDERED_HEADER; 

typedef struct _FAV_ORDERED_RECORD_ 
{ 
    DWORD dwLenRecord;  // Length of each record (skip this bytes to get next record) 
    DWORD dwOrderValue;  // Negative if not ordered (add to end), positive if on list first 
    ITEMIDLIST pidlLinkData; // PIDL data for the individiual link - need to use a PIDL compare to be able to compare to actual .lnk file links. 
} FAV_ORDERED_RECORD; 
  1. 먼저 사용 SHGetFolderLocation (NULL, CSIDL_FAVORITES는, NULL, NULL, & ppidlFavorites)는 즐겨 찾기 폴더의 PIDLIST_ABSOLUTE를 얻을 수 있습니다.

  2. 사용 IShellFolder 인스턴스가 즐겨 찾기에 도착하는 SHGetDesktopFolder()를 통해 데스크톱 IShellFolder 인터페이스 포인터를 가져옵니다 IShellFolder IShellFolder :: BindToObject (ppidlFavorites, NULL, IID_IShellFolder, & pFavoritesShellFolder)를 통해

  3. 데이터를 pidl 매개 변수에 넣고 IShellFolder :: GetDisplayNameOf()를 호출하여 pFavoritesShellFolder를 사용하고 문자열을 가져올 SHGDNF 매개 변수를 설정합니다. 일반적으로이 메서드를 통해 표시 이름, URL 등을 가져옵니다.

셸 링크의 Windows 7/8 '즐겨 찾기'에 적용됩니다. 그러나 IKnownFolderManager :: GetFolder (FOLDERID_Links, & pLinksKnFolder)를 사용하여 필요한 IShellFolder를 최종적으로 검색 할 수 있도록 IKnownFolder를 가져와야합니다. 즉, PIDLIST_ABSOLUTE을 올바르게 가져올 수 있습니다. 레지스트리 키 (링크 주문시) :

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Modules\CommonPlaces 
관련 문제