run command as administrator on remote windows machine - windows

Situation: Running the bat file on windows machine:
1. When I double click the bat file: Bat running is failed.
2. When I right click on bat file and run as administrator: Bat run is successful.
Now I have to run this bat file successfully from remote machine.
What I did:
1. Installed freeSSDd on remote machine and configured administrator user on freeSSHd to access shell and SFTP.
2. Now I am able to login to the remote machine using putty.
Problem:
I am not able to run the bat file successfully. How can I achieve this?
I also used runas /savecred /user:administrator C:/install.bat, but It didn't helped.

There is a way to get this working without any 3rd party software.
You have to create a task on the remote machine using the windows task scheduler which simply executes the desired command. There is an option where you can tell the scheruler to run a bat with a specific account. Enter an admin account and the password and check the "run with highest privileges" box. Leave "Triggers" empty, go to "Settings" and check the "Allow task to be run on demand" box. That's it!
Now when you want to run your file from a different location do
SCHTASKS /RUN /S <RemoteServerName> /U username /P password /TN "<task name>"
If you don't want to enter username and password each time you can adept the user policy (e.g. add the calling machine to the trusted list of the server).

If you have installed an ssh daemon, then you can run your BAT in a remote shell, but you remote shell may open up in something other than CMD.COM. I use cygwin to set up sshd and then from a remote machine, if I ssh in to run a command, it is using cygwin's bash. I can run a BAT file, but need to call CMD first:
ssh WINDOWS_SERVER "cmd /C D:\PATH_TO_BAT\BATCHFILE.BAT"
But there are some pieces missing here. I looked briefly at the Freesshd page and saw only graphical interfaces. Does freesshd support remote command execution, or just secure fire transfer? And what sort of shell get executed on the windows server when you run it?
cygwin is an entire Linux subsystem that runs under Windows and includes an sshd server, but might be a bit much for someone starting out: https://cygwin.com/
\n makes a powershell remote server that listens on port 22 (ssh) and dumps you into a powershell prompt, you can then use my steps above to call CMD from powershell, versus a bash shell.
http://www.powershellserver.com/

Related

Using psexec on a bat file that contains psservice

I have a bat file that tries to stop a service on a remote machine, the file contains the following
psservice \\remoteServerName -u domainName\userName -p password stop serviceName
where userName is a name of a user with Admin privileges on the remote machine.
If I run the last line using cmd then the requested service does stop.
I, however, run the bat file using psexec, since it contains more operation than just stopping the service. This is where my problem occurs:
If I run
psexec -u domainName\userName -p passsword batFilePath
the cmd window seems to get stuck.
But if I run
psexec batFilePath
then the psservice executes correctly.
My problem is that I need the user "domainName\userName" to be able to run the other commands in the bat file.
What can I do ? Why does the cmd got stuck when I gave psexec the parameters of the userName and password ?

PSEXEC returning garbage result. Why?

I want to run a script on a remote windows 2008 server using PSEXEC of PSTOOLs..
I have installed PSTOOLs on my local machine and can run the PSEXEC command successfully as well. I connect to the remote server through it and it even picks up the script placed there. However, all I get is some sort of garbage values. And after that it states that the intended network is no longer available, which it is because I can see it and access it through the GUI.
I must mention that when I execute that script manually in the remote server it works fine. I am using windows remote desktop utility to connect to the server.
Am I using PSEXEC the correct way? Or is the intended function of PSEXEC the same as what I am trying to do?
First you should have a look at the help page
You must use -w to specify the remote working dir, and you can't call a .bat directly, you have to call cmd.exe. So try this
psexec \\remoteserver -w "c:\users\admin\desktop\" cmd.exe /c youbatch.bat

can not issue any command on freesshd server

I installed FreeSSHd server on my Windows XP machine. Then i started FreeSSHd and created a user. After that i runned Putty to connect my newly installed SSH server. I entered my created user name and password in putty. I successfully logged on but i couldn't execute any SSH commands with putty. Only HELP and DIR commands answer properly. Other SSH commands like LS, PWD, etc. returns error message such as "xxx command is an unknown command and can not be executed.".
My question is simple. How can execute SSH commands via Putty over FreeSSHd server on Windows machine. I want to simulate a file copy. I think i should execute SCP or PUT commands but i couldn't success.
Any ideas?
Commands like "ls" and "pwd" aren't "ssh commands", they're Unix commands. You'd expect for them to be available a Unix system (including Linux). MS Windows isn't a Unix system and doesn't provide those commands.
You can install these programs as third-party software if you like. Cygwin is a popular free package.

Trying to delete files via a scheduled task and VBScript

I asked a previous question about downloading file unattended on a server, using VBScript and Windows Task Scheduler. (See
Scripting SFTP unattended download )
That works great but now I also need to delete the files from the server I am calling:
Set sessionses = WScript.CreateObject("WScript.Shell")
sessionses.Run "C:\TCS\SFTP\delThem.bat", , True
PSFTP calling a batch file that runs this command:
psftp user#host:22 -batch -b script.txt -pw pa$$word
script.txt is as follows:
cd FromCeridian
del *.GEN
If I run this command from the command line, or double click the batch file containing the command, it works "interactively", but when running unattended and scheduled, it doesn't do this part. The server is SFTP, so I can't just use win ftp commands to do it.
Any ideas?
Check the security options of your task to verify the user identity has correct access privileges.

How to execute a Windows command on a remote PC?

Is it possible to execute a Windows shell command on a remote PC when I know its login name and password?
Is it possible to do it using client PC's Windows shell?
If you are in a domain environment, you can also use:
winrs -r:PCNAME cmd
This will open a remote command shell.
psexec \\RemoteComputer cmd.exe
or use ssh or TeamViewer or RemoteDesktop!
This can be done by using PsExec which can be downloaded here
psexec \\computer_name -u username -p password ipconfig
If this isn't working try doing this :-
Open RegEdit on your remote server.
Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System.
Add a new DWORD value called LocalAccountTokenFilterPolicy
Set its
value to 1.
Reboot your remote server.
Try running PSExec again from
your local server.
You can use native win command:
WMIC /node:ComputerName process call create “cmd.exe /c start.exe”
The WMIC is part of wbem win folder: C:\Windows\System32\wbem

Resources