使用vc6.0开发的windows服务程序

xyqxdd 2014-06-03 05:18:58
使用vc6.0开发的一个服务程序,最后发布成realease版本,里面有服务的exe程序,在本机运行该exe程序,就可以在任务管理器中找到发布的服务,但是在别的电脑上运行该exe程序,没有反应,是怎么回事???
...全文
421 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
zzfzd123 2014-11-07
  • 打赏
  • 举报
回复
敢问楼主,ATL服务。你解决了吗??
x幸y运q签 2014-06-06
  • 打赏
  • 举报
回复
按上面方式注册了还是看不到服务啊
ForestDB 2014-06-05
  • 打赏
  • 举报
回复
有无log?
huanglin03 2014-06-05
  • 打赏
  • 举报
回复
在运行框中输入 AAAA.exe /UnregServer 为反 注册格式 AAAA.exe /service 为注册格式
huanglin03 2014-06-05
  • 打赏
  • 举报
回复
VC编译时,最后一步会自动帮你注册该服务的,你程序代码里没有注册,到别人的机器上就是没有注册,服务不注册,服务管理器就不认,当然会出各种异常的了,,
Dobzhansky 2014-06-04
  • 打赏
  • 举报
回复
vc6 没有 crt 问题, 有无用到第三方库? 那台机器登录账户有安装服务的权限?
赵4老师 2014-06-04
  • 打赏
  • 举报
回复
用调试器(OD,WINDBG等)调试服务程序 To debug the initialization code of a service application, the debugger must be attached when the service is started. This is accomplished by creating a registry key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\ProgramName The ProgramName is the image file for the service application you are debugging. Do not specify a path. For example, the ProgramName might look like MyService.exe. Under this key create a string data value called Debugger. The value of this string should be set to the full path of the debugger that will be used. For example, c:\Debuggers\windbg.exe In addition to setting this registry key, the service application must be marked as "interactive". This allows your service to interact with the desktop, and allows the debugger window to appear on your desktop. This again requires modifying a registry key: you must bitwise-or the type entry for your service with 0x100 (this is the value for SERVICE_INTERACTIVE_PROCESS according to Winnt.h). The exact location and name of this registry entry varies. For example: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MyServiceKey Finally, you need to adjust the service application timeout. Otherwise, the service application will kill the debugger within 20 seconds after starting. Adjusting the timeout involves setting an entry in the following registry key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control Under this key, create a DWORD data value called ServicesPipeTimeout. Set this entry to the amount of time in milliseconds that you want the service to wait before timing out. For example, 60,000 is one minute, while 86,400,000 is 24 hours. 设置ServicesPipeTimeout后需要重启系统才生效 Now, when the service is started, the debugger will also start. When the debugger starts, it will stop at the initial process breakpoint, before the service has begun running. This allows you to set breakpoints or otherwise configure your debugging session to let you monitor the startup of your service. Another option is to place calls to the DebugBreak function in your service from the point at which you would like to break into the debugger. (For more information, see DebugBreak in the Platform SDK documentation.) If your service is running with other services in a Service Host Process, you may need to isolate the service into its own Service Host Process.
x幸y运q签 2014-06-04
  • 打赏
  • 举报
回复
,最后生成的服务是exe形式的啊,怎么在别的机子上注册
赵4老师 2014-06-04
  • 打赏
  • 举报
回复
在64位Windows下: 64位exe和dll在目录c:\windows\system32目录下; 32位exe和dll在目录c:\windows\syswow64目录下; 在64位Windows下注册32位的dll要用 c:\windows\syswow64\regsvr32.exe c:\windows\syswow64\xxxxxxxxxx.dll
x幸y运q签 2014-06-04
  • 打赏
  • 举报
回复
动态链接库??什么意思
jiangbai333 2014-06-04
  • 打赏
  • 举报
回复
动态链接库!
x幸y运q签 2014-06-04
  • 打赏
  • 举报
回复
http://www.bianceng.cn/Programming/vc/201011/19877.htm,按照这个上面生成的服务,编译运行成功,发布release版本,成功后的exe在别的机子双击后找不到服务
x幸y运q签 2014-06-04
  • 打赏
  • 举报
回复
没有设置权限
Dobzhansky 2014-06-04
  • 打赏
  • 举报
回复
regserver 就是写注册表, 有无权限嗯,
x幸y运q签 2014-06-04
  • 打赏
  • 举报
回复
在cmd下先运行YourSvr/RegServer,再运行YourSvr/Service,最后是YourSvr.exe/register,在本机可以,别的机子不行
x幸y运q签 2014-06-04
  • 打赏
  • 举报
回复
已经用depends查看过依赖的dll了,别的机子上都有,还是不能运行
赵4老师 2014-06-04
  • 打赏
  • 举报
