1

I have a dotnet winform application compressed and protected by RPX Packer with a password. The application can be opened from the windows command prompt supplying the password as the command line argument(e.g. MyApp.exe ). Instead of the command prompt I want to start the dotnet app from a native C++ application. I tried the following code which works without a password, but with a password some cryptographic error comes.

#include "stdafx.h"
#include "windows.h"
#include "shellapi.h"

int _tmain(int argc, _TCHAR* argv[])
{
  SHELLEXECUTEINFO shExecInfo;

  shExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);

  shExecInfo.fMask = NULL;
  shExecInfo.hwnd = NULL;
  shExecInfo.lpVerb = L"runas";
  shExecInfo.lpFile = L"MyApp.exe";
  shExecInfo.lpParameters = L"password";
  shExecInfo.lpDirectory = NULL;
  shExecInfo.nShow = SW_NORMAL;
  shExecInfo.hInstApp = NULL;

  ShellExecuteEx(&shExecInfo);

  return 0;
  }

How do I achieve this?

jeff
  • 684
  • 1
  • 11
  • 30
  • 2
    "some cryptographic error comes" I guess we'll all take turns and guess what the error is. It might take some time :) – user1233963 Oct 29 '13 at 09:01
  • sure. If I run from command prompt(e.g. MyApp.exe ) then the application runs without any problem. – jeff Oct 29 '13 at 09:03
  • I always initialize these structures to zero first eg ZeroMemory(&shExecInfo,sizeof(shExecInfo)); before I set the size. Also I use _T("runas") or use SHELLEXECUTEINFOW and not mix Ls with Ts – Angus Connell Oct 29 '13 at 09:06
  • @AngusConnell what is the difference between Ls and Ts? – jeff Oct 29 '13 at 10:26
  • Ts as TCHARs, Ls as in wide chars strings, if you look into SHELLEXECUTEINFO you'll find that there is a #define that points to the char * version or the wide char * version. So _T("xx") will be wide char * or char * depending on how you have set up project, it wont change anything, but it means if you change your project setting it will still compile – Angus Connell Oct 29 '13 at 11:04
  • Ok, but I am quite perplexed why the app is giving error message. because I can run the dotnet app(MyApp.exe) from the command prompt(e.g. MyApp.exe ) by supplying the password as the argument. Bu when the password is given as a parameter from the C++ application the error message is thrown. Why ? – jeff Oct 29 '13 at 12:07
  • Yes, it's not the reason why, it was just a stylistic point. Have you tried writing a .NET app that can call "MyApp.exe"? There are other ways to spawn processes in C. But to be honest your way looks fine to me. Sorry not too much help – Angus Connell Nov 08 '13 at 17:32

0 Answers0