3
votes

I am trying to create a google cloud windows instance from the standard public image for windows server 2012. I am having a script which needs to be run at startup through metadata. The script is actually invoked but the script ran as normal user with standard privilege which is created by google cloud while instantiating the windows image. But i need to run the script as administrator i spent two days breaking my head with solutions to elevate the user's privilege but not helping though Tried : I have tried to elevate the privilege of the user but thats not working. Is there a workaround here .

Thanks in Adv!

2
AFAIK the startup script runs with admin privileges. Have you received any error when running your script ? - Faizan

2 Answers

2
votes

This is my solution.

Create a windows task schedule with admin privilege to do what you want. And execute schtasks /Run /I /TN "TaskFolder\TaskName" in startup script.

0
votes

What I have done is: In a windows template create a scheduled task that runs with high privileges and runs a ps1 script from for example: c:\programdata\startupscript.ps1. Set it to run in startup.

Then you create a metadata when building the server (this script will copy the file you have in GCP storage to the local server): (gcloud shell command to add to your build script) --metadata=sysprep-specialize-script-cmd=gsutil\ cp\ gs://yourbucket/script.ps1\ c:\programdata\startup.ps1

Now, all you have to do, is maintain the script in the gcp storage.