Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


create quick scheduled task

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> Post a VBScript >> create quick scheduled task
  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 >>
 create quick scheduled task - 12/6/2005 9:14:00 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
created this so I dont have to stay after hours to manually run a script
it creates a one time job for tonight at 6pm. edit however you wish schedule-wise


      

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site
 
 
Post #: 1
 
 RE: create quick scheduled task - 12/6/2005 9:15:05 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
just a note, youll have to run this with cscript (you do have that set as your default scripting host right?)

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to kirrilian)
 
 
Post #: 2
 
 RE: create quick scheduled task - 12/7/2005 2:16:03 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
What kind of a crazy person wouldn't. I'd be forever clicking message boxes otherwise. :)

_____________________________

"... 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 kirrilian)
 
 
Post #: 3
 
 RE: create quick scheduled task - 12/7/2005 5:05:05 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
one of my co-workers, even after suggesting he should (a few times...) so i sent him a script that iterated all the files on his file system (gotta love wmi!!)
needless to say, he didnt think to just kill the process... (not that i havent ever done this to myself lol)

yes im evil, but im ok with it

another note on the script above, the path to the executable cant have any spaces in it

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to ebgreen)
 
 
Post #: 4
 
 RE: create quick scheduled task - 7/4/2007 10:00:56 PM   
  aru1683

 

Posts: 20
Score: 0
Joined: 7/1/2007
From: India
Status: offline
I am getting error code as 1

(in reply to kirrilian)
 
 
Post #: 5
 
 RE: create quick scheduled task - 7/4/2007 10:07:34 PM   
  aru1683

 

Posts: 20
Score: 0
Joined: 7/1/2007
From: India
Status: offline
This is my code kindly correct it pls..

Dim password

WScript.echo "Make sure you've copied over the deployment data!"
Set objPassword = CreateObject("ScriptPW.Password")
'secure way to enter your password into the script
'neat huh?
WScript.echo "Please enter your password:"
'password = objPassword.GetPassword()
password=inputbox("Password pls")
chkSched()

Sub chkSched()
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set WshShell = WScript.CreateObject("WScript.Shell")
   
    'checks for pre-existing job
    If not fso.fileExists("C:\SYSROOT\Tasks\date.job") then
        'creates it if it doesnt exist
        runDate = setFileDate()
        WScript.Echo runDate
        schedule = "SCHTASKS /Create /SC once /TN date /TR ""C:\Documents and Settings\Arumugam_n\Desktop\vb scrpits\date.vbs""/ST 04:45:00PM /RU INFBOA\Arumugam_n /RP " & password & ""
        return = WshShell.Run(schedule, 1, True)
        'WScript.echo schedule

        If return = 0 Then
            WScript.Echo "the task was successfully created"
        Else
            WScript.Echo "there were problems creating the task"
     wscript.echo "Error Code was " &return
        End If
    Else
        WScript.Echo "Job already exists"
        'delete previous tast
        fso.DeleteFile "C:\SYSROOT\Tasks\date.job",True
        'rerun task creation
        chkSched()
    End If
End Sub

Function setFileDate()
   theyear = DatePart("yyyy", Date())
   themo = DatePart("m", Date())
   'check for length, pad zero if needed
   if len(themo) < 2 then themo = "0" & themo end if
   theday = DatePart("d", Date())
   'check for length, pad zero if needed
   if len(theday) < 2 then theday = "0" & theday
   setFileDate = themo & "/" & theday & "/" & theyear
End Function 'setFileDate

Function GetPassword()
password=Inputbox("Type your password")
End Function

(in reply to aru1683)
 
 
Post #: 6
 
 RE: create quick scheduled task - 7/4/2007 11:24:46 PM   
  gdewrance


Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
you cant just type sysroot and expect the computer to know what you want. If you type sysroot in Start run you will also get an error.
You will need to do somthing like this

Dim WshEnv : Set WshEnv = WshShell.Environment("Process")

SysRoot = WshEnv("%SystemRoot%")

If not fso.fileExists(SysRoot & "\Tasks\date.job") then

(in reply to aru1683)
 
 
Post #: 7
 
 RE: create quick scheduled task - 7/5/2007 12:25:24 AM   
  aru1683

 

Posts: 20
Score: 0
Joined: 7/1/2007
From: India
Status: offline
Hi thanks for the reply. i have changed the code as per ur suggestion. but still it was giving the error code of 1.( which means request not supported) kindly resolve this plzzzzzzzzz..

Dim password
Dim WshEnv

Set objPassword = CreateObject("ScriptPW.Password")
WScript.echo "Please enter your password:"

password=inputbox("Password pls")
chkSched()

Sub chkSched()
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set WshShell = WScript.CreateObject("WScript.Shell")
      Set WshEnv = WshShell.Environment("Process")
