Hi ALL,
This realates to vb script code to append a file in C Drive in a remote machine accessed from a machine in different domain. I am able to successfully connect to the machine, but the file entry is not successful. I am Placing the snippet here.. Plz let me know.
On Error Resume Next
COnst ForAppending = 8
Set filesys = CreateObject("Scripting.FileSystemObject")
Set readfile = filesys.OpenTextFile("machine.txt", 1, false) ' For Reading
Do Until readfile.AtEndOfStream
MachineName = readfile.ReadLine
msgbox MachineName
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
strdomain = "test"
Set objSWbemServices = objSWbemLocator.ConnectServer(MachineName, "root\cimv2", "vvv", "ssss","MS_409","ntlmdomain:" +strdomain)
msgbox Err.number
If Err.number = 0 Then 'If remote connectivity is successful
Set objFSO = CreateObject("Scripting.FileSystemObject")
filePath = "\\" & MachineName & "\\C$\WINDOWS\system32\drivers\etc\hosts"
Set objFile = objFSO.OpenTextFile(filePath, ForAppending, True)
objFile.WriteLine "192.81.255.255"
objFile.Close
Else 'If error connecting to Remote Host/Registry
WScript.Echo "Error connecting to the Remote Host/Registry on : " & MachineName
End If
Loop
readfile.Close
MsgBox "Script has been successfully executed.."
It says logon failure at line 16.
Error code was zero, hence the connection is successful.
But I donno why is it not taking the file path C$..when the user credentials look fine too.
Kindly advice me through this.