⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 csdn_文档中心_windows9x 的后台进程.htm

📁 csdn10年中间经典帖子
💻 HTM
📖 第 1 页 / 共 2 页
字号:
            "1"是Service进程,<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 
            "0"普通进程<BR>...<BR>+24h &nbsp;DWORD &nbsp; pPSP // DOS 
            PSP指针<BR>...<BR>============================================<BR>---- 
            3. 实 现 接 口 <BR><BR>---- (1) Windows95 中 提 供 的 简 单 的Service 接 口 是 一 
            个32 位 的API: RegisterServiceProcess, 由 于 在VC++ 的Online help 中 得 不 到 关 
            于 这 个API 的 确 切 解 释, 笔 者 不 得 不 针 对 此API 进 行 了 逆 向 分 析, 以 下 是 
            在Windows95 的Kernel32.dll 中 该API 的 伪 码. 我 们 可 以 清 楚 的 看 到Window95 内 部 
            到 底 是 怎 样 做 的, 其 实 处 理 的 非 常 简 单. <BR><BR>BOOL 
            RegisterServiceProcess<BR>( DWORD dwProcessID, DWORD dwType 
            )<BR>{<BR>HANDLE dwPID;<BR>if( dwProcessID == NULL )<BR>&nbsp; dwPID 
            = dwCurrentProcessID; <BR>&nbsp; // Get global kernel32 
            variable<BR>else<BR>&nbsp; // Call some kernel functions<BR>&nbsp; 
            if( ( dwPID = CheckPID( dwProcessID ) == NULL )<BR>&nbsp; &nbsp; 
            return FALSE;<BR>if( dwType == 1 )<BR>{<BR>&nbsp; *(BYTE *)( dwPID + 
            0x21 ) | = 0x01;<BR>&nbsp; return TRUE;<BR>}<BR>if( dwType == 0 
            )<BR>{<BR>&nbsp; *(BYTE *)( dwPID + 0x21 ) &amp; = 0xFE;<BR>&nbsp; 
            return TRUE;<BR>}<BR>return FALSE;<BR>}<BR>&nbsp;以下为函数原形:<BR>BOOL 
            &nbsp;RegisterServiceProcess( DWORD dwPID, DWORD dwType )<BR>参数: 
            &nbsp;dwPID:进程ID, NULL代表当前进程<BR>&nbsp; &nbsp;dwType: 
            RSP_SIMPLE_SERVICE为登记<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp;RSP_UNREGISTER_SERVICE为取消登记<BR>返回值: TRUE: 调用成功<BR>&nbsp; 
            &nbsp;FALSE: 调用失败<BR>---- (2) 另 外, 为 了 让Service 进 程 有 机 会 在BOOT 后 就 
            启 动,Windows95 的Registry 中 提 供 了 加 载 方 法: 在KEY " MyComputer 
            \HKEY_LOCAL_MACHINE\SOFTWARE \Microsoft\Windows \CurrentVersion 
            \RunServices " 加 入 自 己 的 应 用 程 序 命 令 行, 即 可 实 现 开 机 自 动 加 载. 当 然, 如 
            果 你 得 机 器 中 没 有 这 个Key, 自 己 建 一 个 也 是 可 以 的. <BR><BR>---- 4. 例 程 
            <BR><BR>---- 下 面 是 实 现 例 程, 所 有 代 码 经 过 了WINDOWS95. WINDOWS98 BETA3 
            的 测 试, 可 以 方 便 的 加 入 到 自 己 的 项 目 文 件 中. <BR><BR>---- 头 文 件: 
            <BR><BR>// File: &nbsp; &nbsp; &nbsp;service.h<BR>// The head file 
            of "service.cpp"<BR>// Note: 1. You must use C++ compiler<BR>// 
            &nbsp; 2. The platform is WIN32 (WINNT &amp; WIN95)<BR><BR>#ifndef 
            _SERVICE_H<BR>#define 
            _SERVICE_H<BR><BR>/////////////////////////////////////<BR>////////////// 
            USED FOR WIN95 SERVICE<BR>// Micros<BR>#define RSP_SIMPLE_SERVICE 
            &nbsp; &nbsp; &nbsp;1<BR>#define RSP_UNREGISTER_SERVICE &nbsp; 
            &nbsp;0<BR><BR>// Function types for GetProcAddress<BR>#define 
            RegisterServiceProcess_PROFILE <BR>(DWORD (__stdcall *) (DWORD, 
            DWORD))<BR><BR>// Service Fuctions in Win95<BR>BOOL 
            &nbsp;W95ServiceRegister(DWORD dwType);<BR>BOOL 
            &nbsp;W95StartService( DWORD dwType );<BR><BR>#endif<BR><BR>CPP 文 
            件:<BR>// File: &nbsp; &nbsp;service.cpp --- implement the 
            service<BR><BR>#include 
            "service.h"<BR>/////////////////////////////////////<BR>////////////// 
            USED FOR WIN95 SERVICE<BR>登 记 为Service 子 程 
            序:<BR>/////////////////////////////////////////<BR>////////////////////////////////////////<BR>// 
            Define: &nbsp; &nbsp; &nbsp; BOOL <BR>&nbsp; 
            &nbsp;W95ServiceRegister(DWORD dwType)<BR>// Parameters: dwType --- 
            Flag to <BR>register or unregister the service<BR>// &nbsp; &nbsp; 
            &nbsp;RSP_SIMPLE_SERVICE &nbsp; means register<BR>// &nbsp; &nbsp; 
            &nbsp;RSP_UNREGISTER_SERVICE means unregister<BR>// Return: TRUE --- 
            call success; <BR>&nbsp; &nbsp;FALSE --- call failer<BR><BR>BOOL 
            &nbsp;W95ServiceRegister( DWORD dwType )<BR>{<BR>&nbsp; &nbsp;// 
            Function address defination<BR>&nbsp; &nbsp;DWORD &nbsp;(__stdcall * 
            hookRegisterServiceProcess)<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;( 
            DWORD dwProcessId, DWORD dwType ); <BR><BR>&nbsp; &nbsp;// Get 
            address of function<BR>&nbsp; &nbsp;hookRegisterServiceProcess = 
            <BR>&nbsp; &nbsp;RegisterServiceProcess_PROFILE<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GetProcAddress<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;(GetModuleHandle("KERNEL32"),<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; TEXT("RegisterServiceProcess"));<BR><BR>&nbsp; 
            &nbsp;// Register the WIN95 service<BR>&nbsp; 
            &nbsp;if(hookRegisterServiceProcess(NULL,dwType)==0)<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp;return FALSE;<BR>&nbsp; &nbsp;return 
            TRUE;<BR>}<BR>---- 加 入 注 册 表 子 程 序: <BR><BR>#define SERVICE_NAME 
            &nbsp;TEXT("SERVICE")<BR>// Define: &nbsp; BOOL 
            &nbsp;W95StartService( DWORD dwType )<BR>// Parameters: dwType --- 
            Flag to<BR>register or unregister the service<BR>// &nbsp; &nbsp; 
            &nbsp;RSP_SIMPLE_SERVICE &nbsp; means register<BR>// &nbsp; &nbsp; 
            &nbsp;RSP_UNREGISTER_SERVICE means unregister<BR>// Return: TRUE --- 
            call success; FALSE --- call failer<BR><BR>BOOL W95StartService( 
            DWORD dwType )<BR>{<BR>&nbsp; &nbsp;// Local Variables<BR>&nbsp; 
            &nbsp;TCHAR &nbsp;lpszBuff[256];<BR>&nbsp; &nbsp;LPTSTR lpszStr = 
            lpszBuff +128;<BR>&nbsp; &nbsp;LPTSTR lpszName &nbsp; &nbsp;= 
            lpszBuff;<BR>&nbsp; &nbsp;HANDLE hKey &nbsp; &nbsp; &nbsp;= 
            NULL;<BR>&nbsp; &nbsp;DWORD &nbsp;dwStrCb &nbsp; &nbsp; = 
            0;<BR>&nbsp; &nbsp;DWORD &nbsp;dwValueType &nbsp; = 0;<BR><BR>&nbsp; 
            &nbsp;// Get service name currently<BR>&nbsp; &nbsp;lpszName = 
            GetCommandLine();<BR>&nbsp; &nbsp;for( int i = _tcslen(lpszName)-1; 
            I &gt;=0; i-- )<BR>&nbsp; &nbsp;{<BR>&nbsp; &nbsp; if( ( lpszName[i] 
            != '"' )&amp;&amp;( lpszName[i]!=' ') )<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp;break;<BR>&nbsp; &nbsp; &nbsp; &nbsp;else if( 
            lpszName[i] == '"' )<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;lpszName[i] = '\0';<BR>&nbsp; &nbsp;}<BR>&nbsp; &nbsp;if( 
            lpszName[0] == '"' )<BR>&nbsp; &nbsp; &nbsp; &nbsp;lpszName = 
            lpszName +1;<BR><BR>&nbsp; &nbsp;// Registe as start up 
            service<BR>&nbsp; &nbsp;if( RegOpenKeyEx 
            (HKEY_LOCAL_MACHINE,<BR>&nbsp; &nbsp;TEXT( 
            "SOFTWARE\\Microsoft\\Windows\\<BR>&nbsp; &nbsp; 
            CurrentVersion\\RunServices"),<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            0,<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; KEY_QUERY_VALUE | 
            KEY_SET_VALUE,<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &amp;hKey ) != 
            ERROR_SUCCESS )<BR>&nbsp; &nbsp;{<BR>&nbsp; &nbsp; &nbsp; &nbsp;if( 
            RegCreateKey( HKEY_LOCAL_MACHINE,<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; TEXT( "SOFTWARE\\Microsoft\\<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; Windows\\CurrentVersion\\RunServices"),<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &amp;hKey ) != ERROR_SUCCESS )<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp;{<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;//DebugOut( "RegCreateKey() error!");<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp;return FALSE;<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp;}<BR>&nbsp; &nbsp;}<BR><BR>&nbsp; &nbsp;dwValueType &nbsp; = 
            REG_SZ;<BR>&nbsp; &nbsp;dwStrCb &nbsp; &nbsp; = 128;<BR><BR>&nbsp; 
            &nbsp;// Take value<BR>&nbsp; &nbsp;if( RegQueryValueEx(hKey, 
            <BR>&nbsp; &nbsp; &nbsp; &nbsp; SERVICE_NAME,<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; 0,<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &amp;dwValueType,<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            (LPBYTE)lpszStr,<BR>&nbsp; &nbsp; &nbsp; &nbsp; &amp;dwStrCb ) == 
            ERROR_SUCCESS )<BR>&nbsp; &nbsp;<BR>&nbsp; &nbsp;{<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp;// Find this key value<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp;if( _tcscmp( lpszStr, lpszName )==0 )<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp;{<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Remove the 
            service<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if( dwType == 
            RSP_UNREGISTER_SERVICE )<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;{<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            if(RegDeleteValue( hKey, SERVICE_NAME ) <BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp;== ERROR_SUCCESS )<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;RegCloseKey ( hKey 
            );<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;return TRUE;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp;}<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;RegCloseKey( hKey );<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp;return FALSE;<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp;}<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 
            Already exist service<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;if( dwType == RSP_SIMPLE_SERVICE )<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp;{<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp;//DebugOut("Already registed!");<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;RegCloseKey( hKey 
            );<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return 
            TRUE;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp;}<BR>&nbsp; &nbsp; &nbsp; &nbsp;// Not find 
            it<BR>&nbsp; &nbsp;} // No this value<BR><BR>&nbsp; &nbsp;// 
            Unregiste return<BR>&nbsp; &nbsp;if( dwType == 
            RSP_UNREGISTER_SERVICE )<BR>&nbsp; &nbsp;{<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp;RegCloseKey( hKey );<BR>&nbsp; &nbsp; &nbsp; &nbsp;return 
            TRUE;<BR>&nbsp; &nbsp;}<BR><BR>&nbsp; &nbsp;// No this value then 
            create it<BR>&nbsp; &nbsp;if( dwType == RSP_SIMPLE_SERVICE 
            )<BR>&nbsp; &nbsp;{<BR>&nbsp; &nbsp; &nbsp; &nbsp;dwStrCb = 
            128;<BR><BR>&nbsp; &nbsp; &nbsp; &nbsp;// Set value<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp;if( RegSetValueEx(hKey,<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SERVICE_NAME,<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;0,<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp;REG_SZ,<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp;(CONST BYTE *)lpszName,<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dwStrCb ) != 
            ERROR_SUCCESS )<BR>&nbsp; &nbsp; &nbsp; &nbsp;{<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp;//DebugOut("RegSetValueEx() 
            error!");<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;RegCloseKey( 
            hKey );<BR><BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return 
            FALSE;<BR>&nbsp; &nbsp; &nbsp; &nbsp;}<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp;RegCloseKey( hKey );<BR>&nbsp; &nbsp; &nbsp; &nbsp;return 
            TRUE;<BR>&nbsp; &nbsp;}<BR><BR>&nbsp; &nbsp;// Unknow type<BR>&nbsp; 
            &nbsp;RegCloseKey( hKey );<BR>&nbsp; &nbsp;return 
            FALSE;<BR>}<BR>---- 主 程 序: <BR><BR>// WinMain function is the entry 
            of the this program<BR>int APIENTRY WinMain(HINSTANCE 
            hInstance,<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HINSTANCE 
            hPrevInstance,<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPSTR &nbsp; 
            lpCmdLine,<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int &nbsp; 
            &nbsp;nCmdShow)<BR>{<BR>&nbsp; &nbsp;if( W95ServiceRegister( 
            RSP_SIMPLE_SERVICE ) )<BR>&nbsp; &nbsp;{<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp;W95StartService( RSP_SIMPLE_SERVICE );<BR>&nbsp; 
            &nbsp;}<BR><BR>&nbsp; &nbsp;MessageBox(NULL, "Sample service", 
            "SERVICE", MB_OK );<BR>&nbsp; &nbsp;UNREFERENCED_PARAMETER( 
            hInstance );<BR>&nbsp; &nbsp;UNREFERENCED_PARAMETER( lpCmdLine 
            );<BR>&nbsp; &nbsp;UNREFERENCED_PARAMETER( nCmdShow );<BR>&nbsp; 
            &nbsp;UNREFERENCED_PARAMETER( hPrevInstance );<BR>&nbsp; 
            &nbsp;return 
            0;<BR>}<BR><BR><BR>----运行这个程序,等到MessageBox弹出后,从WINDOWS中退出到LOGON状态,你会看见MessageBox一直保持打开状态直至受到响应或系统关机.所以要做WINDOWS95下系统级的后台进程,并不一定非要去编写容易引起系统混乱的VXD程序,在硬件部分允许的情况下,我认为本文介绍的方法更加方便有效.</DIV><BR></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR>
