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
769 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 79

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 79

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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Regular expression help 2 22
SQL Help 27 40
see android hidden files 10 24
New User Account Creation Issue 4 19
Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
While working, an annoying popup showing below will come and we cannot cancel or close it form the screen. The error message will come again and again.
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…
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.

786 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