473,587 Members | 2,487 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6660
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.Get EnvironmentVari able()
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.Op enRemoteBaseKey ()". Just read the value
from "HKEY_LOCAL_MAC HINE\SYSTEM\Cur rentControlSet\ Control\Session
Manager\Environ ment". 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
"RegConnectRegi stry()"). 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@_nospa m.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.Op enRemoteBaseKey ()". Just read the value
from "HKEY_LOCAL_MAC HINE\SYSTEM\Cur rentControlSet\ Control\Session
Manager\Environ ment". 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
"RegConnectRegi stry()"). 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.Op enRemoteBaseKey ()". Just read the value
from "HKEY_LOCAL_MAC HINE\SYSTEM\Cur rentControlSet\ Control\Session
Manager\Environ ment". 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
"RegConnectRegi stry()"). 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 "SHGetFolderPat h()", 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@_nospa m.comwrote in message
news:eY******** ******@TK2MSFTN GP05.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.Op enRemoteBaseKey ()". Just read the
value from "HKEY_LOCAL_MAC HINE\SYSTEM\Cur rentControlSet\ Control\Session
Manager\Environ ment". 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
"RegConnectRegi stry()"). 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.Manageme nt to get at this kind of info.
Willy.

Aug 22 '07 #7
"Hayato Iriumi" <hi*****@gmail. comwrote in message
news:11******** **************@ m37g2000prh.goo glegroups.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.Manageme nt and read the "WindowsDirecto ry" property of WMI's
class Win32_Operating System.
Next sample reads the "windowsdirecto ry" from a remote server (BOBSMachine)
....
ConnectionOptio ns co = new ConnectionOptio ns();;
co.Username = "administrator" ; // user with sufficient privileges to
connect to the cimv2 namespace
co.Password = "adminPwd"; // his password
ManagementScope scope = new
ManagementScope (@"\\BOBSMachin e\root\cimv2", co);
SelectQuery query =
new SelectQuery("Se lect windowsdirector y from
Win32_Operating System");
ManagementObjec tSearcher searcher =
new ManagementObjec tSearcher(scope , query);
foreach (ManagementObje ct windir in searcher.Get())
Console.WriteLi ne("Value = {0}", windir["windowsdirecto ry"]);
....

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.Manageme nt 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. "%SystemRoo t% 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 "ExpandEnvironm entStrings()" 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
1616
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 on the remote machine. From my local machine(currently on Unix), I want to Run a java GUI that will invoke test.BAT on the remote machine, which...
9
2992
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 trying to login with correct credentials it give me error: Server Error in '/PDVMgr' Application. ...
5
6337
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
4670
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 machine. Its not a webservice. I need something like remote method invocation(but dlls).
0
1349
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 page. I get an error message statting 'The base type 'NameSpace.Class.Default' does not exist in the source file 'Default.cs'.' where namespace and...
4
6681
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. How can this be done? Of course, if I simply make a .bat file on my machine which invokes the remote machines executible - it runs and displays on...
1
1333
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 instance on the remote app that I execute I check for the existence of a file, and if it's not there,I want to display a simple popup message telling...
3
2303
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 install the application on every machine... this was not a problem with vb6.
0
1291
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: unable to connect to microsoft vistual studio remote debugging monitor named msdb3. the microsfot visual studio remote debugging montor (msvsmon.exe)...
0
7920
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7849
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7973
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6626
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5718
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3844
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1189
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.