SysRoot = WshEnv("%SystemRoot%")
   
    'checks for pre-existing job
    If not fso.fileExists(SysRoot & "\Tasks\date.job") then
        'creates it if it doesnt exist
        runDate = setFileDate()
        WScript.Echo runDate
        schedule = "SCHTASKS /Create /SC once /TN date.job /TR ""C:\Documents and Settings\Arumugam_n\Desktop\vb scrpits\date.vbs""/ST 04:45:00PM /RU INFBOA\Arumugam_n /RP " & password & ""
        return = WshShell.Run(schedule, 1, True)
        'WScript.echo schedule

        If return = 0 Then
            WScript.Echo "the task was successfully created"
        Else
            WScript.Echo "there were problems creating the task"
     wscript.echo "Error Code was " &return
        End If
    Else
        WScript.Echo "Job already exists"
        'delete previous tast
        fso.DeleteFile "C:\SYSROOT\Tasks\date.job",True
        'rerun task creation
        chkSched()
    End If
End Sub

Function setFileDate()
   theyear = DatePart("yyyy", Date())
   themo = DatePart("m", Date())
   'check for length, pad zero if needed
   if len(themo) < 2 then themo = "0" & themo end if
   theday = DatePart("d", Date())
   'check for length, pad zero if needed
   if len(theday) < 2 then theday = "0" & theday
   setFileDate = themo & "/" & theday & "/" & theyear
End Function 'setFileDate



(in reply to gdewrance)
 
 
Post #: 8
 
 RE: create quick scheduled task - 7/5/2007 2:56:45 AM   
  DiGiTAL.SkReAM


Posts: 1139
Score: 6
Joined: 9/6/2005
From: Florida, USA
Status: offline
Two of the most common methods for getting the value of environment variables are:
1)

      

and 2)

      

As you can see if you look closely, when you use the ExpandEnvironmentStrings() method, you need to wrap the variable name in %'s like this: %SYSTEMROOT%
However, when you use the oEnv() method, you need to NOT wrap the variable name in %'s like this: SYSTEMROOT

The two methods work the same, but the ExpandEnvironmentStrings method has access to one or two more variables than oEnv does.  Go figure.

_____________________________

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury

(in reply to aru1683)
 
 
Post #: 9
 
 RE: create quick scheduled task - 7/5/2007 5:06:47 PM   
  aru1683

 

Posts: 20
Score: 0
Joined: 7/1/2007
From: India
Status: offline
can anybody correct my above code and make it to work..
am stuck up in this for a long time.. its screwing up my head..

pls don mistake me.

(in reply to DiGiTAL.SkReAM)
 
 
Post #: 10
 
 RE: create quick scheduled task - 7/5/2007 11:17:33 PM   
  gdewrance


Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
I have used the following in the past

Set WshShell = CreateObject("WScript.Shell")
Set WshEnv = WshShell.Environment("Process")

SysDrive = WshEnv("SYSTEMDRIVE")
SysRoot = WshEnv("SYSTEMROOT")
SysUsers = WshEnv("USERNAME")
LogonSvr = WshEnv("LOGONSERVER")


Would this be correct based on your first example below

I see this method does not set WshShell.Environment("Process") is that the only difference
Set WshShell = CreateObject("Wscript.Shell")
SysRoot = WshShell.ExpandEnvironmentStrings("%SYSTEMROOT%")
SysDrive = WshShell.ExpandEnvironmentStrings("%SYSTEMDRIVE%")
SysUsers = WshShell.ExpandEnvironmentStrings("%USERNAME%")
LogonSvr = WshShell.ExpandEnvironmentStrings("%LOGONSERVER%")

(in reply to DiGiTAL.SkReAM)
 
 
Post #: 11
 
 RE: create quick scheduled task - 7/5/2007 11:54:52 PM   
  aru1683

 

Posts: 20
Score: 0
Joined: 7/1/2007
From: India
Status: offline
thanks but where should i change it in my code.

am running this script on my local machine which also needs user name and password to schedule a task.

can u correct my code and post it again. don mistake i have been learning vb script just week since..

(in reply to gdewrance)
 
 
Post #: 12
 
 RE: create quick scheduled task - 7/6/2007 12:12:24 AM   
  gdewrance


Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
There was a problem with passing the password part of the script, the following works.


      

(in reply to aru1683)
 
 
Post #: 13
 
 RE: create quick scheduled task - 7/6/2007 12:27:36 AM   
  gdewrance


Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
If you still want the inputbox then use the code below, personally I would create the script with the password in it and just encode the script to vbe, my users have no clue what scripts are anyway or where to find them

Password = InputBox ("Please enter your password:")

(in reply to aru1683)
 
 
Post #: 14
 
 RE: create quick scheduled task - 7/6/2007 12:36:51 AM   
  aru1683

 

Posts: 20
Score: 0
Joined: 7/1/2007
From: India
Status: offline
I really thankful to you my friend.. it worked fine.. I don have any words how to thank u. any how good work done by u.. great applauds man...


I really proud of being in this community. thanks guys...

(in reply to gdewrance)
 
 
Post #: 15
 
 RE: create quick scheduled task - 7/11/2007 2:53:32 PM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
sorry i havent been on the board much to help, thanks for helping guys

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to aru1683)
 
 
Post #: 16
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Post a VBScript >> create quick scheduled task 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