Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Schedule Custom Script/Exe

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,61750
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Schedule Custom Script/Exe
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Schedule Custom Script/Exe - 6/23/2008 9:59:49 AM   
  Eddieduce

 

Posts: 15
Score: 0
Joined: 6/17/2008
Status: offline
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 my VBS files to exe's but they still don't 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.
 
 
Post #: 1
 
 RE: Schedule Custom Script/Exe - 6/23/2008 11:59:54 PM   
  ebgreen


Posts: 5041
Score: 31
Joined: 7/12/2005
Status: offline
This topic has been discussed many times on the forum. Have you tried searching?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Eddieduce)
 
 
Post #: 2
 
 RE: Schedule Custom Script/Exe - 6/27/2008 6:05:17 AM   
  Eddieduce

 

Posts: 15
Score: 0
Joined: 6/17/2008
Status: offline
I have but many are different and others are too advanced.

I found one that seems like a simple one. I've made it work for my LOCAL machine. 

Could someone please help me correct the problem of failed scheduling based on my second script aswell as how I would merge these two.  How do I substitute the variables.

I need to merge the smaller of course.
The scripts are separated by forward slashes:  ////

/////////////////////////////////////////////////////////////////////
FIRST SCRIPT
/////////////////////////////////////////////////////////////////////
On Error Resume Next

WScript.Echo "Start of script processes."
WScript.Echo "Starting connection to Host.... "

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 to " & Hostname & " retrieved Successfully."
       txtStreamOut.WriteLine("Computer connection to " & Hostname & " retrieved Successfully.")
  
       '' 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        'If mappingfails display message.
                  WScript.Echo "Error# " & Err.Number & " - " & Err.Description
                  txtStreamOut.WriteLine("Err# " & Err.Number & " - " & Err.Description)
                  Err.Clear()                                   

              Else                   '' --->  Start file copy process.
                  WScript.Echo "Succesfully mapped to " & Hostname & " ."
                  txtStreamOut.WriteLine("Managed to map to " & Hostname)
  
               ''Attempt to Change network file attribure [Still fails to change attributes]
               ''----------------------------------------
               'WSCRIPT.ECHO "Attempting to change remote file attributes " &_
               ' "for client " & HOSTNAME & ".... "                           
               'TXTSTREAMOUT.WRITELINE("Attempting to change remote file attributes.... ")

               'cONST ReadOnly = 1
               'CONST Hidden   = 2
          
               'CONST System   = 4

               'SET OBJFSO  = CREATEOBJECT("SCRIPTING.FILESYSTEMOBJECT")
               'SET OBJFILE = OBJFSO.GETFILE("H:\Folder1\file1")           

               'IF OBJFILE  = ATTRIBUTES AND ReadOnly THEN OBJFILE.ATTRIBUTES = OBJFILE.ATTRIBUTES XOR ReadOnly
              
                   'IF ERR.NUMBER <> 0 THEN
                       'WScript.Echo "Error# " & Err.Number & " - " & Err.Description
                       'txtStreamOut.WriteLine("Err# " & Err.Number & " - " & Err.Description)
                          'Err.Clear()

                   'WScript.Sleep(1000)
                                                          
                   'ELSE

                       'WScript.Echo "Succesfully changed file attributes for " & Hostname & " ."
                       'txtStreamOut.WriteLine("Succesfully changed file attributes for " & Hostname)

                   'END IF

               ''Attempt to copy file Set1
               ''-------------------------
               WScript.Echo "Attempting to copy file Set1.... "
               txtStreamOut.WriteLine("Attempting to copy files...")
               fso.CopyFile "C:\Folder1\File1", "H:\Folder1\File1",_
                "True"      'from specified location to destination file must NOT have an extension.
                                                          
                   IF ERR.NUMBER <> 0 THEN        ' Display message if copy fails
                       WSCRIPT.ECHO "Error# " & ERR.NUMBER & " - " & ERR.DESCRIPTION & ".  File Set1 Copying failed."
                       TXTSTREAMOUT.WRITELINE("ERR# " & ERR.NUMBER & " - " & ERR.DESCRIPTION)
                       ERR.CLEAR()

                   ELSE                'Display message if copy successful.
                       WScript.Echo "Copying of File Set1 Completed succesfully."
                       txtStreamOut.WriteLine("Copying Completed.")
                   END IF

               ''Attempt to copy file Set2
               ''-------------------------
               WScript.Echo "Attempting to copy file Set2.... "
               txtStreamOut.WriteLine("Attempting to copy files...")
               fso.CopyFolder "C:\DOSTest\RemoteEx\NetCopy", "H:\",_
                "True"      'from specified location to destination.
                                                          
                   IF ERR.NUMBER <> 0 THEN        ' Display message if copy fails
                       WSCRIPT.ECHO "Error# " & ERR.NUMBER & " - " & ERR.DESCRIPTION & ". Copying of File Set2 Failed."
                       TXTSTREAMOUT.WRITELINE("ERR# " & ERR.NUMBER & " - " & ERR.DESCRIPTION)
                       ERR.CLEAR()

                   ELSE                'Display message if copy successful.
                       WScript.Echo "Copying of File Set2 Completed succesfully."
                       txtStreamOut.WriteLine("Copying Completed.")
                   END IF

'****************************************
' THIS IS WHERE I HAVE ATTEMPTED TO PLACE THE SCHEDULED FILE EXECTION SCRIPT
'****************************************



               ''Attempt to change file attributes

           END IF

       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

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

End If

WScript.Echo "End of Script processes'."

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

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

Set fso = Nothing
Set fldr1 = Nothing
Set fldr2 = Nothing
Set net = Nothing

/////////////////////////////////////////////////////////////////////
SECOND SCRIPT
/////////////////////////////////////////////////////////////////////

'<Start of Script>

' Succesfull in setting scheduled task locally
' Failed to connect remotely.
strComputer = "."           'Connects to specified computer.
strCommand = "dflt_PHONICS.vbs"      '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.>
''=========================== 

_____________________________

Ed

(in reply to ebgreen)
 
 
Post #: 3
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Schedule Custom Script/Exe Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts