Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. ShellExecute or WinExec!!

ShellExecute or WinExec!!

Scheduled Pinned Locked Moved C / C++ / MFC
questioncom
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    abc876
    wrote on last edited by
    #1

    I am trying to call ShellExecute or WinExec in my Win NT service application. When i am running it as simple win32 application, both of the functions executes well but when it is run as service under LocalSystem account, both of them dont work. what to do??? How can i execute another .exe file from current program???? Muhammad Shoaib Khan http://geocities.com/lansolution

    R 1 Reply Last reply
    0
    • A abc876

      I am trying to call ShellExecute or WinExec in my Win NT service application. When i am running it as simple win32 application, both of the functions executes well but when it is run as service under LocalSystem account, both of them dont work. what to do??? How can i execute another .exe file from current program???? Muhammad Shoaib Khan http://geocities.com/lansolution

      R Offline
      R Offline
      Robert Kuster
      wrote on last edited by
      #2

      > I am trying to call ShellExecute or WinExec > in my Win NT service application. > ... both of them dont work. ShellExecute and WinExec both work fine and your process gets created. You just don't see the window of your application because it's on a wrong desktop. To modify this tell your service to be interactive:     Administrative Tools > Component Services > Services (local) >     > double click your service > Tab: "Log On" > Check: "Allow service to interact with desktop" Although you will see the application now, it will still run under the local System account (often unwanted). To modify this behaviour use CreateProcessAsUser rather than ShellExecute or WinExec:

      STARTUPINFO si;
      PROCESS_INFORMATION pi;

      si.cb = sizeof(STARTUPINFO);
      si.lpReserved = NULL;
      si.lpTitle = NULL;
      si.lpDesktop = "WinSta0\\Default";
      si.dwX = si.dwY = si.dwXSize = si.dwYSize = 0L;
      si.dwFlags = 0;
      si.wShowWindow = SW_SHOW;
      si.lpReserved2 = NULL;
      si.cbReserved2 = 0;

      CreateProcessAsUser(hToken,NULL, szMyApp, NULL, NULL, FALSE,
      0, NULL, NULL, &si, &pi);
      CloseHandle(pi.hThread);
      CloseHandle(pi.hProcess);

      How to get the security token of a logged-on user? There are several ways, but I usually simply *steal* it from explorer.exe (via OpenProcessToken). As an example check the nRunAsLoggedOnUser function here[^] (=some handy service helper routines from CISCO). RK :)

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups