Logoff a special user via batch file? - batch-file

Can logoff or sing out a special user in domain from server via batch file?
like : shutdown -r -m \\target computer

If it's going to run via batch file, you have to authenticate first, so I assume you have the credentials for that specific user/domain admin user, so I'd recommend using wmic.exe(using RPC):
wmic /node:"ServerHostname" /user:"DomainName\DomainAdmin" /password:"DomainAdminPass" process call create "shutdown -l -t 0"
There are many other ways to do this in a domain like performing a "net use" to authenticate and than creating and running a service via sc.exe or at.exe/authenticating via schtasks.exe and creating a schedule tasks that can run remotely.

Related

Why does the batch file I created to stop and start a windows service not working correctly

My batch file that I created to stop and then start windows service won't run and throws back an error
Each time I run the file as Admin (I am the only user that's on this machine and the account is an admin account).
I have tested my batch file on its own and not in task scheduler and it works perfectly fine when I run the batch file as admin. However, it falls over when I try set up a daily task on Task Scheduler.
I have a simple batch file that stops and starts a service. for reference this is what it looks like:
Net Stop "StorSvc"
Net Start "StorSvc"
I have run this as admin and it worked fine. I then created a task to do this daily at a certain time. I placed the file in C: Drive and attached the file to my task scheduler.
On the security options I have ticked
"Run whether user is logged on or not"
"Run with the highest privileges"
I have changed the "When running the task use the following user account" to my account, Systems and other admin options that show up. I even selected "System"
When I click ok it prompts me to sign in to the admin account. when I do this it says
"An error has occurred for task StorSvc" Error message. One or more of the specified arguments are not valid"
All of the last run results are as listed below:
0x800710E0
0x41303
0x2
I have had better success with sc.exe for controlling services via batch file.
For your situation this should work:
sc.exe stop StorSvc
sc.exe start StorSvc
If that still gets credential issues you could include PsExec.exe like this:
psexec.exe -u <user> -p <password> -c "sc.exe stop StorSvc"
psexec.exe -u <user> -p <password> -c "sc.exe start StorSvc"

How to map drive as system account via batch file

I need to map a network drive as a the local system account on a server, I can achieve this fine by running psexec -I -s cmd.exe then the net use command
My issue is the drive disconnects on reboot, even with persistent set to /p:yes
I’ve been trying to create a batch file that will run at startup that will run cmd via psexec, and then execute the net use command.
I can get to this point where cmd runs but I can’t get the next part of the command for net use to appear in the new cmd window.
Has anyone got any ideas/a better way of doing this altogether?
As a side note, the network share requires separate credentials to connect to it so it has to be mapped in such a way that credentials can be specified.
Have you tried saving the file as a .cmd file type and placing it in the shell:startup folder? It will run automatically every time you log in to the pc.

How to make PSexec launch bat file on currently logged in user account

I am currently trying to figure out if PSexec has the ability to launch a batch file on the currently logged on user's account. I'm attempting to open a wep page with a batch file on multiple computers on a domain. I would like to know if it is possible to launch the file with the logged on users account so they see the opened weppage. Any help would be very appreciated.
Interactive mode?
From the documentation:
PsExec -i
Run the program so that it interacts with the desktop of the
specified session on the remote system. If no session is specified the
process runs in the console session.
PsExec.exe -s -i 1 \\computername notepad.exe

batch script for running application on two machines #homenetwork

I am trying figure out how to run an application on local pc and then on my second pc both are at my home network, I am using several applications which merge together by entering second pc ip, so i though if i can anyway do something like
my spec: local 10.0.0.1
and second pc 10.0.0.4
need to run from my local
#echo off
start "" "C:\TEST\TESTAPP.EXE"
start 10.0.0.4 "C:\TEST2\TESTAPP.EXE" <-- just need find a way how to do this
didnt found anything regarding start command and ip address specified maybe it couldnt be achieved with bat script?
thanks everyone for any helpful response and sorry if its just dumb question
If I understand correctly you are trying to start a script on machine B from machine A. If this is correct I would recommend using PSExec from Sysinternals Suit.
Example
Psexec.exe \\<computername or ip> -u username -p password C:\ProgramToRun.exe
PSExec help file from http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx
Using PsExec
Usage: psexec [\\computer[,computer2[,...] | #file]][-u user [-p psswd][-n s][-r servicename][-h][-l][-s|-e][-x][-i [session]][-c [-f|-v]][-w directory][-d][-<priority>][-a n,n,...] cmd [arguments]
-a Separate processors on which the application can run with commas where 1 is the lowest numbered CPU. For example, to run the application on CPU 2 and CPU 4, enter: "-a 2,4"
-c Copy the specified program to the remote system for execution. If you omit this option the application must be in the system path on the remote system.
-d Don't wait for process to terminate (non-interactive).
-e Does not load the specified account’s profile.
-f Copy the specified program even if the file already exists on the remote system.
-i Run the program so that it interacts with the desktop of the specified session on the remote system. If no session is specified the process runs in the console session.
-h If the target system is Vista or higher, has the process run with the account's elevated token, if available.
-l Run process as limited user (strips the Administrators group and allows only privileges assigned to the Users group). On Windows Vista the process runs with Low Integrity.
-n Specifies timeout in seconds connecting to remote computers.
-p Specifies optional password for user name. If you omit this you will be prompted to enter a hidden password.
-r Specifies the name of the remote service to create or interact with.
-s Run the remote process in the System account.
-u Specifies optional user name for login to remote computer.
-v Copy the specified file only if it has a higher version number or is newer on than the one on the remote system.
-w Set the working directory of the process (relative to remote computer).
-x Display the UI on the Winlogon secure desktop (local system only).
-priority Specifies -low, -belownormal, -abovenormal, -high or -realtime to run the process at a different priority. Use -background to run at low memory and I/O priority on Vista.
computer Direct PsExec to run the application on the remote computer or computers specified. If you omit the computer name, PsExec runs the application on the local system, and if you specify a wildcard (\\*), PsExec runs the command on all computers in the current domain.
#file PsExec will execute the command on each of the computers listed in the file.
cmd Name of application to execute.
arguments Arguments to pass (note that file paths must be absolute paths on the target system).
-accepteula This flag suppresses the display of the license dialog.

Automated Bat File Not Working For Service Account

We have a file that we send to the bank and it worked via bat file when sending through FTPS.exe but not we must use PSFTP.exe which works for the desktop user but not the service account. We have tried logging in as the service account user and running the process which works when we are logged in as but not when scheduled through a Windows Server. Have also tried putting the Y in the bat file to answer the validate question whcih we have to answer only once when using desktop user without success.
I have read a lot of hits online pointing to authentication, using two files, etc... but not sure how to implement them. I would really appreciate assistance with this.
here is my bat file which is called by Gentran as an executeable, server is Windows 2008 R2, Service Pack1:
SET MOVEitIP=FTX-SERVSH.bnymellon.com
SET MOVEitUser=******
SET MOVEitPassword=******
echo cd /inbound/trp/ >> frommoveit.txt
echo mput D:\GENSRVNT\PositivePay\*.txt >> frommoveit.txt
echo quit >> frommoveit.txt
psftp -batch %MOVEitIP% -l %MOVEitUser% -pw %MOVEitPassword% -b frommoveit.txt
del frommoveit.txt
Basically took script from bat file for FTPS.exe and updated it for PSFTP.exe to use. Again, this works as desktop user and service account user (when signed into the server) but not when automated.
Thank you in advance for your assistance.
Krise
The service account must have the "Log On Locally" rights otherwise the account will not be able to logon to execute the sheduled task. I think you will see the logon error in the eventvwr at the time the task was run.

Resources