[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
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
?
800 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 84

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 84

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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

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…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
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…
Suggested Courses

868 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