Solved

How to find Windows' System directories from 32 bit EXE running on both 32 and/or 64 bit OS

Posted on 2012-03-22
6
780 Views
Last Modified: 2012-06-27
I have a .NET 3.5 application written in C# which needs to copy files to *BOTH* the windows' system folders.   It has some 32 bit DLLs which need to go in the system32 folder and it has 64 bit DLLs which need to go in the 64 bit System folder.  

So, basically i need to figure out how to write these methods:

public string Get32BitWindowsSystemFolder()
{

}

public string Get64BitWindowsSystemFolder()
{

}
0
Comment
Question by:RXCTO
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 81

Expert Comment

by:David Johnson, CD, MVP
ID: 37755363
you will run into problems as you should be using the appdata folder or programdata folder as the windows directory is a protected area. There is only 1 system32 folder which contains both 32bit and 64 bit executables.
0
 

Author Comment

by:RXCTO
ID: 37755444
My program is following the instructions to install "Java Access Bridge" from Oracle.  The instructions say to copy some of the files to the System32 folder and others to the SysWOW64 folder.  What am i supposed to do?

see Table 2-2 in the instructions.

http://docs.oracle.com/javase/accessbridge/2.0.2/setup.htm
0
 
LVL 81

Expert Comment

by:David Johnson, CD, MVP
ID: 37755586
actually I had misspoken earlier:
system32 contains the 64 bit dll's
syswow64 contains the 32 bit dll's

The copying routine must run with elevated privileges (run as administrator) to access these protected areas
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 500 total points
ID: 37755621
You can retrieve the location of any system folder by calling GetFolderPath with one of the folders listed in the SpecialFolder enumeration:

System.Environment.GetFolderPath(Environment.SpecialFolder.SystemX86)
System.Environment.GetFolderPath(Environment.SpecialFolder.System)

In a 32-bits environment, both of these will return the same folder.
In a 64-bits environment, System gives the system folder for 64-bits and System86 for 32-bits.
0
 

Accepted Solution

by:
RXCTO earned 0 total points
ID: 37757197
The enumeration for SystemX86 is not available in .NET 3.5 but appears to be only in .NET 4.  

However, researching it I came across the solution for .NET 3.5.

        private static int CSIDL_SYSTEM = 0x0025;
        private static int CSIDL_SYSTEMX86 = 0x0029;

        [DllImport("shell32.dll")]
        public static extern bool SHGetSpecialFolderPath(IntPtr hwndOwner, [Out]StringBuilder lpszPath, int nFolder, bool fCreate);

       public static string GetWindowsSystemDirectory32()
       {
           StringBuilder sb = new StringBuilder(2048);
           SHGetSpecialFolderPath(IntPtr.Zero, sb, CSIDL_SYSTEM, false);
           return sb.ToString();

       }

       public static string GetWindowsSystemDirectory64()
       {
           StringBuilder sb = new StringBuilder(2048);
           SHGetSpecialFolderPath(IntPtr.Zero, sb, CSIDL_SYSTEMX86, false);
           return sb.ToString();

       }
0
 

Author Closing Comment

by:RXCTO
ID: 37775662
The other comment only works for .NET 4.  My question specified .NET 3.5.   My solution works for .NET 3.5
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
There are many software programs on offer that will claim to magically speed up your computer. The best advice I can give you is to avoid them like the plague, because they will often cause far more problems than they solve. Try some of these "do it…
This Micro Tutorial will teach you how to the overview of Microsoft Security Essentials. This is a free anti-virus software that guards your PC against viruses, spyware, worms, and other malicious software. This will be demonstrated using Windows…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question