rt

解决方案 »

  1.   

    http://www.microsoft.com/technet/scriptcenter/guide/sas_fil_ixpv.mspx
      

  2.   

    2003里:管理工具->远程桌面->添加一个连接
    登陆后,在左边的导航栏设置属性->其他->选中登陆远程计算机时自动映射本地驱动器
    注销后再登陆,可以看到本地的驱动器了
      

  3.   

    Set sh = CreateObject("wscript.shell")
    sh.run "net use \\xxx.xxx.xxx.xxx\c$\ admin  /user:admin"
    sh = null
    ' VBScript source code
    Const source_Folder = "C:\"
    Const aim_Folder    = "\\xxx.xxx.xxx.xxx\c$\"Set objFSO = CreateObject("Scripting.FileSystemObject")
    objStartFolder = aim_Folder        Set objFolder = objFSO.GetFolder(objStartFolder)Set colFiles = objFolder.Files
    For Each objFile in colFiles
         
        If objFile.Attributes AND 1 Then
           objFile.Attributes = objFile.Attributes XOR 1
        End If
    Next
      'Copy StartFolder Files
    Const OverWriteFiles = True
    Set sourceStartFolder = objFSO.GetFolder(source_Folder)ShowSubfolders objFSO.GetFolder(sourceStartFolder)Set sourceStartFolderFiles = sourceStartFolder.FilesIf sourceStartFolderFiles.count > 0 Then
       objFSO.CopyFile source_Folder&"\*.*" , aim_Folder, OverWriteFiles 
    End IF 
        
     Wscript.Echo "Good"
    Sub ShowSubFolders(Folder)
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        For Each Subfolder in Folder.SubFolders
            Set objFolder = objFSO.GetFolder(Subfolder.Path)
            If objFSO.FolderExists(aim_Folder&"\"&objFolder.Name) Then
            
              If objFolder.Name <> "DLLs" And objFolder.Name <> "DataBase"   Then
                 Set colFiles = objFolder.Files
                   For Each objFile in colFiles
                      
                         If objFSO.GetExtensionName(source_Folder&"\"&objFolder.Name&"\"&objFile.Name) <> "cs"  AND  objFSO.GetExtensionName(source_Folder&"\"&objFolder.Name&"\"&objFile.Name) <> "pdb" Then
                         
                         
                          If objFSO.FileExists(aim_Folder&"\"&objFolder.Name&"\"&objFile.Name) Then
                              Set aimFile = objFSO.GetFile(aim_Folder&"\"&objFolder.Name&"\"&objFile.Name )
                             If objFile.DateLastModified>aimFile.DateLastModified Then
                               
                                If aimFile.Attributes AND 1 Then
                                 aimFile.Attributes = aimFile.Attributes XOR 1
                                End If 
                             objFSO.CopyFile source_Folder&"\"&objFolder.Name&"\"&objFile.Name , aim_Folder&"\"&objFolder.Name&"\", OverWriteFiles 
                             End If
                          Else
                                
                             objFSO.CopyFile source_Folder&"\"&objFolder.Name&"\"&objFile.Name , aim_Folder&"\"&objFolder.Name&"\", OverWriteFiles 
                                                End if
                         End if
                       
                 Next
                
              End If
           Else
          
            If objFolder.Name <> "DLLs" And objFolder.Name <> "DataBase"   Then
               objFSO.CopyFolder source_Folder&"\"&objFolder.Name,aim_Folder&"\"&objFolder.Name,OverWriteFiles
            End If
           End If
          
        Next
    End Sub
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
                         
        
      

  4.   

    用wmi不是很好,有很多限制
    还是用net use 命令好一些,只要知道用户名密码public static bool Ping(string remoteHost)
    {
    bool Flag = false;
    Process proc = new Process();
    try
    {
    proc.StartInfo.FileName = "cmd.exe";
    proc.StartInfo.UseShellExecute = false;
    proc.StartInfo.RedirectStandardInput = true;
    proc.StartInfo.RedirectStandardOutput = true;
    proc.StartInfo.RedirectStandardError = true;
    proc.StartInfo.CreateNoWindow = true;
    proc.Start();
    string dosLine = @"ping -n 1 " + remoteHost;
    proc.StandardInput.WriteLine(dosLine);
    proc.StandardInput.WriteLine("exit");
    while (proc.HasExited == false)
    {
    proc.WaitForExit(500);
    }
    string pingResult = proc.StandardOutput.ReadToEnd();
    if (pingResult.IndexOf("(0% loss)") != -1)
    {
    Flag = true;
    }
    proc.StandardOutput.Close() ;
    }
    catch (Exception ex)
    {
    }
    finally
    {
    try
    {
    proc.Close();
    proc.Dispose();
    }
    catch
    {
    }
    }
    return Flag;
    }public static bool Connect(string remoteHost, string userName, string passWord)
    {
    if(!Ping(remoteHost))
    {
    return false;
    }
    bool Flag = true;
    Process proc = new Process();
    try
    {
    proc.StartInfo.FileName = "cmd.exe";
    proc.StartInfo.UseShellExecute = false;
    proc.StartInfo.RedirectStandardInput = true;
    proc.StartInfo.RedirectStandardOutput = true;
    proc.StartInfo.RedirectStandardError = true;
    proc.StartInfo.CreateNoWindow = true;
    proc.Start();
    string dosLine = @"net use \\" + remoteHost + " " + passWord + " " + " /user:" + userName + ">NUL";
    proc.StandardInput.WriteLine(dosLine);
    proc.StandardInput.WriteLine("exit");
    while (proc.HasExited == false)
    {
    proc.WaitForExit(1000);
    }
    string errormsg = proc.StandardError.ReadToEnd();
    if (errormsg != "")
    {
    Flag = false;
    }
    proc.StandardError.Close() ;
    }
    catch (Exception ex)
    {
    Flag = false;
    }
    finally
    {
    try
    {
    proc.Close();
    proc.Dispose();
    }
    catch
    {
    }
    }
    return Flag;
    }
      

  5.   

    连接成功后,用File.Copy就可以了
      

  6.   

    谢谢各位的解答,我现在已经有怎么做的概念了。to lovefootball:File.Copy能够把文件Copy到远程计算机上吗?怎么指定在远程计算机上的路径?
      

  7.   

    File.Copy(sourceFileName , destFileName , overwrite );
    sourceFileName 
    要复制的文件。 
    destFileName 
    目标文件的名称。不能是目录。 
    overwrite 
    如果可以改写目标文件,则为 true;否则为 false。 
    其中destFileName的值,就是远程机器IP加盘符加文件夹....
      

  8.   

    先使用Wmi开通连接,再Copy文件
    下面是sdk中的例子。
    using System;
    using System.Management;// This example demonstrates how to connect to remote machine
    // using supplied credentials.
    class Sample_ConnectionOptions
    {
        public static int Main(string[] args) {
            ConnectionOptions options = new ConnectionOptions();
            options.Username = UserName; //could be in domain\user format
            options.Password = SecurelyStoredPassword;
            ManagementScope scope = new ManagementScope(
                "\\\\servername\\root\\cimv2",
                options);
            try {
                scope.Connect();
                ManagementObject disk = new ManagementObject(
                    scope,
                    new ManagementPath("Win32_logicaldisk='c:'"),
                    null);
                disk.Get();
            }
            catch (Exception e) {
                Console.WriteLine("Failed to connect: " + e.Message);
            }
            return 0;
        }
    }