• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 82
  • Last Modified:

VFP 8 Calling Advapi32.dll RegConnectRegistry

I had this question after viewing Variable type declaration in VFP.

My goal to to query a value in a remote computer's registry from within my VFP 8 program.
The only API functions I could find was  OpenRemoteBaseKey (.NET Framework) and RegConnectRegistry  (Advapi32.dll)

The C++ construction:
LONG WINAPI RegConnectRegistry(
  _In_opt_ LPCTSTR lpMachineName,
  _In_     HKEY    hKey,
  _Out_    PHKEY   phkResult
);

lpMachineName is a string variable like "\\remotecomputer"
hKey can be one of these hex constants (the hex value is shown with a &H prefix):
    HKEY_LOCAL_MACHINE,  &H80000002
    HKEY_USERS , &H80000003
phkResult is described as: A pointer to a variable that receives a key handle identifying the predefined handle on the remote computer.

In VFP I tried this:
  DECLARE INTEGER RegConnectRegistry IN win32api ;
    STRING lpMachineName, ;
    INTEGER hKey, ;
    INTEGER phkResult

  ln_result=0
  ln_HKEY_USERS = 0x80000003
  ln_Ret = RegConnectRegistry("\\EPCWIN10", ln_HKEY_USERS, @ln_result)

ln_Ret returns 1780, according to Winerror.h that means: "A null reference pointer was passed to the stub"

The remote registry service is running on \\EPCWIN10
I'm thinking I can't simply convert hex to decimal.
What am I doing wrong? Is there some other way to programmatically read a value from a remote registry?
Thanks,
Jerry
0
jinfeld
Asked:
jinfeld
  • 5
  • 3
2 Solutions
 
pcelbaCommented:
You should test it on your local computer first - so pass the NULL value as computer name.

Also the declaration must declare the output parameter by reference:

  DECLARE INTEGER RegConnectRegistry IN win32api ;
    STRING lpMachineName, ;
    INTEGER hKey, ;
    INTEGER @phkResult

If the function succeeds on your local computer (under admin account) then you may start to play with remote calls.

Remember the user which executes the call must be admin on the remote computer.

IMO PowerShell is maybe better tool to query remote registry. More info: https://itfordummies.net/2016/09/06/read-remote-registry-powershell/
https://social.technet.microsoft.com/Forums/office/en-US/0835c303-2edd-4c06-bbc9-5c7952402d0c/powershell-to-get-the-registry-key-value-from-remote-server-with-txt-file?forum=winserverpowershell
https://4sysops.com/archives/retrieve-the-registry-keys-from-remote-computers-via-powershell/
0
 
jinfeldPresidentAuthor Commented:
Thanks,
I'll try it locally first. How do automate PowerShell inside my VFP program?
Jerry
0
 
pcelbaCommented:
PowerShell does not work in OLE Automation mode most probably - something like  CREATEOBJECT('PowerShell.Application')  does not work but you can execute PowerShell script via RUN command in FoxPro. If you need to transfer results to FoxPro then it should be possible via text file.

OTOH, do you need FoxPro for this purpose any more? PowerShell can do almost anything.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
jinfeldPresidentAuthor Commented:
I need to use the value of the remote registry key in my Foxpro program. If I can't get automation to work, I'll try to run a powershell script with output to a temp text file that I can then pull into my VFP program.
Thanks,
Jerry
0
 
pcelbaCommented:
Hi Jerry

does the remote registry reading by PowerShell work for you? If yes then please close the question. Don't hesitate to ask if you have additional questions.

Regards
Pavel
0
 
jinfeldPresidentAuthor Commented:
No because I need to make a change to the remote registry, not just read it.
But I'll try again and update this topic.
Thanks,
Jerry
0
 
pcelbaCommented:
A few links describing how to use PowerShell to read/edit remote registry were provided and they are working w/o problems if the user has sufficient access rights.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now