bash – How to Automatically Run a Batch File on a Self-Cleaning Virtual Machine?

I am trying to learn a little bit of test automation. I know some batch files, I am brushing up my “PowerShell” skills and – who knows – I might even end up using some bash, in the long run.

I have this self-cleaning virtual machine that gets completely wiped-out after an user log-out. Upon the next user log-in, the Registry and the start-up folders get cleared. All I can do is to manually double-click on desktop icons in order to start some static software applications that I am recurrently using.

The batch file part I have managed to do by myself. I am enabling the execution of local “PowerShell” scripts and then running a script that is changing some desktop icons. Here is how the Change_Desktop_Icons.BAT batch file is looking right now:

@Rem  Just add a "Rem" command in front of the next line for debugging purposes.
@Echo Off

Rem Setting the local variables up.
Set PowerShellBase="%SystemRoot%System32WindowsPowerShellv1.0"
Set PowerShellExecutable="%PowerShellBase%PowerShell.Exe"
Set PowerShellScript="Y:DigitizationPowershellThe_My_Computer_Desktop_IconChange_Desktop_Icons.PS1"

Rem Changing the current directory to the local base installation of PowerShell.
ChDir %PowerShellBase%

Rem Enabling the execution of local scripts on this machine.
%PowerShellExecutable% -Command "& {Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser}"

Rem Executing the script that changes some desktop icons.
%PowerShellExecutable% %PowerShellScript%

@Rem  Just remove the "Rem" command in front of the next line for debugging purposes.
Rem Pause

The “PowerShell” part has nicely been debugged by some great people who are roaming about on this website and for whose help I am thanking them again. Great lessons I am learning here every day.

Now, the problem is that I always have to manually double-click on the Change_Desktop_Icons desktop icon. After the manual double-click and the execution of the scripts, the desktop icons get nicely changed, as it can be seen in the picture that appears below.

What I am now looking for is to somehow automate even the manual double-click. I am aware that the “Task Scheduler” static software application might be used in this respect, but I do not fully know how.

The virtual machine is quite tightly set up. I am not allowed to use certain static software applications such as, for instance, the “Group Policy“.

At this point, I have posted this question on the “Stack Overflow” website. Apparently, due to the fact that it is less related to the Software Development process and more suited for the general Personal Computer usage, the question has been closed.

I am pasting here the two comments that I have received on this question.

  • Add a scheduled task to run the Powershell script on logoff. There’s plenty of articles around that demonstrate how to do this – Scepticalist yesterday

  • I agree with @Scepticalist. Also, isn’t there a public folder on your V.M.? You can also toss it in there and have it run at log-in/start-up – Abraham Zinala yesterday

These are the two comments that I have appended to the question in order to reply to the commenters:

  • Unfortunately, it seems that I am not allowed to create a scheduled task on this virtual machine, @Scepticalist. Its user name is EE65037. I am checking its user name and it is perfect. I am copy-pasting its password, so I know for sure that it is all right. The only remaining cause for the happening of this weird behavior might be the fact that the system administrative team could have enforced a while ago some kind of group policies that are currently disabling the creation of scheduled tasks by the users of these virtual machines. – Mihai Dobrescu 22 hours ago

  • Indeed, @Abraham Zinala, there are a few directories that I am still allowed to use and that are intact after the logoff/logon process couple. The desktop folder is \ISXPFV01.hd00.unicreditgroup.euus_qv2_dem_user_data_pool_nra$EE65037.HD00Desktop . I am also attempting to maintain the shell-scripts in the Y:DigitizationGitHubShell-Scripting folder. I do not know how to place a scheduled task in either of these directories, but – first of all – apparently I am not allowed to create any kind of scheduled tasks, at all, on this virtual machine. – Mihai Dobrescu 22 hours ago

After my latest two comments, to my surprise, I have managed to create the scheduled task somehow. I cannot explain why this time it did not ask me for my credentials. It simply created it and saved it.

I have tested it and it was nicely running the Change_Desktop_Icons.BAT batch file. The problem is that the same thing did not happen at the user logon, when I want it to be run.

Is there a way to save the scheduled task in the Y:DigitizationGitHubShell-Scripting folder, for example? Or is there another way to solve this problem?