473,386 Members | 1,738 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,386 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 6638
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.