non-admin logins prevent program execution
-
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; }
-
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; }
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 callQueryValue()
without having first calledOpen()
. 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