首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

关于Windows服务的怪事,解决思路

2012-02-21 
关于Windows服务的怪事,急!我写了个Windows服务,在服务中用CreateProcess创建另一个我写的程序aaa.exe(带

关于Windows服务的怪事,急!
我写了个Windows服务,在服务中用CreateProcess创建另一个我写的程序aaa.exe(带界面的),CreateProcess返回值非0,但aaa实际没起来(界面看不到,进程管理器里也没有),但用同样的方法打开NOTEPAD.exe却能成功,怎么回事啊!

创建进程的方法如下:
CreateProcess(NULL, "aaa.exe ",NULL,NULL,TRUE,NULL,NULL,NULL,&si,&pi)

[解决办法]
指定文件的绝对路径,因为notepad.exe是在windows目录中,而windows目录是系统环境目录
[解决办法]
CreateProcess在当第一个参数为NULL时会按照下面顺序查找程序:
1. The directory from which the application loaded.
2. The current directory for the parent process.
3. The 32-bit Windows system directory. Use the GetSystemDirectory function to get the path of this directory.
4. The 16-bit Windows system directory. There is no function that obtains the path of this directory, but it is searched. The name of this directory is System.
5. The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
6. The directories that are listed in the PATH environment variable. Note that this function does not search the per-application path specified by the App Paths registry key. To include this per-application path in the search sequence, use the ShellExecute function

Notepad符合第5条,而你自己写的EXE则很可能不在这些路径下。
[解决办法]
恩,给出具体的路径就好了
比如D:\program\
[解决办法]
但用同样的方法打开NOTEPAD.exe却能成功
========================================
Notepad.exe依赖于环境变量路径设置
[解决办法]
还要设置工作路径,很多程序在不设置工作路径的情况下都泡不起来。SetDictionary。

热点排行