salvete!
在我的服务器上,我正在运行HmailServer,该服务使用本地系统帐户。
我需要将文件复制到另一台计算机。因此,我有一个脚本可以使用cmdkey.exe保存凭据,然后复制文件。
如果我自己运行此功能(在独立的VBS文件中),则在登录到服务器时可以工作,但我是管理员。但是,如果我让HmailServer服务运行此功能,则该功能运行,但总是说目的地不存在。
注意,我已经评论了凭证的删除。如果我去服务器运行cmdkey /list
,我会发现凭据永远不会设置,这意味着命令失败。这意味着凭据的第一个设置可能也失败了,这就是为什么" OBJFSO"找不到目录。
再次,如果我将所有这些都放在单独的文件中,并通过双击文件将其运行为test.vbs
,则可以使用。但是,如果我从HmailServer中使用它,它将失败。
我想这意味着HmailServer(本地系统帐户)没有设置凭据的权利?我该如何工作?
option explicit
dim SPcopyMessage
SPcopyMessage = CopyFileToRemoteMachine("SERVER", "mydomainusername", "password", "c:test2.txt", "\SERVERsomefolderotherfolder")
MsgBox SPcopyMessage
function CopyFileToRemoteMachine(whatMachine, whatUsername, whatPassword, whatSourceFile, whatDestination)
dim errormessage, CredentialCreate, CredentialDelete
errormessage = "Sharepoint Mail Delivered"
CredentialCreate = "cmd.exe /c cmdkey /add:" & whatMachine & " /user:" & whatUsername & " /pass:" & whatPassword
Dim objShell, objFSO
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
CALL objShell.Run(CredentialCreate, 0, True) 'add username to the credentials list
If objFSO.FileExists(whatSourceFile) Then
If objFSO.FolderExists(whatDestination) Then
If Right(whatDestination, 1) <> "" Then
whatDestination = whatDestination & ""
End If
objFSO.CopyFile whatSourceFile, whatDestination, True
Else
errormessage = "Destination does not exist: " & whatDestination
End If
Else
errormessage = "Source file does not exist: " & whatSourceFile
End If
'CredentialDelete = "cmd.exe /c cmdkey /delete:" & whatMachine
'CALL objShell.Run(CredentialDelete, 0, True)
set objFSO = nothing
set objShell = nothing
CopyFileToRemoteMachine = errormessage
end function
弄清楚了一种方法!首先,我确保该目的地已与Machine2上的正确用户帐户共享。然后在Machine1上制作脚本以映射网络驱动器,然后复制文件。只要N驱动器从未用于该机器上的其他任何东西,这将起作用。
这是代码是否对任何人有帮助!
function CopyFileToRemoteMachine(whatMachine, whatUsername, whatPassword, whatSourceFile, whatDestination)
dim errormessage, mdrive
errormessage = "File successfully copied"
mdrive = "N:"
Dim objFSO, objNetwork
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("Wscript.Network")
If not objFSO.FileExists(mdrive) Then
objNetwork.MapNetworkDrive mdrive, whatDestination, False, whatUsername, whatPassword
End If
If Right(whatDestination, 1) <> "" Then
whatDestination = whatDestination & ""
End If
If objFSO.FileExists(whatSourceFile) Then
If objFSO.FolderExists(whatDestination) Then
objFSO.CopyFile whatSourceFile, whatDestination, True
Else
errormessage = "Destination does not exist: " & whatDestination
End If
Else
errormessage = "Source file does not exist: " & whatSourceFile
End If
objNetwork.RemoveNetworkDrive mdrive,TRUE,TRUE
set objFSO = nothing
set objNetwork = nothing
CopyFileToRemoteMachine = errormessage
end function