Windows XP Run VBS remotely

Can you help?

  • Don't Know

    Votes: 0 0.0%
  • I May

    Votes: 0 0.0%
  • Easy

    Votes: 0 0.0%

  • Total voters
    0
Joined
Jun 17, 2008
Messages
1
Reaction score
0
I have found and made this script work (which I need to improve) to run another VBS script that will change the default printer.

The way this script works is that it searches for the 'Hostname' file, whichlists all the computernames to copy to, and continues it's process.

I need to automatically run the script(Dflt_print.vbs) that is found in the folder which is copied to the network machine.

I found a script(Shown at the end), that had some information but, since I am a newby at this, I could not get it to work.

Here is the script:
================
On Error Resume Next

' Error codes
'-------------
'Error# -2147023570 - Logon failure: unknown user name or bad password.
'Error# -2147023693 - No network provider accepted the given network path.
'Error# -423 - Object required.

WScript.Echo "Start of Deploy.vbs script."
WScript.Echo "Starting connection to Hosts... "

file1 = "C:\DOSTest\remoteEx\hostname.txt"
file2 = "C:\DOSTest\remoteEx\Deploylog.txt"

TimeNow = Time
DateNow = Date
DateTimeNow = Trim(Date & " " & Time)

Set fso = CreateObject("Scripting.FileSystemObject")

If fso.FileExists(file1) Then
Set txtStream = fso.OpenTextFile(file1) ' Open text file.
Set txtStreamOut = fso.CreateTextFile(file2) ' Open output file.
txtStreamOut.WriteLine("Beginning of Log file at " & DateTimeNow)
txtStreamOut.WriteLine("Started connection to Host(s).")

Do While Not (txtStream.atEndOfStream)

' Read a hostname
' ---------------
Text = txtStream.ReadLine
Hostname = Trim(Text)
WScript.Echo "Computer Connection Retrieved " & Hostname & "."
txtStreamOut.WriteLine("Computer retrieved Successfully " & Hostname & ".")

' Attempt to map a drive
' ----------------------
WScript.Echo "Attempting to map Drive H: over the administrative share: \\" & Hostname & " ... "
txtStreamOut.WriteLine("Attempting to map Drive H: over the administrative share: \\" & Hostname & "\c$" & "...")

Dim net
Set net = CreateObject("WScript.Network")
net.MapNetworkDrive "H:", "\\" & Hostname & "\c$","True"
If Err.Number <> 0 Then
WScript.Echo "Error# " & Err.Number & " - " & Err.Description & ". "
txtStreamOut.WriteLine("Err# " & Err.Number & " - " & Err.Description)
Err.Clear()
Else ' ---> Start copying files process
WScript.Echo "Succesfully mapped to " & Hostname & "."
txtStreamOut.WriteLine("Managed to map to " & Hostname & ". ")

'Attempt to copy files
'---------------------
WScript.Echo "Attempting to copy files... "
txtStreamOut.WriteLine("Attempting to copy files...")
fso.CopyFolder "C:\netcopy", "H:\", "True" 'from specified location to destination.
WScript.Echo "Copying of Files Completed succesfully."
txtStreamOut.WriteLine("Copying Completed.")

WScript.Sleep(1000)

' Attempt to unmap drive
WScript.Echo "Attempting to unmap Drive H: from the administrative share: \\" & Hostname & "\c$" & " ... "
txtStreamOut.WriteLine("Attempting to unmap Drive H: from the administrative share: \\" & Hostname & "\c$" & "...")

net.RemoveNetworkDrive "H:", "True", "True"
If Err.Number <> 0 Then
WScript.Echo "Err# " & Err.Number & " - " & Err.Description
txtStreamOut.WriteLine("Err# " & Err.Number & " - " & Err.Description)
Err.Clear()
Else
WScript.Echo "Managed to unmap from " & Hostname & " Successfully."
txtStreamOut.WriteLine("Successful upmap from " & Hostname & ".")
End if

End if

WScript.Echo "Ended connection(s) to host(s)."
txtStreamOut.WriteLine("Ended connection(s) to host(s).")
Loop
End If

WScript.Echo "End of Deploy.vbs Script."
===============================================



Const OverwriteExisting = TRUE
Set objFSO = CreateObject("Scripting.FileSystemObject")
strComputer = "MyPC"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objNewJob = objWMIService.Get("Win32_ScheduledJob")
errJobCreated = objNewJob.Create _
("wscript.exe c:\netcopy\Dflt_LJ22PHON_Print.vbs", "********084500.000000-420", _
False, 2, , True, JobID)
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top