How To Automatically run a powershell cmd on a specific folder on windows 10 start up after a delay (30s) - node.js

We are using web project unfinished, and everytime the computer start, we need to go to:
c:/wamp64/www/
In this folder we have a folder "projectname", we have to shift right click , and open powershell windows here.
then we have in the terminal: PS C:\wamp64\www\projectname> (and here we have to write "node server.js") and enter.
This have to be done once wamp is open, this is the reason of the delay.
How can we do that automatically at windows start up after 30s ? that way we won't have to do that every time we reboot a computer.
thank you for your help

I would use the task scheduler for that purpose.
Open Task Scheduler by pressing “Windows+R” and then typing “taskschd.msc” in the window that opens. Then take the following steps:
Click “Create a task” and enter a name and description for the new task. To run the program with administrator privileges, check the “Run with the highest privileges” box.
Switch to the Triggers tab and click the “New…” button. Here you can specify the conditions that trigger the task to be executed. For example, you can have it executed on schedule, at logon, on idle, at startup or whenever a particular event occurs.
Choose At log on then set it to run for Any user and set the delay to 30 seconds
Navigate to the “Actions” tab, and click “New…”.
To schedule the PowerShell script, specify the following parameters:
Action: Start a program
Program\script: powershell
Add arguments (optional): -File [Specify the file path to the script here]
References
How to automate powershell scripts with task scheduler

Related

Powershell scripts going to sleep

I have a powershell script which loops over each file in a folder and does a lot of "high-computation" tasks on each of these files. I have multiple instances of this script running on my system.
I do use a write-host before starting each of these tasks to see when these tasks start and end.
I started these instances of the script last night and when I came today morning I noticed that some of my powershell terminal were stuck at a write-host command and when I pressed ENTER they wrote that content to terminal and continued the preocessing.
It looks like some of these terminals go to sleep. Why am i seeing this and how can i prevent this?
Disable the "QuickEdit" option in the "Windows PowerShell" Properties window.
Right click the PowerShell window to get the to the Properties window.

Powershell script not running on Task Scheduler

I have a PS script that opens Excel (Com Object), processes a bunch of information, re-saves, and then sends some critical information via e-mail. The script runs great, and when I run it from the Run Console, it works great as well. However, when I schedule it as a task in the Task Scheduler it is not working properly. The task seems to "successfully run" every single time, but I do not get the output e-mail that I am supposed to get. I have run many other PS Scripts without a problem using the same configuration in the task scheduler. Could this have something to do with opening Excel as part of a script scheduled? Any thoughts are welcome.
I solved this issue using the answer from #briantist in PowerShell script won't execute as a Windows scheduled task, but I wanted to isolate exactly which switch was solving the problem.
It had nothing to do with -ExecutionPolicy, -Noninteractive, -NoLogo, -NoProfile or any other system privilege, user account running the script, etc.
Just needed to add -File in front of the script path in the Task Scheduler > Actions > Arguments field. Without this switch PowerShell was launching and the task history was showing Action Completed, but the script was not executing.

Wrong time in the Windows on dual-boot PC (Winwows/Linux)

On my PC I use two operation systems Windows 8 and Ubuntu 14.04. I noticed that after booting Linux and then rebooting to Windows, Windows show the wrong time (Windows clock is 2 hours behind).
I checked in the Linux - time is correct.
I checked time settings - both OS have UTC+2 time zone and option to set time from the Internet.
If I correct time in Windows and do not boot Linux everything is O.K. But at list single loading Linux makes time shift.
I have tried to remove the option for setting time from the Internet.
But manual time setting option changed nothing. What should be done to see the same time in the both operating systems?
That's very popular problem.
All you need to do (and that's really the rightest way) is to say Windows that you hardware time is UTC.
To do it just add the following DWORD key to the registry:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\RealTimeIsUniversal
and set its value to 1.
Also you can youse QWORD key instead of DWORD if you have 64bit Windows. But, as far as I know, it's not necessary.
The simplest solution is to set time zone UTC (London) in Linux.
I faced a similar problem, and my solution is quite simple without changing any configs of your operating system.
Requirements: Need to have a internet connection for time sync. Have admin privileges.
You need to enable windows time service
Go to services by typing in the search bar.
Open services
Search for windows time service (W32Time)
W32Time Service
Change the Startup Type to Automatic
Change Startup type
Creating a small bat script file
Open Notepad and create a file with the following command.
w32tm /resync
Save it anywhere with .bat extension. (Remember its location)
Schedule a task
Go to Task Scheduler by typing it in the search bar
Open Task Scheduler
Right click on the empty space > create new task
Create New Task
Give your task a name and description
Change "When running the task, use the following user account" to any admin user or admin group account.
Select "Run whether user is logged on or not"
Check the box for "Run with highest privileges"
Check the box for "Hidden" and "Configure for" = Windows 10
Go to Triggers tab, add the following triggers by clicking on "New..."
First Trigger
"Begin the task:" Select "At startup"
In Advanced settings, check the box for Enabled
Second Trigger
"Begin the task:" Select "At log on"
"Settings" Select "Any user"
In Advanced settings, check the box for Enabled
Go to Actions tab, create a new action by clicking on New...
"Action:" Select "Start a program"
In "Program/script" browse and select the file you created earlier.
And then click OK
Go to Conditions tab
Check the box "Start only if the following network connection is available"
Select your internet network or you can select "any connection" as wild card.
Go to Settings tab.
Check "Allow task to be run on demand"
Check "Run task as soon as possible ..."
Check "If the task fails, restart every" select "1 minute", "Attempts to restart up to:" 3 times
Check "Stop the task if runs longer than:" 3 Days
Check "If the running task does not end when requested, force it to stop"
"If the task is already running, then the following rule applies:"
Select "Do not start a new instance"
I had the same problem recently. My solution is:
First make sure you have the correct time zone
Set BIOS time to local time.
In Linux, edit /etc/default/rcS by replacing UTC=yes with UTC=no.
Reboot.

How to automatically start and advance a few steps in an application in background in linux?

I'm using Genymotion to run WhatsApp on Ubuntu 13.04 as I don't own an Android.
To get to Whatsapp everytime I login, I have to
1) open terminal and run ~genymotion/genymotion
2) click a button on the GUI which opens up another new window (play button).
3) wait for about 30s for the device to get ready.
How can I make the computer do these first two steps automatically for me at start up?
Even better if it possible to do them in background, i.e., I shouldn't see the GUI opening. It should perform the steps and be "minimized".
I was thinking if there was a way to record what my click does and then put it in a script.
Something like a strace command.
I hope my question is clear enough. I'm relatively new to Linux.
For now Genymotion allows you to start a VM from the command line, by calling the "player" binary, and passing the VM name as a parameter.
You could write a shell script that:
run: <GENYMOTION PATH>/player --vm-name <VM NAME>,
wait some seconds for the VM to boot: sleep 10,
then use adb to start your Application: adb shell am start -n com.whatsapp/com.whatsapp.Main
Luckily, no need to simulate clicks for this.

