高分求win server 2008 / C++ 高手牛人解答困惑 - SCM启动的某进程创建WLBS子进程操作远端cluster node 失败

Richard_L 2014-07-08 01:36:33
OS:Windows server 2008 / Windows server 2008 r2
IDE:Visual C++ 2005

我有一个程序A,Win32的程序,service的形式,在windows的service control manager中启动。A中调用CreateProcess创建WLBS命令去启动和停止远程的cluster节点。但是无论如何也不能启动或者停止远程节点,可以启动或者停止本地节点。 另外,手动执行wlbs命令是可以启动远程节点的。wlbs服务没有设置密码。

求帮助!

关键代码如下:

服务的安装:

BOOL CNTService::Install()
{
// Open the Service Control Manager
SC_HANDLE hSCM = ::OpenSCManager(NULL, // local machine
NULL, // ServicesActive database
SC_MANAGER_ALL_ACCESS); // full access
if (!hSCM) return FALSE;

// Get the executable file path
char szFilePath[_MAX_PATH];
::GetModuleFileName(NULL, szFilePath, sizeof(szFilePath));

// Create the service
SC_HANDLE hService = ::CreateService(hSCM,
m_szServiceName,
m_szServiceName,
SERVICE_ALL_ACCESS,
SERVICE_WIN32_OWN_PROCESS |SERVICE_INTERACTIVE_PROCESS,
SERVICE_DEMAND_START, // start condition
SERVICE_ERROR_NORMAL,
szFilePath,
NULL,
NULL,
NULL,
NULL,
NULL);
if (!hService) {
DWORD dwErr = GetLastError();
switch(dwErr)
{
case ERROR_ACCESS_DENIED:
break;
case ERROR_CIRCULAR_DEPENDENCY:
break;
case ERROR_DUP_NAME:
break;
case ERROR_INVALID_HANDLE:
break;
case ERROR_INVALID_NAME:
break;
case ERROR_INVALID_PARAMETER:
break;
case ERROR_INVALID_SERVICE_ACCOUNT:
break;
case ERROR_SERVICE_EXISTS:
break;
default:
break;
}
NvUtility::DisplayError("CreateService");
SetLastError(dwErr);
::CloseServiceHandle(hSCM);
return FALSE;
}

// make registry entries to support logging messages
// Add the source name as a subkey under the Application
// key in the EventLog service portion of the registry.
char szKey[256];
HKEY hKey = NULL;
strcpy(szKey, "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\");
strcat(szKey, m_szServiceName);
if (::RegCreateKey(HKEY_LOCAL_MACHINE, szKey, &hKey) != ERROR_SUCCESS) {
::CloseServiceHandle(hService);
::CloseServiceHandle(hSCM);
return FALSE;
}

// Add the Event ID message-file name to the 'EventMessageFile' subkey.
::RegSetValueEx(hKey,
"EventMessageFile",
0,
REG_EXPAND_SZ,
(CONST BYTE*)szFilePath,
strlen(szFilePath) + 1);

// Set the supported types flags.
DWORD dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE;
::RegSetValueEx(hKey,
"TypesSupported",
0,
REG_DWORD,
(CONST BYTE*)&dwData,
sizeof(DWORD));
::RegCloseKey(hKey);

LogEvent(EVENTLOG_INFORMATION_TYPE, EVMSG_INSTALLED, m_szServiceName);

// tidy up
::CloseServiceHandle(hService);
::CloseServiceHandle(hSCM);
return TRUE;
}


wlbs子进程的创建:

result NvCs::ExecWlbsCommand(const TCHAR *cmd)
{
result res = errUnknown;
PROCESS_INFORMATION pi = {NULL};
STARTUPINFO si = {sizeof(si)};
ZeroMemory(&pi, sizeof(pi));
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);

#if defined NDEBUG
si.wShowWindow = SW_HIDE;
#else
si.wShowWindow = SW_SHOWNORMAL;
#endif

// wlbs.exe is in the system directory
TCHAR cmdLine[MAX_PATH] = TEXT("");
UINT cb = ::GetSystemDirectory(cmdLine, sizeof cmdLine);
// This path does not end with a backslash unless the system directory is the root directory
if ((cb > 3) && (cb < sizeof cmdLine)) _tcscat(cmdLine, TEXT("\\"));

_tcscat(cmdLine, "WLBS.EXE ");
_tcscat(cmdLine, cmd);

if (::CreateProcess(NULL, cmdLine, 0, 0, FALSE, CREATE_NEW_CONSOLE, 0, 0, &si, &pi))
{
DWORD dwWait = ::WaitForSingleObject(pi.hProcess, wlbsTimeout);
if (WAIT_OBJECT_0 == dwWait)
{
DWORD wlbsExitCode = 0XFFFFFFFF;
if (::GetExitCodeProcess(pi.hProcess, &wlbsExitCode) && (1 == wlbsExitCode))
res = success;
DebugMsg("wlbsExitCode = %d\n", wlbsExitCode);
} else {
res = errUnexpected;
DebugMsg("Trouble while executing WLBS command");
}
::CloseHandle(pi.hProcess);
::CloseHandle(pi.hThread);
}

if(m_b_simul_wlbs)
res = success;
DebugMsg("ExecWlbsCommand(%s), res = %d\n", cmdLine, res);
return res;
}
...全文
578 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
无想无念 2016-05-11
  • 打赏
  • 举报
回复
楼主解决了吗??
赵4老师 2014-07-17
  • 打赏
  • 举报
回复
#include <conio.h>
#include <stdio.h>
char pw[40];
int i,ch;
FILE *f;
void main() {
    cprintf("\r\nPassword:");
    i=0;pw[i]=0;
    while (1) {
        ch=getch();
        if (ch==13 || i>=39) break;
        switch (ch) {
        case 27:
            cprintf("\rPassword: %40s"," ");
            cprintf("\rPassword: ");
            i=0;pw[i]=0;
            break;
        case 8:
            if (i>0) {
                i--;
                pw[i]=0;
                cprintf("\b \b");
            }
            break;
        default:
            pw[i]=ch;
            i++;
            pw[i]=0;
            cprintf("*");
            break;
        }
    }
    cprintf("\r\n");
    f=fopen("password.txt","w");
    fprintf(f,"%s\n",pw);
    fclose(f);
}
Richard_L 2014-07-08
  • 打赏
  • 举报
回复
是不是分不够?我可以加的,只要回答。
Richard_L 2014-07-08
  • 打赏
  • 举报
回复
是不是哪里说的不清楚?我可以补充的!
Richard_L 2014-07-08
  • 打赏
  • 举报
回复
怎么没人理我?

6,869

社区成员

发帖
与我相关
我的任务
社区描述
Windows 2016/2012/2008/2003/2000/NT
社区管理员
  • Windows Server社区
  • qishine
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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