473,320 Members | 1,926 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

windir on a remote machine

Hello, folks.
I have a need to get the value of %windir% on a remote machine. Is it
possible to get this value using C#?

Aug 22 '07 #1
8 6626
Hayato Iriumi wrote:
Hello, folks.
I have a need to get the value of %windir% on a remote machine. Is it
possible to get this value using C#?
I'm not aware of any API that provides that directly, even outside of
..NET. However, I would think that any sort of remoting API that allows
you to execute code on a remote machine (however you choose to implement
it) would allow you to use the Environment.GetEnvironmentVariable()
method to get the information you want.

Pete
Aug 22 '07 #2
Hello, folks.
I have a need to get the value of %windir% on a remote machine. Is it
possible to get this value using C#?
Don't know if there's a higher level function that will do this but the
solution seems to be "RegistryKey.OpenRemoteBaseKey ()". Just read the value
from "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Contr ol\Session
Manager\Environment". At least that seems to be the analogue for how you
would do it using the native WinAPI (which I have done in C++ using
"RegConnectRegistry()"). Note that you have authorization issues to deal
with of course but this will likely be a non-issue if the security context
of the calling thread has access to the other machine (if not you can
authenticate in code but that's another story).
Aug 22 '07 #3
Hi, Larry. Thanks for your reply. I really appreciate your help!

On Aug 22, 12:33 pm, "Larry Smith" <no_spam@_nospam.comwrote:
Hello, folks.
I have a need to get the value of %windir% on a remote machine. Is it
possible to get this value using C#?

Don't know if there's a higher level function that will do this but the
solution seems to be "RegistryKey.OpenRemoteBaseKey ()". Just read the value
from "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Contr ol\Session
Manager\Environment". At least that seems to be the analogue for how you
would do it using the native WinAPI (which I have done in C++ using
"RegConnectRegistry()"). Note that you have authorization issues to deal
with of course but this will likely be a non-issue if the security context
of the calling thread has access to the other machine (if not you can
authenticate in code but that's another story).

Aug 22 '07 #4
Larry Smith wrote:
>Hello, folks.
I have a need to get the value of %windir% on a remote machine. Is it
possible to get this value using C#?

Don't know if there's a higher level function that will do this but the
solution seems to be "RegistryKey.OpenRemoteBaseKey ()". Just read the value
from "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Contr ol\Session
Manager\Environment". At least that seems to be the analogue for how you
would do it using the native WinAPI (which I have done in C++ using
"RegConnectRegistry()"). Note that you have authorization issues to deal
with of course but this will likely be a non-issue if the security context
of the calling thread has access to the other machine (if not you can
authenticate in code but that's another story).
As long as the remote machine is a newer version of Windows this should
work. Non NT based Windows (Windows 95, Windows 98) do not store
environment variables in the registry.
--
Tom Porterfield
Aug 22 '07 #5
As long as the remote machine is a newer version of Windows this should
work. Non NT based Windows (Windows 95, Windows 98) do not store
environment variables in the registry.
Yes, there are some caveats (the "Remote Registry" service must be running
on both machines for instance) but the above issue is probably the least of
his worries. I don't recall if "windir" is even defined on those (almost
antiquated) OSs. In any event, reading values like this from the registry is
rather ugly IMO (though probably stable in this particular case). Moreover,
since "windir" is the equivalent of CSIDL_WINDOWS using the WinAPI shell
functions such as "SHGetFolderPath()", he might want to investigate if a
dedicated function exists for finding special folders on a remote machine
(assuming this is his real objective)
Aug 22 '07 #6
"Larry Smith" <no_spam@_nospam.comwrote in message
news:eY**************@TK2MSFTNGP05.phx.gbl...
>Hello, folks.
I have a need to get the value of %windir% on a remote machine. Is it
possible to get this value using C#?

Don't know if there's a higher level function that will do this but the
solution seems to be "RegistryKey.OpenRemoteBaseKey ()". Just read the
value from "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Contr ol\Session
Manager\Environment". At least that seems to be the analogue for how you
would do it using the native WinAPI (which I have done in C++ using
"RegConnectRegistry()"). Note that you have authorization issues to deal
with of course but this will likely be a non-issue if the security context
of the calling thread has access to the other machine (if not you can
authenticate in code but that's another story).

This isn't of great help has the value stored is a placeholder
(%SystemRoot%) which gets expanded by the OS before it's returned in the
environment block of the logon user, you will have to expand this on the
remote system to get it's real value. Much easier is to use
System.Management to get at this kind of info.
Willy.

Aug 22 '07 #7
"Hayato Iriumi" <hi*****@gmail.comwrote in message
news:11**********************@m37g2000prh.googlegr oups.com...
Hello, folks.
I have a need to get the value of %windir% on a remote machine. Is it
possible to get this value using C#?


Use System.Management and read the "WindowsDirectory" property of WMI's
class Win32_OperatingSystem.
Next sample reads the "windowsdirectory" from a remote server (BOBSMachine)
....
ConnectionOptions co = new ConnectionOptions();;
co.Username = "administrator"; // user with sufficient privileges to
connect to the cimv2 namespace
co.Password = "adminPwd"; // his password
ManagementScope scope = new
ManagementScope(@"\\BOBSMachine\root\cimv2", co);
SelectQuery query =
new SelectQuery("Select windowsdirectory from
Win32_OperatingSystem");
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(scope, query);
foreach (ManagementObject windir in searcher.Get())
Console.WriteLine("Value = {0}", windir["windowsdirectory"]);
....

Willy.

Aug 22 '07 #8
This isn't of great help has the value stored is a placeholder
(%SystemRoot%) which gets expanded by the OS before it's returned in the
environment block of the logon user, you will have to expand this on the
remote system to get it's real value. Much easier is to use
System.Management to get at this kind of info.
Willy.
Alas you're correct but I didn't know what native .NET methods were
available to retrieve this info (which he should normally depend on of
course). However, it was really a direct answer to his question though I'm
still not 100% certain of his intentions (though I should have clarified
it). He may literally require the value of this environment variable in its
raw or expanded state. This could even differ from %SYSTEMROOT% in theory
(and the value returned by your own example) so he needs to confirm what
he's really looking for, the value of "windir" (expanded or otherwise), or
the path of the windows folder regardless of "windir". In any case, I didn't
take the time to look at what the default value for "windir" was (in terms
of other environment variables) since he could normally plug in any other
environment variables in as required. This would involve some extra work to
parse "windir" and expand any other embedded variables but it's a fairly
trivial exercise. "%SystemRoot% however presents an impediment since it's
one of several predefined environment variables that isn't stored as a
regular environment variable. Its actual value would therefore need to be
(remotely) tracked down but it's potentially doable (I'd have to look). The
logged on user on the remote machine is another matter however. He shouldn't
depend on any expansion associated with that user via the remote equivalent
of "ExpandEnvironmentStrings()" and cousin(s). "windir" is a system
environment variable so it shouldn't be defined in terms of user environment
variables. There may not even be any interactive user at the time or call or
it's even possible there could be more than one interactive logon session
(even without any human actually being logged on in theory).
Aug 23 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: sandiyan | last post by:
Hi, I am trying to use java to do the following: Remote machine(Windows): Has a drive mapped(m:\) to a network share. Invoking a BAT file(test.BAT) from this drive will install an application...
9
by: Marina Anufreichik | last post by:
Hi, After deploymnet web application on web server I can access page on local machine and login fine but when I'm trying to access web site from remote machine I can see login page, but when I'm...
5
by: McGeeky | last post by:
Is it possible to install an assembly on a remote machine's GAC? I don't see an option for it using gacutil.exe -- McGeeky http://mcgeeky.blogspot.com
4
by: Rohith | last post by:
I need to import dlls that are present in the remote machine. Its a dll written in C that exposes methods. I want to import that dll in my C# application. But that dll is not present in the local...
0
by: GrantMagic | last post by:
Hi I am currently trying to use a test machine to access web site files on a remote machine. Once set up IIS with the files pointing to a share on the remote machine, i try view the default...
4
by: reichek | last post by:
I have a 4 machine peer network I would like to be able to invoke an executable ( .exe file) on a remote machine and have it run on that remote machine - I do not want it to run on my machine. ...
1
by: Jason | last post by:
I've a c# app that I execute on a remote machine, which works as I expect it to, but when I encounter an error on the remote machine how do I know what's going on, since it's a remote app? For...
3
by: =?Utf-8?B?RGFydGhTaWRpb3Vz?= | last post by:
hello, i need to run an application from a remote machine in the same intranet. But everytime i do something like "\\server\app\aplication.exe" i get a clr error. How can i do this? i can't...
0
by: DR | last post by:
How to debug sql 2005 on remote machine. I am administrator on both my dev machine and remote sql server machine. I get this error when i try to connect to remote machien with visual studio: ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.