WinCE下读写注册表的又一种方法
2011-12-01 22:01
316 查看
闲话少说,直接附上代码,供参考。
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--> 1 // Preloader.cpp : 定义控制台应用程序的入口点。
2 //
3
4 #include "stdafx.h"
5 #include <windows.h>
6 #include "creg.hxx"
7
8 #define GET_PATH_FROM_REG
9
10 #define REG_ROOT HKEY_CURRENT_USER
11 #define REG_PATH _T("Software")
12 #define REG_NAME _T("AutoRunApp")
13 #define INI_PATH _T("\\Config.ini")
14 #define WINCE_STANDARD_SHELL _T("\\windows\\explorer.exe")
15
16 static TCHAR g_szFilePath[MAX_PATH];
17
18 #ifdef GET_PATH_FROM_REG // 从注册表中读取需开机时自启动程序的完整路径
19 static BOOL GetFilePath(TCHAR *pFileName)
20 {
21 if (pFileName)
22 {
23 CReg Reg;
24 DWORD dwLen = MAX_PATH;
25 Reg.Create(REG_ROOT,REG_PATH);
26 if (Reg.ValueSZ(REG_NAME,pFileName,dwLen))
27 {
28 return TRUE;
29 }
30 }
31
32 return FALSE;
33 }
34 #else // 从文件中读取需开机时自启动程序的完整路径
35 static BOOL GetFilePath(TCHAR *pFileName)
36 {
37 int nIndex;
38
39 if(pFileName)
40 {
41 HANDLE hFile = INVALID_HANDLE_VALUE;
42 char szPath[MAX_PATH];
43 DWORD dwRead;
44 hFile = CreateFile(INI_PATH,GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL);
45 if(hFile != INVALID_HANDLE_VALUE)
46 {
47 ReadFile(hFile,szPath,MAX_PATH,&dwRead,NULL);
48 for(nIndex = 0; nIndex < dwRead; nIndex++)
49 {
50 if(szPath[nIndex] == '\r' || szPath[nIndex] == '\n')
51 {
52 break;
53 }
54 *pFileName++ = szPath[nIndex];
55 }
56
57 *pFileName = _T('\0');
58
59 CloseHandle(hFile);
60 return TRUE;
61 }
62 }
63
64 return FALSE;
65 }
66 #endif
67
68 static BOOL IsFileExist(TCHAR *pFileName)
69 {
70 if (pFileName)
71 {
72 HANDLE hFind = INVALID_HANDLE_VALUE;
73 WIN32_FIND_DATA fd;
74
75 RETAILMSG(1,(TEXT("\r\nIsFileExist(%s)"),pFileName));
76
77 hFind = FindFirstFile(pFileName,&fd);
78
79 if (INVALID_HANDLE_VALUE != hFind)
80 {
81 FindClose(hFind);
82 return TRUE;
83 }
84 }
85
86 return FALSE;
87 }
88
89 static BOOL RunAppFile(TCHAR *pFilePath)
90 {
91 if (pFilePath)
92 {
93 PROCESS_INFORMATION pi;
94 BOOL bRet = FALSE;
95 bRet = CreateProcess(pFilePath,NULL,NULL,NULL,FALSE,0,NULL,
96 NULL,NULL,&pi);
97 if (bRet)
98 {
99 CloseHandle(pi.hThread);
100 CloseHandle(pi.hProcess);
101 return TRUE;
102 }
103 }
104
105 return FALSE;
106 }
107
108 int _tmain(int argc, _TCHAR* argv[])
109 {
110 // 获取开机时需自启动程序的完整路径
111 // 判断该程序否存在
112 // 如果程序存在,则启动该程序,如果不存在,则启动WinCE默认的Shell
113 if (GetFilePath(g_szFilePath))
114 {
115 if (IsFileExist(g_szFilePath))
116 {
117 if(RunAppFile(g_szFilePath))
118 {
119 return 0;
120 }
121 }
122 }
123
124 RunAppFile(WINCE_STANDARD_SHELL);
125
126 return 0;
127 }
相关文章推荐
- WinCE下读写注册表的又一种方法
- WinCE 应用程序开机自动运行的又一种方法
- 一种通过注册表获取USB虚拟串口端口号的方法
- Linux基础学习之测硬盘读写速度、内存读写速度的一种方法
- 一种通过注册表简便修改IE代理服务器的方法
- 一种读写可并发进行的队列的实现方法
- 【WinCE】WinCE程序开发中出现“无法找到PInvoke DLL"Kernel32.dll"”问题的一种解决方法
- WINCE恢复默认HIVE注册表的方法
- 介绍一种很棒的wince 如何替换系统声音的方法
- wince中将自己的应用程序编译到内核并开机启动的一种方法
- winCE注册表读写
- WINCE恢复默认HIVE注册表的方法
- Wince 中实现注册表恢复原厂设置的方法
- WinCE 应用程序开机自动运行的又一种方法
- WinCE恢复默认HIVE注册表的方法
- 介绍一种很棒的wince 如何替换系统声音的方法
- wince中将自己的应用程序编译到内核并开机启动的一种方法
- WinCE 应用程序开机自动运行的又一种方法
- WinCE中显示32位色BMP文件的一种方法
- 一种简便实效的配置文件读写方法