Setting up cron task in Plesk 11

I'm trying to setup a cron task in Plesk to run a short script every 5 minutes, I've just moved from a managed hosting account to a full access Plesk VPS, and I'm a little lost on a couple of things, this one in particular, when I go to Server > Scheduled Tasks I get a list of 'system users' as below, but I'm not sure under which user to make the cron task, any ideas?
adm
apache
bin
daemon
ftp
games
gopher
.. going all the way down to webalizer
The cron script path is below if that's relevant as to which user to choose -
/var/www/vhosts/mysite.com/httpdocs/scripts/index.php
If you are going to create subscription-level task, than you can create cron/windows scheduler task in:
"Subscriptions" > your subscription > "Websites & domains" > click on "Show advanced operations" > "Scheduled Tasks" > there will be only one name of FTP user of your subscription.
Note: Pay attention to interface changes for Plesk 11.5 and Plesk 12+ - there is no need to open "Show advanced operations".
The latest Plesk 12.5 provide a lot of options to cover most of the task cases:
Plesk 12.5
Other Plesk versions support only "Run a command" option:
Plesk 12.0
Plesk 11.5
If you need just answer, in "Server" -> "Scheduled Tasks" you can choose:
FTP user of your subscription mysite.com
your can choose root, but it's not recommended for security reasons.
For Plesk version below 12.5 to schedule execution of PHP script on Windows there is two ways:
Direct call of php binary with your script as argument.
Path to executable file: C:\Program Files (x86)\Parallels\Parallels Panel\Additional\PleskPHP55\php.exe
Arguments: path to you script like C:\inetpub\vhosts\domain.tld\httpdocs\script.php
Note: Pay attention to interpretation path, ...Additional\PleskPHP55\php.exe it path for PHP 5.5, you can change PleskPHP55 to PleskPHP5, PleskPHP53 or PleskPHP54 to use another PHP version.
Call script via request to your site:
Path to executable file: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Arguments: -c "(new-object system.net.webclient).downloadstring('http://domain.test/script.aspx')"
https://www.motherhost.com/help/creating-or-removing-scheduled-tasks-in-plesk/
Creating a Scheduled Task in Plesk 10:
You can set up Scheduled Tasks in Plesk by doing the following:
Log into Plesk*
Click on the Websites & Domains tab.
Click on Show Advanced Operations (a small grey link in the middle of the page), if the advanced options are not already shown.
Click on Scheduled Tasks.
Select the appropriate system user.
Click on Schedule New Task.
Fill out the form as follows:
Switched On: Check the box to turn on the scheduled task.
Description: A short description to remind you what this scheduled task does.
Scheduler Notification: If you want an email every time this runs, select the appropriate option, otherwise select Do Not Send. You may provide an email address where you want the notifications sent to.
Path to executable file: Specify the path to the file you wish to execute. For Windows servers, it would be something like this:
C:\Program Files (x86)\Parallels\Plesk\Additional\PleskPHP5\php-cgi.exe
Arguments: D:\Inetpub\vhosts\mydomain.tld\httpdocs\myscript.php
For Linux servers with Plesk, ir would be something like this:
/var/www/vhosts/domain.tld/httpdocs/myscript.php
Replace domain.tld with your domain name, and myscript.php with the appropriate subfolder(s) (if any) and filename.
Task Priority: Select Low, Normal or High.
Specify when to run your command by selecting the appropriate checkboxes in the Hours, Days of month, Months or Days of week fields.
Click OK to schedule the task or click Run Now to schedule the task and immediately run it.
You will be taken back to the Scheduled Tasks screen and you should see your new scheduled task listed at the bottom.
Removing a Scheduled Task in Plesk 10
Logging into Plesk*
Click on the Websites & Domains tab.
Click on Show Advanced Operations (a small grey link in the middle of the page), if the advanced options are not already shown.
Click on Scheduled Tasks.
Select the appropriate system user.
Check the box next to the Scheduled Task you want to remove.
Click on the Remove button.
It will load a new page and ask if you really want to deleted it. Check the Confirm Removal box and click on the OK button.
You will be taken back to the Scheduled Tasks screen and it should say: "Information: Scheduled tasks were removed."
Use this command:
php -q httpdocs/scripts/index.php

Resources