my below code is not working....It can create up to Location10 not more than that, please help.

'On Error Resume Next


strComputer = "."

Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\default:StdRegProv")

strKeyPath = "Software\Microsoft\Office\12.0\Access\Security\Trusted Locations\"

strWriteLn = "C:\Program Files\Microsoft Office\"

strvalName = "Location"


Set Objshell = CreateObject("wscript.shell")


Chk_N_Write_Line ( strWriteLn )


Sub Chk_N_Write_Line ( strWriteLn )

objReg.EnumKey HKEY_CURRENT_USER, strKeyPath, arrSubKeys

For Each subkey In arrSubKeys

subkey1 = Replace (LCase(subkey), "location", "") 'Split(Subkey, "n")


subkey1 = subkey1+intcount

strvalName = Left (strvalName,8) & subkey1

A = "HKEY_CURRENT_USER" & "\" & strkeypath & strvalName & "\Path"

objshell.regwrite A,strWriteLn, "REG_SZ"

End Sub

0 Comments   [ - ] Hide Comments


Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
Answer this question or Comment on this question for clarity


From a cursory glance at your code, it only gets up to 'Location10' because you have 10 sub-keys beneath the 'Trusted Location' key.

I'm guessing that you want to add a Trusted Location programmatically? According to what I've read about this path, the sub-keys can be called whatever you like, so long as it's unique. My gambit would be to use a GUID (there's lots of GUID-generation VBScript code around) for that prupose. Note also the 'AllowSubFolders' key, which should be a sub-key of the new 'Trusted Location' sub-key. For reference, see here.
Answered 01/03/2012 by: VBScab
Red Belt

Please log in to comment
Thanks for your valuable reply.
Answered 01/03/2012 by: MadForMsi
Blue Belt

  • Did you work this one out? We're having the same problem with Office 2010.. Does this script enable trusted location on network drives?
Please log in to comment