How to execute batch file on server from my local computer? - batch-file

What would be the best way to execute a specified batch script that are located on a server from my local machine?
I tried using PHP, and I had admin issues. I need something that can specify what batch needs execute, enter it then the batch file will get executed on my server.
Could you give some examples, or any site that works?
Thanks in advance! :)

Related

Run batch file from SQL

I want to run batch file from SQL Job without using exec xp_cmdshell.
Any idea?
Thanks
You could use a SQL Server Job, otherwise i cannot think of a way you could without xp_cmdshell.
Take a look at this
I want to run batch file from SQL Job without using exec xp_cmdshell.
Any idea?
Worth to mention that you can also leverage SQLCLR.
Example: CLR Stored procedure to execute command
Some other googlable threads:
How to execute a DOS command when xp_cmdshell is disabled in SQL Server
Executing an external process() in SQLCLR Project
Such approach introduces severe risks like memory leaks, crashing of underlying .net app pool etc
Therefore another link: Security in the CLR World Inside SQL Server
Instead of running batch file, i have created power shell and ran it from SQL job. It satisfy my requirement and resolved my issue.
Do it like the picture: like this image.
The drive containing the batch file should be other than the C drive, to avoid trouble.
Add execute, read and write permissions for the user, which you are using to run the batch file, to get the username run this query: EXEC master..xp_cmdshell 'whoami', get the name after the \ sign. For example "nt service\mssqlserver". Add permission for this user: mssqlserver
Finally make sure you put the batch file on the same server as where you execute your Job.

VbScript or with Scripting

we need to execute scripts locally, but how can we do it from a remote machine, so as to avoid going on to each machine and triggering the process manually. preferably with VbScript.
Generally in your VBScript you will specify the machine you want to query with the line
strComputer = "."
This can be changed to a computer name or IP address to remotely query a machine. However it is difficult to provide anything further as you've not posted your script or what you're trying to achieve with it..
Write your .vbs scripts and deploy them to a remote server - then on the remote server schedule a task to run whenever you'd like the script to run.
The script will run locally on that server.

Unable to access pscp.exe with a windows service account

I have built a windows batch file code that fetches the list of files from an FTP server and then pulls the appropriate file from that list. The batch file uses a combination of pscp.exe and psftp.exe in order to achieve this.
If I login as a member of the administrator group and execute this batch file manually (double clicking) it works perfectly, but the problem arises when I schedule a windows task to run that batch file from a windows service account (which is not in the administrator group).
The job when running under the windows service account is unable to execute the command for pscp.exe used in the code, whereas it executes everything else prior to that in the batch file perfectly normal.
Below is the line of code that I have used in my batch file :
pscp.exe -sftp -v -batch -pw %password% -ls %username%#ServerAddress:/outbox > F:\dirlist.txt
The service account is a member of BatchAccountsLG and ServiceAccountsLG groups, which is needed for the job to be able to execute the batch file code. Also, the service account has all the required access on any of the files/folders needed in the execution of the code.
I am not sure what the problem is because the batch file works perfectly fine if use my admin credentials, whereas it fails when the job is scheduled with the windows service account.
I have tried looking for an answer through google, but I have drawn a blank, any help on this would be highly appreciated. If there is anything else that I need to add to this, I would be more than glad to do so.
Thanks to all the ideas in advance.

How can I use a batch file to launch an application as a specific user?

I'm trying to figure out how I can use a batch file to launch Internet Explorer as a local user on the system hosting the batch file. Ideally I'd like to be able to double click the batch file and not have to enter user credentials. To break it down a bit:
User is logged onto the host system with a domain user (Server 2008 R2 Standard 64bit)
User can then double click on a batch file that will launch Internet Explorer as a local user on the host system, without prompting for the local user credentials
All I can find is information about NET USE, any help would be greatly appreciated!
"runas" command was intentionally designed to prompt for password. So, that is not your solution.
One of option is to create a scheduled task where you can store the password (safely) and run the scheduled task from batch file.
But if the batch file is distributable and not going to be run on same machine.. you may have to investigate on how to create a schedule task from batch file and then run it.
you may find this reference helpful

Log file locking issues in Batch scripting

I have a batch file which starts a Java server class. The output of the Java is redirected to a log file. This batch file is stared via a windows service. Problem is this log file is becoming very huge. Since the Java server is running, it is not possible to do any modification in the Log file as it is locked. How can I create a new log file for every day?
My idea was to write another batch file which will stop the service, backup the existing log file, delete and start the service file again. Is this approach correct?
java -Xms32m -Xmx256m gtServer >> abclog.txt
Above is the code in the batch file which starts the sever
Any tips on how we could back up the file without stopping the java server?
Thanks in advance
Karthik
Heard about log4j?
Ok, seriously, would it be possible to use some proper logging facility? It usually provides something for this purpose like RollingFileAppender.

Resources