?
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
Medium Priority
?
790 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 82

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 82

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
What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 1500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
A quick guide on how to use Group Policy to create a custom power plan and set it active on Windows 7.
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
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…
Suggested Courses

801 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