Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

creating a batch script to create a scedualed task to be used on multiple pc's


  • Please log in to reply
13 replies to this topic

#1 Joeykong

Joeykong

  • Members
  • 24 posts
  • OFFLINE
  •  
  • Local time:03:59 PM

Posted 19 December 2015 - 12:36 PM

so im an IT specialist at a big car dealer ship im not that good with scripting but what i want to do is when i go around to a computer i want to be able to put a flash drive in run a batch script that creates a folder on the C drive transfers a few files (xml and .bat ) to that folder then from that folder i want to run the batch script that will create a scheduled task to run ccleaner when the pc is in idle for 10 min 
we have 600+ pc's some are on the domain some are off the domain with various user names/passwords and pc names also different os's (xp win 7 and some vista) some are 32 bit but most are 64 bit


ok so i made a scheduled task on my pc then exported the XML i put the files on a flash drive then i made a batch to copy the other batch scripts/xml's to a folder on the c drive (that part im having no issue with )only issue i have is when i try to run the batch to make the task on a different pc then the one i created it on i get a message saying "error: no mapping between account names and security ID's was done <17,8>:logon type 
i plan on just popping in the flash drive and running these scripts as i go around doing the preventive maintenance or wile im on a pc to troubleshoot an issue 


here are my scripts

this one is run off the flash drive and creates a folder on the c drive i have no issues with that but im posting it just as a reference 

@echo off
REM Check if 32 or 64-bit OS
if "%Processor_Architecture%"=="" goto oscheck
if "%Processor_Architecture%"=="x86" goto x86
if "%Processor_Architecture%"=="AMD64" goto x64

:x64
mkdir c:\autocleaner
copy createtask64bit.bat c:\autocleaner\
copy createtask32bit.bat c:\autocleaner\
copy autoclean32bit.xml c:\autocleaner\
copy ccleaner64.xml c:\autocleaner\
echo Everything was copied to \autocleaner to be installed
eject
pause
exit



after that i go to the autocleaner folder on the c drive and then run the other script either the 32 bit or 64 bit depending on the pc 
both scripts are the same only diffence is what xml file it points to 


schtasks /create /tn "ccleaner64" /xml "c:\autocleaner\ccleaner64.xml"
PAUSE

any suggestions ? id also like to be able to do this from one of our network drives

i can also attach the scrips and xml files if needed

thank you



BC AdBot (Login to Remove)

 


#2 KingDavidlll

KingDavidlll

  • Members
  • 297 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:12:59 AM

Posted 19 December 2015 - 09:04 PM

This is due to the fact that the scheduler saves which user to run it as, and as each computer doesn't have the same computer name and user, it will not be able to import correctly.

 

To easily fix this, you can change the UserId in the XML file to be System.

    <Principal id="Author">
      <UserId>System</UserId>
      <LogonType>InteractiveToken</LogonType>
      <RunLevel>LeastPrivilege</RunLevel>
    </Principal>

Edited by KingDavidlll, 19 December 2015 - 09:05 PM.


#3 Joeykong

Joeykong
  • Topic Starter

  • Members
  • 24 posts
  • OFFLINE
  •  
  • Local time:03:59 PM

Posted 21 December 2015 - 10:34 AM

this is what i have now and i get access is denied when i try it do i also need to change 

were it says dell-pc\dell      i tried changing that and got access denied still do i need to run as admin ?

 

<?xml version="1.0" encoding="UTF-16"?>
  <RegistrationInfo>
    <Date>2015-12-18T17:33:15.4032656</Date>
    <Author>DELL-PC\DELL</Author>
  </RegistrationInfo>
  <Triggers>
    <IdleTrigger>
      <Enabled>true</Enabled>
    </IdleTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>System</UserId>
      <LogonType>InteractiveToken</LogonType>
      <RunLevel>LeastPrivilege</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <Duration>PT10M</Duration>
      <WaitTimeout>PT1H</WaitTimeout>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>true</RunOnlyIfIdle>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>P3D</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>"C:\Program Files\CCleaner\CCleaner64.exe"</Command>
      <Arguments>/AUTO</Arguments>
    </Exec>
  </Actions>
</Task>


#4 Joeykong

Joeykong
  • Topic Starter

  • Members
  • 24 posts
  • OFFLINE
  •  
  • Local time:03:59 PM

Posted 21 December 2015 - 10:40 AM

nvm i got it working ! by running as admin ! thank you this is going to make me and my co workers life so much easier !!

 

i dont think its possible but is there any way to make the most recent malware byes free edition run automatically i did research on this a month or 2 ago and found that there is nothing in the program file to set the task to i can make a task that will cause the program to open but not update and scan 

 

 

either way thank you !