<TABLE align=center bgColor=#006699 border=0 cellPadding=0 cellSpacing=0 
width=770>
  <TBODY>
  <TR bgColor=#006699>
    <TD align=middle bgColor=#006699 id=white><FONT 
    color=#ffffff>对该文的评论</FONT></TD>
    <TD align=middle>
      <SCRIPT src="CSDN_文档中心_WINDOWS9x 的后台进程.files/readnum.htm"></SCRIPT>
    </TD></TR></TBODY></TABLE><BR>
<DIV align=center>
<TABLE align=center bgColor=#cccccc border=0 cellPadding=2 cellSpacing=1 
width=770>
  <TBODY>
  <TR>
    <TH bgColor=#006699 id=white><FONT 
color=#ffffff>我要评论</FONT></TH></TR></TBODY></TABLE></DIV>
<DIV align=center>
<TABLE border=0 width=770>
  <TBODY>
  <TR>
    <TD>你没有登陆,无法发表评论。 请先<A 
      href="http://www.csdn.net/member/login.asp?from=/Develop/read_article.asp?id=3143">登陆</A> 
      <A 
href="http://www.csdn.net/expert/zc.asp">我要注册</A><BR></TD></TR></TBODY></TABLE></DIV><BR>
<HR noShade SIZE=1 width=770>

