Update Windows Registry w/Access

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Greetings!

I'm looking for some generic code to read/update the system registry.
Specifically, I need to update the path (environment variable).

I tried using the shell command, but "path" or "path.com" is not recognized.

Any assistance would be greatly appreciated. If you like, you may forward
recommendation to (e-mail address removed) or (e-mail address removed).

Thank you in advance for your assistance.

~ Bob Bonta ~
 
Hi, Bob.
I'm looking for some generic code to read/update the system registry.

You will find example code to read and manipulate the Windows Registry in
this Access 97 DB file:

http://www.amazecreations.com/datafast/GetFile.aspx?file=A97RegistryFns.zip

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
Beware to those who use munged addresses: known newsgroup E-mail harvesters
for spammers are (e-mail address removed) and (e-mail address removed)

- - -
When you see correct answers to your question posted in Microsoft's Online
Community, please sign in to the Community and mark these posts as "Answers,"
so that all may benefit by filtering on "Answered questions" and quickly
finding the right answers to similar questions. Remember that questions
answered the quickest are often from those who have a history of rewarding
the contributors who have taken the time to answer questions correctly.
 
Gunny - thanx for your quick response. While what you provided will help, I
am still in need of a way I can manipulate/modify the path statement - the
environment variable. Any thoughts - anyone?
 
Hi, Bob.
I
am still in need of a way I can manipulate/modify the path statement - the
environment variable.

The Environment PATH variable can be set in the Windows Registry in the
"Path" subkey of this Windows Registry key (all one line):

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session
Manager\Environment

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
Beware to those who use munged addresses: known newsgroup E-mail harvesters
for spammers are (e-mail address removed) and (e-mail address removed)

- - -
When you see correct answers to your question posted in Microsoft's Online
Community, please sign in to the Community and mark these posts as "Answers,"
so that all may benefit by filtering on "Answered questions" and quickly
finding the right answers to similar questions. Remember that questions
answered the quickest are often from those who have a history of rewarding
the contributors who have taken the time to answer questions correctly.
 
PATH is an environmental variable, not a command. The command to use is
SET. Try opening a command window and typing:

SET /? |more

to get all the instructions. I recommend that you use a string variable
to store the command that you send to Shell so that you can more easily
debug it:


Dim strShell as String

strShell = "SET Path = ........."

Call Shell(strShell)

HTH,

Kevin
 
Thank you Kevin.

In a dos prompt, if you type path all by it's little ol' lonesome, it will
return the path variable. The shell command in Access will not recognize the
path command - neither will it recognize the set command in a dos shell.

'69 Camaro provided me with exactly what I needed: code to read/modify the
registry, and the key wherein the path variable I seek resides.

Thank you for your assistance - you and '69 Camaro!
 
You're welcome!

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
Beware to those who use munged addresses: known newsgroup E-mail harvesters
for spammers are (e-mail address removed) and (e-mail address removed)
 
The shell command in Access will not recognize the
path command - neither will it recognize the set command in a dos shell.

Yes it will, but - as with any internal command - you have to specify
the command processor, cmd.exe in Windows 2000 or XP, e.g.:
retval = shell("cmd.exe /k PATH ;")

But anything you do to PATH or other environment variables at a command
prompt only applies to that instance of the command processor and
doesn't affect the registry settings.

As well as editing the registry directly, you can manage environment
settings and much else with the WMI (Windows Management Instrumentation)
library. Google for
wmi "environment variables"
for examples.
 
I do have a syntax question, though. I'm trying to read, then modify the key
you provided in an earlier post
(HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session
Manager\Environment)

With your application, I defined the following as:

Root=HKEY_LOCAL_MACHINE (Toggle selection)
Subkey=SYSTEM\CurrentControlSet\Control\Session Manager\Environment
ValueName=Path

Is this correct? When I use your MDB and enter in the values as listed
above and clidk the "Query Value Key" button, I receive a message box "Could
not open key".

Thanx for your assistance!
 
Hi John,

Thanx for your tip. I tried running the shell with the syntax you provided.
It opened a DOS window but didn't run the Path statement.

?????
 
Thanx for your tip. I tried running the shell with the syntax you provided.
It opened a DOS window but didn't run the Path statement.

My example was
retval = shell("cmd.exe /k PATH ;")

On my system this works as expected: it executes the Windows command
PATH ;
which clears the PATH environment variable - although it does it before
you can see the window. Execute
PATH
yourself at the command prompt and it should respond
PATH=(NULL)

Something like this
retval = shell("cmd.exe /k PATH C:\FOO;%PATH%")
will add a folder to the start of the path.

But using the PATH command only affects the current instance of the
command interpreter. Other command prompts (DOS boxes) you open
subsequently will still use the default path stored in the registry.
 
Hi, Bob.
With your application,

It's not my application. The credit goes to Danny Lesandrini of DataFast
Consulting.
When I use <Danny's> MDB and enter in the values as listed
above and clidk the "Query Value Key" button, I receive a message box
"Could
not open key".

When I tested this application, it worked fine. That was years ago and
probably on a Windows ME computer. After testing this afternoon, I can see
that his code will not work on Windows XP (and likely not Windows 2K,
either). Fortunately, I see what the problem is.

Danny's code in the CommandFunctions( ) subroutine of the form is
concatening "SOFTWARE\" to the subkey string before it is passed to the
Windows API function. This altered subkey's name doesn't exist, so the
Windows API can't find it and open it for you. You need to change all
occurrences in his code to remove this concatenated string. For example,
change:

txtValue = ReadRegValue(HKEY_LOCAL_MACHINE, _
"SOFTWARE\" & txtSubKey, txtValueName)

to:

txtValue = ReadRegValue(HKEY_LOCAL_MACHINE, _
txtSubKey, txtValueName)

But that's not the only problem. Danny's code is based upon the following
Microsoft KB article:

http://support.microsoft.com/default.aspx?id=145679

If you read the information in this article, you'll notice that it only
handles REG_SZ and REG_DWORD key sizes (if you didn't already catch this
limitation by reading Danny's code). These functions don't handle the
Windows Registry key for the Environment Path key size, which is
REG_EXPAND_SZ, a Unicode NULL-terminated string. I searched through the
Microsoft KB on how to read a REG_EXPAND_SZ subkey and only found this
Microsoft KB article:

http://support.microsoft.com/default.aspx?id=265331

Unfortunately, the example code is written for Visual Fox Pro, so it won't
work in VBA. But the example code shows that the string passed to the
Windows API function needs to be sized to the length of the key's value and
filled with spaces, so you'll need to add the following code to the
bas_E-Zone_Reg module:

In the module's Declarations section, add:

Public Const REG_EXPAND_SZ = 2

In the ReadRegValue( ) function's "Select Case lType" block, add the
following Case statement:

Case REG_EXPAND_SZ
sValue = Space(lcch)
lrc = RegQueryValueExSTRING(hKeyHandle, _
sValueName, 0&, lType, sValue, lcch)
ReadRegValue = Left(sValue, lcch - 1)

Save and compile the code and run the application to query this subkey's
value again. It should work now.

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
Beware to those who use munged addresses: known newsgroup E-mail harvesters
for spammers are (e-mail address removed) and (e-mail address removed)
 
Back
Top