Æ
æ— å¤´è€å°¸
I have written a program A with C#. In Main function, I will run a new
executable program B with Process.Start. The code like this
Process myProcess = new Process();
myProcess.StartInfo = ......
.......
Process.Start();
In particular case, Process.Start throw a Win32Exception with access denied.
There's a dialog showed by OS. The stack is
System.ComonentModel.Win32Exception: Access denied
System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo
startInfo)
System.Diagnostics.Process.Start()
Why this exception occured? The user has the principle to access destination
executable program. I'm puzzled. Thanks everyone who can give me clew.
Here is code in Program C with C++
TCHAR szExeFullPath[MAX_PATH] = {0};
DWORD dwExeNameLen = MAX_PATH * sizeof(TCHAR);
HKEY hKey = NULL;
LONG lRet = -1;
// open Regedit key
lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
_T("SOFTWARE\\ProgramC"),
0,
KEY_QUERY_VALUE,
&hKey
);
if ( ERROR_SUCCESS == lRet )
{
// Retrieves the type and data for the specified value name
// associated with an open registry key
lRet = RegQueryValueEx(hKey, _T("AppName"), 0, NULL, (LPBYTE)szExeFullPath,
&dwExeNameLen);
if ( ERROR_SUCCESS != lRet )
{
hr = E_FAIL;
}
// return true when the executable file path is exist
// close registry key
RegCloseKey(hKey);
}
else
{
hr = E_FAIL;
}
_tcscat_s(szExeFullPath, MAX_PATH, _T(" /h"));
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
if ( CreateProcess(NULL, // No module name (use command line).
szExeFullPath, // 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.
)
{
//delete this;
CloseHandle(pi.hProcess);
}
else
{
hr = E_FAIL;
}
The C++ code has any problem? I don't know. Maybe there are, who can tell me?
Thank's again!
executable program B with Process.Start. The code like this
Process myProcess = new Process();
myProcess.StartInfo = ......
.......
Process.Start();
In particular case, Process.Start throw a Win32Exception with access denied.
There's a dialog showed by OS. The stack is
System.ComonentModel.Win32Exception: Access denied
System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo
startInfo)
System.Diagnostics.Process.Start()
Why this exception occured? The user has the principle to access destination
executable program. I'm puzzled. Thanks everyone who can give me clew.
Here is code in Program C with C++
TCHAR szExeFullPath[MAX_PATH] = {0};
DWORD dwExeNameLen = MAX_PATH * sizeof(TCHAR);
HKEY hKey = NULL;
LONG lRet = -1;
// open Regedit key
lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
_T("SOFTWARE\\ProgramC"),
0,
KEY_QUERY_VALUE,
&hKey
);
if ( ERROR_SUCCESS == lRet )
{
// Retrieves the type and data for the specified value name
// associated with an open registry key
lRet = RegQueryValueEx(hKey, _T("AppName"), 0, NULL, (LPBYTE)szExeFullPath,
&dwExeNameLen);
if ( ERROR_SUCCESS != lRet )
{
hr = E_FAIL;
}
// return true when the executable file path is exist
// close registry key
RegCloseKey(hKey);
}
else
{
hr = E_FAIL;
}
_tcscat_s(szExeFullPath, MAX_PATH, _T(" /h"));
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
if ( CreateProcess(NULL, // No module name (use command line).
szExeFullPath, // 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.
)
{
//delete this;
CloseHandle(pi.hProcess);
}
else
{
hr = E_FAIL;
}
The C++ code has any problem? I don't know. Maybe there are, who can tell me?
Thank's again!