Login | |
|
 |
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
|
|
| |
|
|
|
| |
|
|
 |
|
 |
|
|