finding and writing a pidl to reg

M

MikeB77

using vba (I know no other) I'm trying to automate adding a location to "My
Places" on the various file dialogues in Word (02 and 07). I've found its
about writing a registry key to:
HKCU\Software\Microsoft\Office\" & Application.Version & "\Common\Open
Find\Places\UserDefinedPlaces

I've opted for wshShell.regwrite as it appears VBA private profile strings
can't write to this and many other keys. All good. Writing the name key looks
OK but now I've got to figure out a PIDL for the location of my folder and
write that. I've discovered what a PIDL is but am struggling to find how to
create one: I see various references to shell functions but can't make any
work.

Can someone offer some help here?? (XP, word 02 and 07)

thanks in advance

Mike
 
S

Steve Yandl

Mike,

From instructions I've seen for making the registry entries to add a new
folder to the 'MyPlaces' bar, you're needing to supply a path string as data
for the path value. I'm guessing that this folder is a folder made
available by Windows or it's a subfolder of such a shell folder. So, what
you're really asking is how to return the path to one or more of the
standard shell folders which would then allow you to build a path to your
new 'MyPlaces' folder. Is that the case?


Steve
 
M

MikeB77

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
 
S

Steve Yandl

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
 
S

Steve Yandl

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
 
M

MikeB77

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
 
S

Steve Yandl

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top