QQ1321.CN 努力为您提供一个时尚的QQ空间代码交流平台!
一生愛妳QQ空间站
您当前的位置:QQ空间代码|QQ空间模块|QQ图标|QQ空间互踩|QQ免费资源 >> QQ空间代码 >> 文章内容 ╰☆╮文字广告位 ☏非主流同城缘分 ☜网友自由发布空间模块平台☞
创建SvcHost.exe 调用的服务原理与实践(8)
作者:郁郁小蝎 来源:中国站长学院(QQ1321)原创Www.QQ1321.Cn 收藏到QQ书签 【添加到百度搜藏】  推荐好友
/*
used to install by rundll32.exe
Platform SDK: Tools - Rundll32
The Run DLL utility (Rundll32.exe) included in Windows enables you to call functions exported from a 32-bit DLL. These functions must have the following syntax:
*/
void CALLBACK RundllInstallA(
HWND hwnd,// handle to owner window
HINSTANCE hinst,// instance handle for the DLL
char *param,// string the DLL will parse
int nCmdShow// show state
)
{
InstallService(param);
}


int UninstallService(char *name)
{
int rc = 0;
SC_HANDLE schService;
SC_HANDLE hscm;

 __try{
hscm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (hscm == NULL)
{
OutputString("OpenSCManager() error %d", rc = GetLastError() );
return rc;
}

 char *svcname = DEFAULT_SERVICE;
if(name && name[0]) svcname = name;

 schService = OpenService(hscm, svcname, DELETE);
if (schService == NULL)
{
OutputString("OpenService(%s) error %d", svcname, rc = GetLastError() );
return rc;
}

 if (!DeleteService(schService) )
{
OutputString("OpenService(%s) error %d", svcname, rc = GetLastError() );
return rc;
}

 OutputString("DeleteService(%s) SUCCESS.", svcname);
}__except(1)
{
OutputString("Exception Catched 0x%X", GetExceptionCode());
}

 CloseServiceHandle(schService);
CloseServiceHandle(hscm);
return rc;
}

/*
used to uninstall by rundll32.exe
Platform SDK: Tools - Rundll32
The Run DLL utility (Rundll32.exe) included in Windows enables you to call functions exported from a 32-bit DLL. These functions must have the following syntax:
*/
void CALLBACK RundllUninstallA(
HWND hwnd,// handle to owner window
HINSTANCE hinst,// instance handle for the DLL
char *param,// string the DLL will parse
int nCmdShow// show state
)
{
UninstallService(param);
}

//output the debug infor into log file & DbgPrint
void OutputString( char *lpFmt, ... )
{
char buff[1024];
va_listarglist;
va_start( arglist, lpFmt );
_vsnprintf( buff, sizeof buff, lpFmt, arglist );
va_end( arglist );

 DWORD len;
HANDLE herr = GetStdHandle(STD_OUTPUT_HANDLE);
if(herr != INVALID_HANDLE_value)
{
WriteFile(herr, buff, strlen(buff), &len, NULL);
WriteFile(herr, "\r\n", 2, &len, NULL);
}else
{
FILE *fp = fopen("SvcHost.DLL.log", "a");
if(fp)
{
char date[20], time[20];
fprintf(fp, "%s %s - %s\n", _strdate(date), _strtime(time), buff);
if(!stderr) fclose(fp);
}
}

 OutputDebugString(buff);
}

上篇内容:文章:学会保护你计算机中的隐私
下篇内容:文章:创建SvcHost.exe 调用的服务原理与实践(7)
将本文收藏到QQ书签中,以便日后查看或与好友分享
代码阅读排行
· 入侵检测及网络安全发展技术探讨(3)...
· 在Windows XP中如何取得文件或文件夹...
· Win2003“安全事件ID”分析(2)
· Win2003“安全事件ID”分析(3)
· 清除Security列表中的未知用户
· 电脑高手常用的五个按钮
站长精彩推荐
精彩推荐内容
· 何谓HTTP 500内部服务器错误


版权所有:一生愛妳┆QQ空间代码酷站 最佳分辨率 IE6.0 1024×768 备案中 站长(信仰自由)QQ:271443991
未经本站授权严禁建立镜像.本站部分资源来源于网络,版权归原作者所有 欢迎任何建议、批评和鼓励
Copyright © 2007-2008 信仰自由 All Rights Reserved .
收藏此页 - 推荐好友 - 友情连接 - - 信仰自由 - 联系我们 - 网站地图 - 关于我们