Reputation:
I have a 32bit program which I am trying to run on a 64bit computer. I'm running the vssadmin command to get the restore point info and saving it to a text file. Now, it works fine on my 32bit computer and I was testing it on my friend's 64 bit computer and it doesn't work.
If I use system() from within a 32bit application running on a 64 bit system, will it use a 32bit command prompt? That's the only thing I can think that would stop it working as I have manually run the command from a command prompt and it works fine.
If this is the case? Is there anyway to force it to use the right command prompt?
Upvotes: 4
Views: 9930
Reputation: 1
You can use to disable the redirect to the wow64
https://learn.microsoft.com/en-us/windows/win32/api/wow64apiset/nf-wow64apiset-wow64disablewow64fsredirection and https://learn.microsoft.com/en-us/windows/win32/api/wow64apiset/nf-wow64apiset-wow64revertwow64fsredirection
// Disable Redirection to Wow64
PVOID OldValue = NULL;
Wow64Disable = Wow64DisableWow64FsRedirection(&OldValue);
//start Proceess and do stuff
//revert the redirection diable
Wow64RevertWow64FsRedirection(OldValue);
Upvotes: 0
Reputation: 1825
You should always avoid using system() because
you should use CreateProcess().
You can use Createprocess() to just start up an .exe and creating a new process for it. The application will run independent from the calling application.
here's an example i used in one of my projects:
VOID startup(LPCTSTR lpApplicationName)
{
// additional information
STARTUPINFO si;
PROCESS_INFORMATION pi;
// set the size of the structures
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
// start the program up
CreateProcess( lpApplicationName, // the path
argv[1], // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi ) // Pointer to PROCESS_INFORMATION structure
)
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
}
NOTE: as i said earlier, system() does not do the same on different machines, Mats Petersson explained why
Upvotes: 1
Reputation: 129314
In both Linux and Windows [and I beleive BSD/MacOS too], 32-bit applications can start a 64-bit process using the relevant "create a new process" system call [which system()
does some several layers down inside the shell that it starts].
The only restriction is that a 32-bit executable file can't use a 64-bit shared library (.so or .dll) or vice versa. But a new process starts by loading a new executable and at that point the process can be 32- or 64-bit based on the executable file itself.
Upvotes: 10