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. non-admin logins prevent program execution

non-admin logins prevent program execution

Scheduled Pinned Locked Moved C / C++ / MFC
databasewindows-adminsecurityhelpquestion
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.
  • E Offline
    E Offline
    elephantstar
    wrote on last edited by
    #1

    I am trying to launch a program executable(Program A) from another program's menu (Program B). I coded the program B such that it searches the registry for the installation path of program B's executable. This works fine under an administrator login but not for non-admins. I thought it was because I did not grant proper security access by adding KEY_READ to the following line of code: bRetVal = regKey.Open(HKEY_LOCAL_MACHINE ,(LPCTSTR)strTmp, KEY_READ); But when I do include KEY_READ, under an admin login, the above code fails. Why is that? For non-admins, it fails either way. The entire code is shown below. Thanks! CProgramB::Notify(DataNotificationType notifyType, VARIANT data) { STARTUPINFO stStartUpInfo; PROCESS_INFORMATION pProcessInfo; memset(&stStartUpInfo, 0, sizeof(STARTUPINFO)); stStartUpInfo.cb = sizeof(STARTUPINFO); stStartUpInfo.dwFlags = STARTF_USESHOWWINDOW; stStartUpInfo.wShowWindow = SW_SHOWDEFAULT; CRegKey regKey; BOOL bRetVal; CString strTmp = "Software\\ProgramA"; if (bRetVal==ERROR_SUCCESS) { CString key = "InstallDir"; char getValue[256] ; DWORD d = 255; bRetVal=regKey.QueryValue( getValue , (LPCTSTR)key , &d); if (bRetVal==ERROR_SUCCESS) { char comLine[300]; CString keyValue = (CString)getValue; strcpy(comLine, keyValue); strcat(comLine, "programA.exe"); CreateProcess(NULL, comLine, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &stStartUpInfo, &pProcessInfo); } else AfxMessageBox("Query Failed"); } else { AfxMessageBox( "Program Fail to open."); } regKey.Close(); return S_OK; }

    D 1 Reply Last reply
    0
    • E elephantstar

      I am trying to launch a program executable(Program A) from another program's menu (Program B). I coded the program B such that it searches the registry for the installation path of program B's executable. This works fine under an administrator login but not for non-admins. I thought it was because I did not grant proper security access by adding KEY_READ to the following line of code: bRetVal = regKey.Open(HKEY_LOCAL_MACHINE ,(LPCTSTR)strTmp, KEY_READ); But when I do include KEY_READ, under an admin login, the above code fails. Why is that? For non-admins, it fails either way. The entire code is shown below. Thanks! CProgramB::Notify(DataNotificationType notifyType, VARIANT data) { STARTUPINFO stStartUpInfo; PROCESS_INFORMATION pProcessInfo; memset(&stStartUpInfo, 0, sizeof(STARTUPINFO)); stStartUpInfo.cb = sizeof(STARTUPINFO); stStartUpInfo.dwFlags = STARTF_USESHOWWINDOW; stStartUpInfo.wShowWindow = SW_SHOWDEFAULT; CRegKey regKey; BOOL bRetVal; CString strTmp = "Software\\ProgramA"; if (bRetVal==ERROR_SUCCESS) { CString key = "InstallDir"; char getValue[256] ; DWORD d = 255; bRetVal=regKey.QueryValue( getValue , (LPCTSTR)key , &d); if (bRetVal==ERROR_SUCCESS) { char comLine[300]; CString keyValue = (CString)getValue; strcpy(comLine, keyValue); strcat(comLine, "programA.exe"); CreateProcess(NULL, comLine, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &stStartUpInfo, &pProcessInfo); } else AfxMessageBox("Query Failed"); } else { AfxMessageBox( "Program Fail to open."); } regKey.Close(); return S_OK; }

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      elephantstar wrote: bRetVal = regKey.Open(HKEY_LOCAL_MACHINE ,(LPCTSTR)strTmp, KEY_READ); Does this mean that the default security access of KEY_ALL_ACCESS works? elephantstar wrote: BOOL bRetVal; ... if (bRetVal==ERROR_SUCCESS) At this point, bRetVal has not been assigned a value. elephantstar wrote: bRetVal=regKey.QueryValue( getValue , (LPCTSTR)key , &d); You can't call QueryValue() without having first called Open(). elephantstar wrote: CString keyValue = (CString)getValue; Why the unnecessary cast? Use of the <pre> tag will make your code much easier to read.


      "One must learn from the bite of the fire to leave it alone." - Native American Proverb

      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