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
765 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
  • 3
  • 2
6 Comments
 
LVL 78

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 78

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
First some basics on Windows 7 Backup.  It has 2 components one is a file based backup which is stored in .zip files each zip is split at around 200 Megabytes and there is the Image Backup which is as the name implies a total image of the partition …
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
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…

759 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now