Jump to content
Sign in to follow this  
pchauvin

Fileexist on directory with no user access

Recommended Posts

pchauvin

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

Share this post


Link to post
Share on other sites
water

There is a " available that lets you check if a task already exists: _TaskExists


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
spudw2k
pchauvin

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

Share this post


Link to post
Share on other sites
water

water: i don't know how to use this UDF to call the _TaskExists function in my au3 script

Download the UDF from the link I posted above and include it into your script.

Call function _TaskExists

If _TaskExists("Taskname") Then
    MsgBox(0, "", "Task exists")
Else
    MsgBox(0, "", "Task does not exist")
EndIf

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
pchauvin

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?

Share this post


Link to post
Share on other sites
water

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 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
JohnOne

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.

Share this post


Link to post
Share on other sites
pchauvin

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 by pchauvin

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×