Batch script to update hosts file on boot-up using curl - windows

I am trying to get a .bat script to run on boot-up and purge the hosts file with a new one.
I have this working on Windows Server 2008 Standard X86 and it has been working consistently for over a year. I installed 'curl', hard linked it to System32 and schedule the following .bat script using local group policy:
curl x.x.x.x/latest/hosts > C:\Windows\System32\drivers\etc\hosts
Now I want to get the same script working on windows server 2008 R2. I have the same thing setup and it works if I double-click the .bat file. However, when the script runs on startup via GPO, it simply wipes the hosts file completely and I have to login manually and double-click the .bat script.
Any idea what's causing this?
Is it a difference between Server 2008 R2 and Server 2008 STD?

Try
curl.exe x.x.x.x/latest/hosts > C:\Windows\System32\drivers\etc\hosts.tmp
move C:\Windows\System32\drivers\etc\hosts.tmp C:\Windows\System32\drivers\etc\hosts

Related

IIS wont run bat file (UAC Virtualization problem)

IIS hosts a .Net Core that simply needs to run a bat file. The file is part of the project.
On the local machine, everything works properly, but on the server, the bat file is not triggered because it is blocked by UAC virtualization.
On the server, the double-click script runs smoothly, but cannot be started automatically by .NetCore
.Net core has admin rights to execute the script, also AppPool has the
rights to execute the script. But the script simply stays blocked by
UAC.
I tried to completely disable UAC and restarted the server but again the same.
I tried to create a shortcut with admin rights that will run the script but without success.

Teamcity to run .exe file on remote server

We have a build server with Teamcity. It should run an .exe file on a Windows Server 2012 r2 machine after building. I have wasted a day trying to make it work different ways. The last realisation is: .bat file calling an .exe with the needed parameters on a producion server and command line command in teamcity:
psexec -i \\server-ip C:/SharedFolder/RUNME.bat
This works perfectly from command line, but Teamcity shows different errors with exit codes 4, 6 or even doesn't do anything without an error.
How, HOW can I do it? Thanx.
Solved, I just had to run TeamCity services as a domain administrator.

Running batch file from webserver

I have a web server that only I use running on my windows machine, and I would like it to run a batch file that's on the web server when I click a button on the website. Is this possible?
To reiterate:
Click button -> website runs batch file on same machine as webserver
Here's a lightweight webserver example in python: http://www.acmesystems.it/python_httpd
And running the batch file + getting the output: Run a .bat file using python code

Run batch scripts on a remote server (windows) from jenkins

I've got a continuous integration server (Jenkins ) which builds my code (checks for compilation errors) and runs tests and then deploys the files to a remote server (not a war file, but the actual file structure) I do this with a Jenkins plugin which allows me to transfer files via samba, it does this nightly.
Now, what I need to do is run an ant command on the remote server. And after that I need to start the application server on the remote server, the application server is started by running a .bat file from the command line.
I'm pretty clueless how to accomplish this, I know Jenkins is capable of running batch commands, but how do I make them run in the context of the server and not the context of the build server?
If Jenkins on Windows, remote on *nix, use plink.exe (which is essentially command line PuTTy)
If Jenkins on Windows, remote on Window, use psexec.exe
If Jenkins on *nix, remote on *nix, use ssh
If Jenkins on *nix, remote on Windows, (update 2015-01) Ansible http://docs.ansible.com/intro_windows.html has support for calling Windows commands, eg powershell, from a unix/linux machine, https://github.com/ansible/ansible-examples/blob/master/windows/run-powershell.yml
Tell me what OSes are involved (both on Jenkins and remote), and I will flash this out further.
Edit:
The download page for psexec.exe lists all command line options. You will want something along the lines of:
psexec \\remotecomputername -u remoteusername -p remotepassword cmd /c <your commands here>
Replace <your commands here> with actual commands as you would execute them from command prompt.
Note that psexec first needs to install a service, and required elevated command prompt/admin remote credentials to do so.
Also, you need to run psexec -accepteula once to accept the EULA prompt.
Following Slav's answer above, here is a simpler solution for Jenkins (*nix) to remote (windows):
Install an SSH server on your remote windows (MobaSSH home edition worked well for me)
Make sure your Jenkins user, on your Jenkins machine, has the required certification to open an SSH connection with your remote (you can simply open a terminal and ssh to your remote once, then accept the certification. Make sure it is saved for the Jenkins user).
You can now add an execute shell build phase in your Jenkins job which can SSH to your remote windows machine.
Notes :
The established connection might require some additional work - you might have to set windows environment variables or map network drivers in order for your executed commands or batch files to work properly on your windows machines.
If you wish to run GUI related operations this solution might not be relevant (Following my work on running automation tests which require GUI manipulation).
Using Jenkins SSH plugin is an issue, as seen here.
1、i install (MobaSSH home ) on my remote windows server .
2、and install jenkins ssh plugin
3、edit shell eg: go build project
4、it seems something wrong ,
" go: creating work dir: CreateFile C:\WINDOWS\system32\bsh\tmp: The system cannot find the path specified."
I ended up going with a different approach after trying out psexec.exe for a while.
Psexec.exe and copying files over the network was a bit slow and unstable, especially since the domain I work on has a policy of changing password every months (which broke the build).
In the end I went with the master/slave approach, which is faster and more stable. Since I don't have to use psexec.exe and don't have to copy files over the network.

Windows Server 2008 R2 32-bit Task Scheduler

Trying to schedule a task on a Windows Server 2008 R2 box.
I have a vbscript connects to an oracle database to pull data, and I want this to run at intervals.
The vbs is working standalone on the same machine, only when run with 32-bit csript.exe (needs a 32-bit ODBC driver). I can kick the vbs file off with a batch file to call C:\Windows\SysWOW64\cscript.exe "c:\scriptLoc" and it works fine.
But when I try to schedule a task I get the same error I got when trying to run the vbs directly by double clicking - which uses cscript.exe 64-bit (I presume).
I have also tried opening the 32-bit Task Scheduler C:\Windows\SysWOW64\taskschd.msc, and adding the job there, but getting the same results.
Any suggestions?
Thanks
Edit-------------------------------------------------------------------------------------------------------------
The error is that Oracle Client cannot be found, driver is 32-bit and won't work with 64-bit. This error occurs when I manually run vbs with the default cscript.exe, but it all works ok when I manually run with 32-bit cscript.exe
The solution for the scheduled task was:-
Start a Program
Program script = C:\Windows\SysWOW64\cscript.exe (which is the 32-bit csscript.exe)
Add Arguments = C:\Scripts\test.vbs (my vbs script to run)
Start in = C:\Windows\SysWOW64\ (run in the 32-bit directory)

Resources