Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.clipper.visual-objects > #7698
| From | "Marc Verkade [MITCon]" <marc@mitNOSPAMconDELETE.nl> |
|---|---|
| Newsgroups | comp.lang.clipper.visual-objects |
| References | <a136e26a-20fc-4b73-8da7-41e949a70e80@googlegroups.com> |
| Subject | Re: Create instance of task scheduler |
| Message-ID | <FbNxw.51473$B_1.942@fe30.am1> (permalink) |
| Organization | Sunny Usenet - Affordable Usenet |
| Date | 2015-01-27 15:23 +0100 |
Hai,
Here a function we use to restart a service when we notice that the app
itself is hanging...
Note that SCHTasks.exe only accepts parameter names in specific languages.
This code contains Dutch parameters, Google for more info.
Regards, Marc
// Add a schedule task
sTime :=Left(Time(),8)
nHours :=Val(SubStr(sTime,1,2))
nMinutes:=Val(SubStr(sTime,4,2))
DO CASE
CASE Empty(sUser)
DebOut32(String2Psz("No UserName for creating SCHTASKS task!"))
CASE Empty(sPass)
DebOut32(String2Psz("No Password for creating SCHTASKS task!"))
OTHERWISE
DebOut32(String2Psz("Create Windows Task Planner..."))
// Set the time and path parameters
sTime:=MC_StringMerge2("%1:%2:00",StrZero(nHours,2,0),StrZero(nMinutes,2,0))
// Like string.Format
sPath:=Upper(Universe:Filespec:Drivepath) // Set the path of the program
to be executed
sPath:=StrTran(sPath,"PROGRAM FILES","PROGRA~1") // Strip spaces (or use
quotes)
// Add the task to the scheduler
TaskAdd(sUser,sPass,DWSCHTASKS_SC_ONCE,sTime,"UpdateCashIt-"+sTime,sPath+"Bake-itUpdate.exe
"+sPar)
END
// Function to add a task to the Windows Scheduler
FUNCTION TaskAdd(cUserName AS STRING,cUserPassword AS STRING,dwSchema AS
DWORD,sExtraScheme AS STRING,cTaskName AS STRING,cCommandLine AS STRING) AS
LOGIC PASCAL
LOCAL cParameters AS STRING
LOCAL cSchema AS STRING
LOCAL lRetValue AS LOGIC
// Parameters
cParameters:="/Create"
cParameters+=" /RU "+cUserName
cParameters+=" /RP "+cUserPassword
DO CASE
CASE dwSchema==DWSCHTASKS_SC_DAILY
cSchema:="Dagelijks"
// ST = "HH:MM:SS"
cParameters+=" /SC "+cSchema
cParameters+=" /ST "+sExtraScheme
CASE dwSchema==DWSCHTASKS_SC_MINUTE
cSchema:="Minuut"
// MO = 1 - 1439
cParameters+=" /SC "+cSchema
cParameters+=" /MO "+sExtraScheme
CASE dwSchema==DWSCHTASKS_SC_EVERY_HOUR
cSchema:="Elk uur"
// MO = 1 - 23
cParameters+=" /SC "+cSchema
cParameters+=" /MO "+sExtraScheme
CASE dwSchema==DWSCHTASKS_SC_WEEKLY
cSchema:="Wekelijks"
// MO = 1 - 52
// MLV Missing /ST!
cParameters+=" /SC "+cSchema
cParameters+=" /MO "+sExtraScheme
CASE dwSchema==DWSCHTASKS_SC_MONTHLY
cSchema:="Maandelijks" // Daily
// /MO = 1 - 12
// /D = Day
// /ST = Time
// /M = Month
cParameters+=" /SC "+cSchema
cParameters+=" /MO "+sExtraScheme
CASE dwSchema==DWSCHTASKS_SC_ONCE
cSchema:='"Eén keer"'
// ST = "HH:MM:SS"
cParameters+=" /SC "+cSchema
cParameters+=" /ST "+sExtraScheme
CASE dwSchema==DWSCHTASKS_SC_STARTUP
cSchema:='"Bij opstarten"'
// No options
cParameters+=" /SC "+cSchema
CASE dwSchema==DWSCHTASKS_SC_LOGIN
cSchema:='"Bij aanmelden"'
// No options
cParameters+=" /SC "+cSchema
CASE dwSchema==DWSCHTASKS_SC_NOT_ACTIVE
cSchema:='"BIJ NIET-ACTIEF"'
// No options
cParameters:=cParameters + " /SC "+cSchema
OTHERWISE
// Other constants have to be defined.
// NOTE: The dutch version OF SCHTASKS.EXE only recognizes dutch
words here!
// Maybe other localized versions only accepts words on the
respective language!?
ENDCASE
// Clean he commandline
cTaskName:=StrTran(cTaskName,">","")
cTaskName:=StrTran(cTaskName,"<","")
cTaskName:=StrTran(cTaskName,",","")
cTaskName:=StrTran(cTaskName,":","")
cTaskName:=StrTran(cTaskName,";","")
cTaskName:=StrTran(cTaskName,"|","")
cTaskName:=StrTran(cTaskName,"/","")
cTaskName:=StrTran(cTaskName,"\","")
// Task
cParameters+=" /TN "+cTaskName
cParameters+=' /TR "'+cCommandLine+'"'
// Sample : cParameters:="/Create /RU Domain\User /RP Pass /SC Dagelijks
/ST 18:00:00 /TN Programatically_created_task /TR
c:\windows\system32\notepad.exe"
lRetValue:=MC_RunSafe("","SCHTASKS.EXE",cParameters)
RETURN lRetValue
// RunSafe to execute Windows apps / terminal
Function MC_RunSafe(sPath,sFile,sOptions)
LOCAL SEInfo AS _WinShellExecuteInfo
LOCAL hProc AS PTR
LOCAL lpExitCode AS DWORD
LOCAL lRunning AS LOGIC
LOCAL lRetVal AS LOGIC
SEInfo :=MemAlloc(_SIZEOF(_WINShellExecuteInfo))
SEInfo.cbSize :=_SIZEOF(_WINShellExecuteInfo)
SEInfo.fMask :=SEE_MASK_NOCLOSEPROCESS + SEE_MASK_FLAG_NO_UI
SEInfo.Hwnd :=NULL_PTR
SEInfo.lpVerb :=PSZ(_CAST,"open")
SEInfo.lpFile :=PSZ(_CAST, sFile)
SEInfo.lpParameters :=PSZ(_CAST, sOptions)
SEInfo.lpDirectory :=String2Psz(sPath)
SEInfo.nShow :=SW_HIDE
SEInfo.hInstApp :=NULL_PTR
SEInfo.lpClass :=NULL_PSZ
IF ShellExecuteEx(SEInfo) // File executed correctly
hProc:=SEInfo.hProcess
GetExitCodeProcess(hProc,@lpExitCode)
lRunning:=(lpExitCode=STILL_ACTIVE)
DO WHILE lRunning // Wait until finishes
GetExitCodeProcess( hProc, @lpExitCode )
lRunning:=(lpExitCode=STILL_ACTIVE)
Sleep(1000)
ENDDO
CloseHandle(SEInfo.hProcess)
MemFree(SEInfo)
lRetVal:=TRUE
// File was executed and the execution finished
ELSE
// An error occured (use GetLastError() to see what happened)
MemFree(SEInfo)
lRetVal:=FALSE
ENDIF
RETURN lRetVal
schreef in bericht
news:a136e26a-20fc-4b73-8da7-41e949a70e80@googlegroups.com...
How do I create an instance of Windows' taskScheduler ?
Thanks
Henry
schreef in bericht
news:a136e26a-20fc-4b73-8da7-41e949a70e80@googlegroups.com...
How do I create an instance of Windows' taskScheduler ?
Thanks
Henry
Back to comp.lang.clipper.visual-objects | Previous | Next — Previous in thread | Find similar | Unroll thread
Create instance of task scheduler H_Fidler@yahoo.com - 2015-01-27 05:42 -0800 Re: Create instance of task scheduler "Marc Verkade [MITCon]" <marc@mitNOSPAMconDELETE.nl> - 2015-01-27 15:23 +0100
csiph-web