views:

1374

answers:

4

Say you have an app, that you want to provide users ability to browse the system32 directory and execute programs in (like telnet).

What is the best method for supporting this when you need to support XP onwards as a client and 2k onwards for server?

Having written all this up I wonder if it's just too much time/effort in providing a browse to do this, where they could just copy it from explorer. Still requires ability to launch.

I have found some discussion on Nynaeve.

So far it seems there are the following options

  1. Create a sysnative folder in windows which will allow you to browse/execute 64 bit. Issues are:
    • only available in Vista/Longhorn, so no support for XP 64
    • leads to different path naming, can't use same path on multiple versions.
    • will be active for whole of windows, not just our app
    • may not (probably is not) appropriate to do when installing the app
    • allows to specify explicitly through path only which version of the app to launch if there is a 32 bit and 64 bit version
  2. Use the windows API to temporarily disable the redirection when showing file lists or executing users run commands. Issues are:
    • Only available on 64 bit - have to mess with GetProcAddress
    • available only under certain service packs
    • must individually identify all locations that this should be implemented
    • user will need to provide seperate information about whether this is a 64 bit app or 32 bit.

If anybody had some example code which displayed a Windows OpenFile dialog (say using MFC CFileDialog) showing nativly for XP/Vista and allowing the viewing of 64 bit system32 directory, that would be awesome.

If anybody had an example of launching the named app, that would also be great!

Edit:
Currently we use CreateProcess for launching the app (which is failing).

err = CreateProcess((wchar_t*)exeName.c_str(), (wchar_t*)cmdLine.c_str(), NULL, NULL, FALSE, CREATE_SEPARATE_WOW_VDM, NULL, workingDir.c_str(), &startupInfo, &processInfo);
A: 

This link help you about running 64 bit app:
http://stackoverflow.com/questions/8896/memcached-on-windows-x64/499610#499610

Good lock.

lsalamon
A: 

Are you getting redirected to Windows/SysWoW64? I can launch 64-bit apps from Windows/System32 from an OpenFile in a 32-bit managed executable.

Cat
Native C++, not sure if that has any major difference to Managed. I'm not sure if OpenFile is a good example, I don't just want to read the contents of telnet.exe. as in The OpenFile function creates, opens, reopens, or deletes a file. Is this your meaning?
Greg Domjan
As trivial test I right-clicked and ran a 64-bit exe in System32 from the OpenFile dialog. I just wanted to see if it were possible through the simplest means.
Cat
Ah I get your point now, however we cannot even see the 64 bit version of the System32 folder to do such.
Greg Domjan
+1  A: 

I've gone with option 2, For those who might be interested; here is my quick hack at a scoped version of managing the disabling of Wow64 redirection based on notes from MS. Will redirect if the API is available, expects that kernel32.dll is already available.

class Wow64RedirectOff {
    typedef BOOL (WINAPI *FN_Wow64DisableWow64FsRedirection) ( __out PVOID *OldValue );
    typedef BOOL (WINAPI *FN_Wow64RevertWow64FsRedirection) ( __in  PVOID OldValue );

public:
    Wow64RedirectOff() {
     LPFN_Disable = (FN_Wow64DisableWow64FsRedirection)GetProcAddress(
      GetModuleHandle(TEXT("kernel32")),"Wow64DisableWow64FsRedirection");
     if( LPFN_Disable ) {
      LPFN_Disable(&OldValue);
     }
    }

    ~Wow64RedirectOff() {
     if( LPFN_Disable ) {
      FN_Wow64RevertWow64FsRedirection LPFN_Revert = (FN_Wow64RevertWow64FsRedirection)GetProcAddress(
       GetModuleHandle(TEXT("kernel32")),"Wow64RevertWow64FsRedirection");
      if( LPFN_Revert ) {
       LPFN_Revert(OldValue);
      }
     }
    }

private:
    FN_Wow64DisableWow64FsRedirection LPFN_Disable;
    PVOID OldValue; 
};

And thus usage would be

Wow64RedirectOff scopedRedirect;
//CFileOpen
//CreateProcess
Greg Domjan
A: 

I had faced this similar problem and came up with this solution http://www.codeproject.com/tips/55290/Disabling-Windows-file-system-redirection-on-a-CFi.aspx

Any suggestions/ imporvements are highly encouraged :)

Kartik Sura