/build/static/layout/Breadcrumb_cap_w.png

Schedule Custom Script/Exe

I have found and modified a couple of VBS scripts that will copy and then run files remotely. I have attempted to 'Task Schedule' one of the scripts but it fails every time. I found the VBS2exe.com site and converted them to exe's but they still dont run through the Scheduler.

I have read that XP blocks 'unsafe' executables and that an ActiveX code may be needed to allow this to be run.

Can someone please help this newbe?

Here is one of my scripts I want to schedule for setting up a default printer:

----------------
Set WSHNetwork = CreateObject("WScript.Network")
WSHNetwork.SetDefaultPrinter "Printer1"
----------------

I know I could put the .exe or .VBS in the start menu to run in the background once the user logs in but do'nt want to do that.

0 Comments   [ + ] Show comments

Answers (4)

Posted by: ds0934 15 years ago
Orange Senior Belt
0
If it's setting a default printer, it should be executed within the context of the logged on user. The best/easiest way to accomplish that is using a login script.
Posted by: Eddieduce@yahoo.com 15 years ago
Senior Yellow Belt
0
I have this script that I use to login and transfer files through the network but I can not seem to merge the bottom script to the top one.

'===========================
file1 = "C:\hostname.txt"
file2 = "C:\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)

' Attempt to map a drive
' ----------------------
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
Err.Clear()

Else ' ---> Start copying files process.
txtStreamOut.WriteLine("Managed to map to " & Hostname)

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

'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'This is where I attempted to merge the bottom script (I deleted my attempt).
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

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

net.RemoveNetworkDrive "H:", "True", "True"
If Err.Number <> 0 Then
txtStreamOut.WriteLine("Err# " & Err.Number & " - " & Err.Description)
Err.Clear()

Else
txtStreamOut.WriteLine("Successful upmap from " & Hostname & ".")
End if
End if

txtStreamOut.WriteLine("Ended connection(s) to host(s).")

Loop
End If

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

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

txtStreamOut.WriteLine("End of Log file at " & DateTimeNow)

'<End of script.>


'///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'Second Script.
'//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

'<Start of Script>

' Succesfull in setting scheduled task locally
' Failed to connect remotely.
strComputer = "." 'Connects to specified computer.
strCommand = "dflt_PHON.EXE" 'Opens specified file from OS root.

Const INTERVAL = "n"
Const MINUTES = 1

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objScheduledJob = objWMIService.Get("Win32_ScheduledJob")
Set objSWbemDateTime = CreateObject("WbemScripting.SWbemDateTime")

objSWbemDateTime.SetVarDate(DateAdd(INTERVAL, MINUTES, Now()))
errReturn = objScheduledJob.Create(strCommand, objSWbemDateTime.Value, False, 0, 0, True, intJobID)


If errReturn = 0 Then
Wscript.Echo "notepad.exe was started with a process ID: " & intJobID
Else
Wscript.Echo "notepad.exe could not be started due to error: " & errReturn
End If
'<End of script.>
'===========================
Posted by: Eddieduce@yahoo.com 15 years ago
Senior Yellow Belt
0
I was able to figure out the way to put the script in the start folder for user accounts to change the default printer.

I am now attempting to change the printer without placing the script in the start folder.

I added the code:

Set WSHNetwork = CreateObject("WScript.Network")
WSHNetwork.SetDefaultPrinter "Print1"

The problem I am having is that, even though I am already connected to the remote machine and my script changes file attributes and copies files, when it gets to this part it changes the local default printer.

What am I doing wrong?
Posted by: aogilmor 15 years ago
9th Degree Black Belt
0
check out prn????.vbs in your system folder (winxp). Lots of code to manage printers. All of the heavly lifting has already been done by the geniuses at msft :-)
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