Hi Steve
I don't think that's what Im asking, but then again I'm rather at sea on
this. I can return the paths of standard system folders (My Documents,
Recent etc.) I've done so to create my new folder (C:\Documents and
settings\blahblahblah...\My Documents\\MyNewPlaces) that I now want to add to
Office's 'My Places'. So I have the string path of my Folder already. Now
I want to write this to the registry so it gets added to Office's My PLaces.
I've tried to figure this out by (1) adding a folder manually to Word's 'My
Places' and then (2) looking at the registry key created (at
HKCU\Software\Microsoft\Office\...\Common\Open Find\Places\UserDefinedPlaces
). The keys I see that contain apparently meaningful data (to me!) are 'Name'
(as it appears in the 'My PLaces' bar) and a PIDL. So I figure I've got to
generate a PIDL from my folder's path string and write it to that key.
I've seen online various (mostly vb) references to generating a PIDL from
shell or API functons like SHGetSpecialFolderLocation. So I figured I beed to
solve that, but am struggling. Or ask here. As really, I'm out of my depth
(never written to registry before) and haven't mastered API etc. Also its
quite possible I haven't figured out how to write this to the registry or
what it needs to be
Any clues?
Thanks, Mike
> Mike,
>
[quoted text clipped - 29 lines]
> >
> > Mike
Steve Yandl - 27 Dec 2007 13:26 GMT
Mike,
I've not yet tested but the information I've seen says you create a new
subkey of UserDefinedPlaces (such as Place1, Place2, etc.) and give it two
values, "Name" and "Path". The data for name will be the string that is the
name of your folder and path is the string representing the path. I suspect
that you can use either the regular path or the PIDL for the folder as
entries in the registry and Word will respond the same way. Since you're
creating the folder and know the path, try using that instead of determining
the PIDL.
Steve
> Hi Steve
> I don't think that's what Im asking, but then again I'm rather at sea on
[quoted text clipped - 71 lines]
>> >
>> > Mike
Steve Yandl - 27 Dec 2007 23:10 GMT
Mike,
I figured out how to use Windows API to return the PIDL but the value is
returned as a long integer and converting to binary or DWord didn't appear
to deliver the value needed for the registry. However, when I wrote a
subroutine to create the new subkey and entered a value named "Path" with
the path to a new folder for the MyPlaces bar, it ended up being converted
to a pidl value (after testing in Word and then checking using regedit).
Below is a sample subroutine that might help you out. I'm using WMI to read
from and write to the registry rather than the RegWrite method of the
windows script host shell object like you planned. Just alter the top two
lines in the sub to reflect the name and path to the folder you want added
to MyPlaces.
_____________________________________________
Sub NewMyPlacesFldr()
strMyPlaceName = "Testing Folder"
strMyPlacePath = "C:\Test"
On Error Resume Next
Const HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & _
strComputer & "\root\default:StdRegProv")
strKeyPath = "Software\Microsoft\Office\" _
& Application.Version & "\Common\Open Find\Places\UserDefinedPlaces"
objRegistry.EnumKey HKEY_CURRENT_USER, strKeyPath, arrSubkeys
intNew = -1
For Each objSubkey In arrSubkeys
intPlace = CInt(Right(objSubkey, Len(objSubkey) - 5))
If intPlace > intNew Then
intNew = intPlace
End If
Next
intNew = intNew + 1
strKeyPathNew = strKeyPath & "\Place" & CStr(intNew)
objRegistry.CreateKey HKEY_CURRENT_USER, strKeyPathNew
strValue = strMyPlaceName
strValueName = "Name"
objRegistry.SetStringValue HKEY_CURRENT_USER, _
strKeyPathNew, strValueName, strValue
strValue = strMyPlacePath
strValueName = "Path"
objRegistry.SetStringValue HKEY_CURRENT_USER, _
strKeyPathNew, strValueName, strValue
End Sub
_____________________________________________
Steve Yandl
> Hi Steve
> I don't think that's what Im asking, but then again I'm rather at sea on
[quoted text clipped - 71 lines]
>> >
>> > Mike
MikeB77 - 28 Dec 2007 09:20 GMT
Hi Steve
thanks so much for your answer and code solution - I tried it and it worked
straight out of the box. As you said, writing the path string was converted
to a pidl when checking with regedit (xp, wd2007). My next task is to figure
out WMI so I can fully understand this. I'm so please you got interested in
this one - saved me many hours of sleep!
Mike
> Mike,
>
[quoted text clipped - 135 lines]
> >> >
> >> > Mike
Steve Yandl - 28 Dec 2007 15:31 GMT
Mike,
You're very welcome.
WMI takes some getting used to. If you want to discover some of the ways
you can use it, check out
http://www.microsoft.com/technet/scriptcenter/default.mspx
The site is targeting IT types who primarily work with vbScript or
Powershell but much of what is there can be utilized by people who mostly
work with VBA. Had you proceeded with your initial plan to access the
registry through the "WScript.Shell" object's methods, I think you would
have had a real challenge determining the subkeys (Place0, Place1, Place2,
etc.) that were already present before you would have been able to add a
new, appropriately named, subkey.
Steve
> Hi Steve
> thanks so much for your answer and code solution - I tried it and it
[quoted text clipped - 169 lines]
>> >> >
>> >> > Mike