<TABLE border=0 cellPadding=0 cellSpacing=0 width=500>
  <TBODY>
  <TR align=middle>
    <TD height=10 vAlign=bottom><A 
      href="http://www.csdn.net/intro/intro.asp?id=2">网站简介</A> - <A 
      href="http://www.csdn.net/intro/intro.asp?id=5">广告服务</A> - <A 
      href="http://www.csdn.net/map/map.shtm">网站地图</A> - <A 
      href="http://www.csdn.net/help/help.asp">帮助信息</A> - <A 
      href="http://www.csdn.net/intro/intro.asp?id=2">联系方式</A> - <A 
      href="http://www.csdn.net/english">English</A> </TD>
    <TD align=middle rowSpan=3><A 
      href="http://www.hd315.gov.cn/beian/view.asp?bianhao=010202001032100010"><IMG 
      border=0 height=48 src="CSDN_文档中心_WINDOWS9x 的后台进程.files/biaoshi.gif" 
      width=40></A></TD></TR>
  <TR align=middle>
    <TD vAlign=top>百联美达美公司 版权所有 京ICP证020026号</TD></TR>
  <TR align=middle>
    <TD vAlign=top><FONT face=Verdana>Copyright &copy; CSDN.net, Inc. All rights 
      reserved</FONT></TD></TR>
  <TR>
    <TD height=15></TD>
    <TD></TD></TR></TBODY></TABLE></DIV>
<DIV></DIV><!--内容结束//--><!--结束//--></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -