views:

186

answers:

1

After calling RegConnectRegistry(...) to open the registry on a remote machine, is it not possible to expand environment variables? I have looked at ExpandEnvironmentStrings and ExpandEnvironmentStringsForUser, but that only appears to be useful on the local machine. I think it must be possible considering that RegistryKey.GetValue() in .Net does expand the variables after calling RegistryKey.OpenRemoteBaseKey(), but I need to do this outside of .Net.

Any ideas?

+2  A: 

Given that the environment variables running in a given process is based on the currently logged on user, how would you determine the set of environment variables that would be active on the remote machine?

Even if you could read that information (it's in the registry after all), what would you do about processes that change their environment?

Larry Osterman
I need to expand registry key values under local machine under EventLog to get message resource dll path(s).
Mitch
Given that the .Net function that does what you want expands environment strings using the current environment variables, couldn't you just call ExpandEnvironmentStrings on the string?
Larry Osterman
Yeah, you're right. Seeing now that the .Net function only expands based on the current environment that would be the way to go.
Mitch
Apparently you can use WMI to find this information for the remote machine...
Larry Osterman
Yeah, I ended up using this query: select windowsdirectory from Win32_OperatingSystem. I only needed to expand %SystemRoot%.
Mitch