//开始按钮的消息响应函数,所有功能在此实现
void CIpctoolsDlg::OnStart()
{
UpdateData();
CPromptDlg PromptDlg;
if(m_strIPAddress.IsEmpty()||m_strUserName.IsEmpty())
{
PromptDlg.m_strMessage = _T("请填写IP、用户名、密码。");
PromptDlg.DoModal();
return;
}
if(m_strLocalFile.IsEmpty())
{
CFileDlg dlg;
dlg.m_strMessage = _T("文件存在了吗?");
if(dlg.DoModal()==IDCANCEL)
return;
else
bFileExist =TRUE;
}
if(m_strStartCmd.IsEmpty())
{
PromptDlg.m_strMessage = _T("请指定你要运行的程序。");
PromptDlg.DoModal();
return;
}
//用自定义函数建立IPC连接
BOOL bRet = ConnectIPC((TCHAR *)m_strIPAddress.operator LPCTSTR(),m_strUserName.operator LPCTSTR(),m_strPassWord.operator LPCTSTR());
if(bRet == FALSE)
{
DisConnectIPC((TCHAR *)m_strIPAddress.operator LPCTSTR());
for(int i=1;i<=50;i++)
m_Progress.SetPos(i);
PromptDlg.m_strMessage = _T("连接失败。");
if(PromptDlg.DoModal()==IDOK)
m_Progress.SetPos(0);
return;
}
LPTIME_OF_DAY_INFO pBuf=NULL;
NET_API_STATUS nStatus;
nStatus = NetRemoteTOD(m_strIPAddress.AllocSysString(),(LPBYTE*)&pBuf); //获取远程主机的时间
if (nStatus != NERR_Success)
{
DisConnectIPC((TCHAR *)m_strIPAddress.operator LPCTSTR());
for(int i=1;i<=100;i++)
m_Progress.SetPos(i);
PromptDlg.m_strMessage = _T("获取远程主机时间失败。");
if(PromptDlg.DoModal()==IDOK)
m_Progress.SetPos(0);
return;
}
if (pBuf != NULL)
NetApiBufferFree(pBuf);
strRemoteFile = _T("\\\\"+m_strIPAddress+"\\"+m_strRemoteFile);
if(!bFileExist)
{
bRet = ::CopyFile(m_strLocalFile.operator LPCTSTR(),strRemoteFile.operator LPCTSTR(),FALSE);//向远程主机拷贝文件
if(!bRet)
{
DWORD dwret = GetLastError();
DisConnectIPC((TCHAR *)m_strIPAddress.operator LPCTSTR());
for(int i=1;i<=150;i++)
m_Progress.SetPos(i);
CString strMessage;
strMessage.Format(_T("(%d)"),dwret);
strMessage = _T("复制文件")+strRemoteFile+_T("失败")+strMessage;
PromptDlg.m_strMessage = strMessage;
if(PromptDlg.DoModal()==IDOK)
m_Progress.SetPos(0);
return;
}
}
DWORD Day=1;
CTime tm(pBuf->tod_year,pBuf->tod_month,pBuf->tod_day,pBuf->tod_hours+(-pBuf->tod_timezone)/60,pBuf->tod_mins,pBuf->tod_secs);
for(int i=1;i<tm.GetDay();i++)
Day = Day*2;
LPDWORD JobId;
AT_INFO ai;
memset(&ai,0,sizeof(ai));
//给ai结构变量各成员赋值
ai.Command = m_strStartCmd.AllocSysString();
ai.DaysOfMonth = Day;
ai.DaysOfWeek = 0;
ai.Flags = JOB_NONINTERACTIVE;
ai.JobTime = ((pBuf->tod_hours+(-pBuf->tod_timezone)/60)%24)*60*60*1000+(pBuf->tod_mins+1)*60*1000;
nStatus = NetScheduleJobAdd(m_strIPAddress.AllocSysString(),LPBYTE(&ai),JobId);//添加作业
if(nStatus == NERR_Success)
{
DisConnectIPC((TCHAR *)m_strIPAddress.operator LPCTSTR());
for(int i=1;i<=1000;i++)
m_Progress.SetPos(i);
PromptDlg.m_strMessage = _T("指定的程序将于60秒后启动。");
if(PromptDlg.DoModal()==IDOK)
m_Progress.SetPos(0);
return;
}
else
{
DisConnectIPC((TCHAR *)m_strIPAddress.operator LPCTSTR());
DWORD dwret = GetLastError();
for(int i=1;i<=200;i++)
m_Progress.SetPos(i);
CString strMessage;
strMessage.Format(_T("(%d)"),dwret);
strMessage = _T("启动程序失败")+strMessage;
PromptDlg.m_strMessage= strMessage;
if(PromptDlg.DoModal() ==IDOK)
m_Progress.SetPos(0);
return;
}
}
void CIpctoolsDlg::OnStart()
{
UpdateData();
CPromptDlg PromptDlg;
if(m_strIPAddress.IsEmpty()||m_strUserName.IsEmpty())
{
PromptDlg.m_strMessage = _T("请填写IP、用户名、密码。");
PromptDlg.DoModal();
return;
}
if(m_strLocalFile.IsEmpty())
{
CFileDlg dlg;
dlg.m_strMessage = _T("文件存在了吗?");
if(dlg.DoModal()==IDCANCEL)
return;
else
bFileExist =TRUE;
}
if(m_strStartCmd.IsEmpty())
{
PromptDlg.m_strMessage = _T("请指定你要运行的程序。");
PromptDlg.DoModal();
return;
}
//用自定义函数建立IPC连接
BOOL bRet = ConnectIPC((TCHAR *)m_strIPAddress.operator LPCTSTR(),m_strUserName.operator LPCTSTR(),m_strPassWord.operator LPCTSTR());
if(bRet == FALSE)
{
DisConnectIPC((TCHAR *)m_strIPAddress.operator LPCTSTR());
for(int i=1;i<=50;i++)
m_Progress.SetPos(i);
PromptDlg.m_strMessage = _T("连接失败。");
if(PromptDlg.DoModal()==IDOK)
m_Progress.SetPos(0);
return;
}
LPTIME_OF_DAY_INFO pBuf=NULL;
NET_API_STATUS nStatus;
nStatus = NetRemoteTOD(m_strIPAddress.AllocSysString(),(LPBYTE*)&pBuf); //获取远程主机的时间
if (nStatus != NERR_Success)
{
DisConnectIPC((TCHAR *)m_strIPAddress.operator LPCTSTR());
for(int i=1;i<=100;i++)
m_Progress.SetPos(i);
PromptDlg.m_strMessage = _T("获取远程主机时间失败。");
if(PromptDlg.DoModal()==IDOK)
m_Progress.SetPos(0);
return;
}
if (pBuf != NULL)
NetApiBufferFree(pBuf);
strRemoteFile = _T("\\\\"+m_strIPAddress+"\\"+m_strRemoteFile);
if(!bFileExist)
{
bRet = ::CopyFile(m_strLocalFile.operator LPCTSTR(),strRemoteFile.operator LPCTSTR(),FALSE);//向远程主机拷贝文件
if(!bRet)
{
DWORD dwret = GetLastError();
DisConnectIPC((TCHAR *)m_strIPAddress.operator LPCTSTR());
for(int i=1;i<=150;i++)
m_Progress.SetPos(i);
CString strMessage;
strMessage.Format(_T("(%d)"),dwret);
strMessage = _T("复制文件")+strRemoteFile+_T("失败")+strMessage;
PromptDlg.m_strMessage = strMessage;
if(PromptDlg.DoModal()==IDOK)
m_Progress.SetPos(0);
return;
}
}
DWORD Day=1;
CTime tm(pBuf->tod_year,pBuf->tod_month,pBuf->tod_day,pBuf->tod_hours+(-pBuf->tod_timezone)/60,pBuf->tod_mins,pBuf->tod_secs);
for(int i=1;i<tm.GetDay();i++)
Day = Day*2;
LPDWORD JobId;
AT_INFO ai;
memset(&ai,0,sizeof(ai));
//给ai结构变量各成员赋值
ai.Command = m_strStartCmd.AllocSysString();
ai.DaysOfMonth = Day;
ai.DaysOfWeek = 0;
ai.Flags = JOB_NONINTERACTIVE;
ai.JobTime = ((pBuf->tod_hours+(-pBuf->tod_timezone)/60)%24)*60*60*1000+(pBuf->tod_mins+1)*60*1000;
nStatus = NetScheduleJobAdd(m_strIPAddress.AllocSysString(),LPBYTE(&ai),JobId);//添加作业
if(nStatus == NERR_Success)
{
DisConnectIPC((TCHAR *)m_strIPAddress.operator LPCTSTR());
for(int i=1;i<=1000;i++)
m_Progress.SetPos(i);
PromptDlg.m_strMessage = _T("指定的程序将于60秒后启动。");
if(PromptDlg.DoModal()==IDOK)
m_Progress.SetPos(0);
return;
}
else
{
DisConnectIPC((TCHAR *)m_strIPAddress.operator LPCTSTR());
DWORD dwret = GetLastError();
for(int i=1;i<=200;i++)
m_Progress.SetPos(i);
CString strMessage;
strMessage.Format(_T("(%d)"),dwret);
strMessage = _T("启动程序失败")+strMessage;
PromptDlg.m_strMessage= strMessage;
if(PromptDlg.DoModal() ==IDOK)
m_Progress.SetPos(0);
return;
}
}