#5 KingDavidlll

KingDavidlll

  • Members
  • 297 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:12:59 AM

Posted 27 December 2015 - 06:20 PM

Unfortunately you'll have to purchase a full copy for that as programming something to do that would essentially be in my eyes pirating.  No problem, feel free to post again if you have any more problems!



#6 Joeykong

Joeykong
  • Topic Starter

  • Members
  • 24 posts
  • OFFLINE
  •  
  • Local time:03:59 PM

Posted 29 December 2015 - 12:48 PM

that what i thought so upon looking into this more i realized the tasks is being created now but if i go into task scheduler and hit run on the task it says running but i dont get a little icon by the time showing ccleaner is running/cleaning

 

if i manually create the task then run it it shows the little icon in the bottom saying ccleaner is cleaning but the pc's that i use the script to create the task if i hit run on the task i dont get the icon

not sure if that means its not running or not

any other suggestions  



#7 KingDavidlll

KingDavidlll

  • Members
  • 297 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:12:59 AM

Posted 30 December 2015 - 03:47 AM

Check the task scheduler to see when the task last run.  Another way would be to put something in the recycle bin and see if it gets deleted.



#8 Joeykong

Joeykong
  • Topic Starter

  • Members
  • 24 posts
  • OFFLINE
  •  
  • Local time:03:59 PM

Posted 31 December 2015 - 01:09 PM

thats the strange thing it says it's running and that it ran successfully but i dont think the program is actually running i tried the recycle bin thing and it didnt delete it so i guess the task is being created fine but it dosent actually run  

i tested this on a vista machine and it has been saying the task is running for like 10 hours or more 



#9 KingDavidlll

KingDavidlll

  • Members
  • 297 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:12:59 AM

Posted 01 January 2016 - 01:33 AM

Try just run the "C:\Program Files\CCleaner\CCleaner64.exe" /auto in cmd and see if that works



#10 Joeykong

Joeykong
  • Topic Starter

  • Members
  • 24 posts
  • OFFLINE
  •  
  • Local time:03:59 PM

Posted 06 January 2016 - 01:31 PM

 "C:\Program Files\CCleaner\CCleaner64.exe"/auto worked on 2 pc's

so what should i do now

 

im guessing id have to make a script to make a task to run another script ? 



#11 KingDavidlll

KingDavidlll

  • Members
  • 297 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:12:59 AM

Posted 06 January 2016 - 11:21 PM

So once you run the batch script on a computer, can you make the event manually on that computer and see if it runs correctly?



#12 Joeykong

Joeykong
  • Topic Starter

  • Members
  • 24 posts
  • OFFLINE
  •  
  • Local time:03:59 PM

Posted 07 January 2016 - 12:16 PM

what batch script ? the 1st one i run is to just copy the files from my flash drive to the pc's local drive and that works fine 

the 2nd one creates the task and that works but i think the task its self is the issue 

and  yes i can make the task manually and it will run 

but the whole reason i wanted to do it with a script is because its much faster  this way i can just go to a pc when someone calls about any type of issue(site issue email issue ect) or when we are prepping a new pc for deployment  i can just pop my flash drive in a run those scripts this way ccleaner runs automatically this way the computers stay fast and run good and we dont get as many calls about slow pc's

 

thank you



#13 KingDavidlll

KingDavidlll

  • Members
  • 297 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:12:59 AM

Posted 08 January 2016 - 02:53 AM

I haven't run into this problem before to be honest.  The next thing to do in my opinion after you've checked running the first script to install cccleaner and then manually create the task is to:

  1. After creating the task manually, export it again, delete the task, then try to create the task through the commandline and see if it runs
  2. If that runs, do the same thing on a different computer, manually create the task, export it, delete it, change the exported UserId to system and import it and see if it runs.


#14 Joeykong

Joeykong
  • Topic Starter

  • Members
  • 24 posts
  • OFFLINE
  •  
  • Local time:03:59 PM

Posted 01 October 2016 - 01:07 PM

i realized i never replied i found out how to fix this 

 

make one script with this in there(note you might need to type it in manualy )

@echo off
cd C:\Program Files\CCleaner\CCleaner.exe
start CCleaner.exe /AUTO
exit
 
save it as what ever you want 
 
then make this script 
 
Schtasks /create /SC DAILY /TN "this will be the name of the task" /TR "map the location were you saved the 1st script ..ex c:\matiance\ccleaner.bat" /ST 09:00
pause

 

 

so what will happen is it will create a tasks to run the ccleaner script every day at 9:00 am (to change the time just change the ST 09:00  to what ever time you want note this uses 24hr time ..just google a conversion )

 

 

if anyone has any questions let me know 

 

thank you 






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users