pchauvin Posted June 25, 2012 Share Posted June 25, 2012 Hello, i want to create a schedule task on windows 7 with schtasks command. All works fine but i would like to check if the file of scheduled task exist or not before create it. But the directory c:\windows\system32\task is unaccessible by simple user. Is there a way to do somethink like "runas fileexist"? Thanks Link to comment Share on other sites More sharing options...
JohnOne Posted June 25, 2012 Share Posted June 25, 2012 I imagine you could run a commandline command as admin such as dir C:\Windows\System32\file.ext output will be file not found if not exist. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
water Posted June 25, 2012 Share Posted June 25, 2012 There is a " available that lets you check if a task already exists: _TaskExists My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
spudw2k Posted June 25, 2012 Share Posted June 25, 2012 I believe you can use schtasks /query as a normal user. Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX BuilderMisc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose ArrayProjects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalcCool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
pchauvin Posted June 26, 2012 Author Share Posted June 26, 2012 Thank at all, JohnOne and spudw2k: ok for "dir" or "schtasks /query" in auto-it but how to capture the result of this command in the au3 script? The runas command return the PID of the process, evenif the dir or schtasks /query command return a message like "task or directory doesn't exist"..... water: i don't know how to use this UDF to call the _TaskExists function in my au3 script thanks Link to comment Share on other sites More sharing options...
JohnOne Posted June 26, 2012 Share Posted June 26, 2012 Look at help file example for StdoutRead() AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
water Posted June 26, 2012 Share Posted June 26, 2012 water: i don't know how to use this UDF to call the _TaskExists function in my au3 scriptDownload the UDF from the link I posted above and include it into your script. Call function _TaskExistsIf _TaskExists("Taskname") Then MsgBox(0, "", "Task exists") Else MsgBox(0, "", "Task does not exist") EndIf My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
pchauvin Posted June 26, 2012 Author Share Posted June 26, 2012 Water, there is a problem: simple user can't view the sheduled task and the function return none ("task does not exist") Is there a way to execute this function with admin right? Link to comment Share on other sites More sharing options...
water Posted June 26, 2012 Share Posted June 26, 2012 I haven't used any of the function of the Task Scheduler UDF myself. So I can't give you any insight information. Please check the download link I provided and see if you can find anything relevant on this thread. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
JohnOne Posted June 26, 2012 Share Posted June 26, 2012 This works for me, just remember to use the same filename in the rename line. #include <Constants.au3> $out = '' $pid = RunAs('user',@ComputerName,'pass',0,@ComSpec & ' /c rename C:\Windows\System32\file.ext file.ext',@ScriptDir,@SW_HIDE,$STDERR_MERGED) While ProcessExists($pid) $out &= StdoutRead($pid) WEnd If Not StringInStr($out,'cannot find the file') Then MsgBox(0,'YAY!','File Exists') Else MsgBox(0,'BOOOO!','File Not Exists') EndIf AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
pchauvin Posted June 27, 2012 Author Share Posted June 27, 2012 (edited) Great! it work! Thank you JohnOne, and water. here is my script: #include <Constants.au3> $Password="" Local $Pid = RunAs([User],[Domain],$Password,0,'schtasks /query /TN "Arrêt ordinateur"', @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) $out ="" While ProcessExists($pid) $out &= StdoutRead($pid) WEnd if Not StringInStr ($out, "Arr^t ordinateur") then RunAs([User],[Domain],$Password,0,'schtasks /create /SC "WEEKLY" /D FRI /ST 23:59:00 /TN "Arrêt ordinateur" /TR [program's name to run] /RU "SYSTEM" /F') Edited June 27, 2012 by pchauvin Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now