回复
先用depends.exe查看exe依赖的dll及其版本号, 再将除系统dll(比如kernel32.dll,ntdll.dll,gdi32.dll……)以外的dll拷贝到exe文件所在目录下。
赵4老师 2014-06-04
  • 打赏
  • 举报
回复
用depends.exe查看exe依赖的dll及其版本号。 depends.exe不需要编译开发环境。 C:\60G\Microsoft SDK\Bin\Depends.Exe C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Bin\Depends.Exe C:\Program Files\Microsoft Visual Studio\Common\Tools\DEPENDS.EXE C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\Bin\Depends.Exe C:\SupportTools\depends.exe
x幸y运q签 2014-06-04
  • 打赏
  • 举报
回复
别的机子上面没有编译环境的,在本机调试成功后,直接在别的机子上运行的
赵4老师 2014-06-04
  • 打赏
  • 举报
回复
引用 5 楼 xyqxdd 的回复:
发布的release版本,里面有生成的exe服务程序,双击该程序,本机任务管理器中就有这个服务,把这个程序拷贝到别的机子,双击exe就没有反应,服务也没开启
用depends.exe查看exe依赖的dll及其版本号。 有时不将“调用函数名字+各参数值,进入函数后各参数值,中间变量值,退出函数前准备返回的值,返回函数到调用处后函数名字+各参数值+返回值”这些信息写日志到文件中是无论如何也发现不了问题在哪里的,包括捕获各种异常、写日志到屏幕、单步或设断点或生成core文件、……这些方法都不行! 写日志到文件参考下面:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef WIN32
    #include <windows.h>
    #include <io.h>
#else
    #include <unistd.h>
    #include <sys/time.h>
    #include <pthread.h>
    #define  CRITICAL_SECTION   pthread_mutex_t
    #define  _vsnprintf         vsnprintf
#endif
//Log{
#define MAXLOGSIZE 20000000
#define MAXLINSIZE 16000
#include <time.h>
#include <sys/timeb.h>
#include <stdarg.h>
char logfilename1[]="MyLog1.log";
char logfilename2[]="MyLog2.log";
static char logstr[MAXLINSIZE+1];
char datestr[16];
char timestr[16];
char mss[4];
CRITICAL_SECTION cs_log;
FILE *flog;
#ifdef WIN32
void Lock(CRITICAL_SECTION *l) {
    EnterCriticalSection(l);
}
void Unlock(CRITICAL_SECTION *l) {
    LeaveCriticalSection(l);
}
#else
void Lock(CRITICAL_SECTION *l) {
    pthread_mutex_lock(l);
}
void Unlock(CRITICAL_SECTION *l) {
    pthread_mutex_unlock(l);
}
#endif
void LogV(const char *pszFmt,va_list argp) {
    struct tm *now;
    struct timeb tb;

    if (NULL==pszFmt||0==pszFmt[0]) return;
    _vsnprintf(logstr,MAXLINSIZE,pszFmt,argp);
    ftime(&tb);
    now=localtime(&tb.time);
    sprintf(datestr,"%04d-%02d-%02d",now->tm_year+1900,now->tm_mon+1,now->tm_mday);
    sprintf(timestr,"%02d:%02d:%02d",now->tm_hour     ,now->tm_min  ,now->tm_sec );
    sprintf(mss,"%03d",tb.millitm);
    printf("%s %s.%s %s",datestr,timestr,mss,logstr);
    flog=fopen(logfilename1,"a");
    if (NULL!=flog) {
        fprintf(flog,"%s %s.%s %s",datestr,timestr,mss,logstr);
        if (ftell(flog)>MAXLOGSIZE) {
            fclose(flog);
            if (rename(logfilename1,logfilename2)) {
                remove(logfilename2);
                rename(logfilename1,logfilename2);
            }
        } else {
            fclose(flog);
        }
    }
}
void Log(const char *pszFmt,...) {
    va_list argp;

    Lock(&cs_log);
    va_start(argp,pszFmt);
    LogV(pszFmt,argp);
    va_end(argp);
    Unlock(&cs_log);
}
//Log}
int main(int argc,char * argv[]) {
    int i;
#ifdef WIN32
    InitializeCriticalSection(&cs_log);
#else
    pthread_mutex_init(&cs_log,NULL);
#endif
    for (i=0;i<10000;i++) {
        Log("This is a Log %04d from FILE:%s LINE:%d\n",i, __FILE__, __LINE__);
    }
#ifdef WIN32
    DeleteCriticalSection(&cs_log);
#else
    pthread_mutex_destroy(&cs_log);
#endif
    return 0;
}
//1-78行添加到你带main的.c或.cpp的那个文件的最前面
//81-85行添加到你的main函数开头
//89-93行添加到你的main函数结束前
//在要写LOG的地方仿照第87行的写法写LOG到文件MyLog1.log中
加载更多回复(3)

64,647

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