Jump to content

Fileexist on directory with no user access


Recommended Posts

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

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 - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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 - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...