Execute PSEXEC on a remote server 2008

marmoor99
marmoor99 used Ask the Experts™
on
Hi All

I am trying to run psexec command from a windows XP to execute a .bat file on a remote server with Windows Server 2008.
I am using this syntax: psexec.exe -i \\ServerName -u user -p pass c:\....bat
I am not able to perform this task on server 2008 while on server 2003 the same syntax work beautifully.
I have checked that the user I am using is part of the administrators group and it is. Is there something I need to know regarding psexec executing on server 2008?
Are there any services that needs to be started on the remote system for psexec to work?
What am I'm doing wrong?

Please assist
Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
I also noticed that when I run this command to enter a server 2008 machine, it created a new service on the remote machine called psexec....
When I execyte the command to enter server 2003 machine it does not create any service...
TechnoChatWintel Administrator / Cloud Computing

Commented:
You have to disable UAC and Firewall.

Also you might have to apply LocalAccountTokenFilterPolicy fix to execute on 2008.

Thanks
Saugata







reg add HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System /v LocalAccountTokenFilterPolicy /t Reg_DWord /d 1 /f

Open in new window

TechnoChatWintel Administrator / Cloud Computing

Commented:
PsExec create service on both 2K3 and 2K8.

Thanks
Saugata
psexec.JPG
psexec-1.JPG

Author

Commented:
OK.
I have checked everything you suggested:
-Firewall is off.
-LocalAccountTokenFilterPolicyis set to 1 in the registry
-And this is my UAC configuration which is the same on the Server 2003 Machine:


Picture-1.png
i would just like to clear one thing: psexec creates a service on the remote machine but then it removes the service. That's why it seems there is no service installed

Author

Commented:
I see.
Does anyone have any idea why it still does not work on server 2008?
Maybe it got something to do with how psexec is configured or used?
TechnoChatWintel Administrator / Cloud Computing

Commented:
There is nothing to configure with psexec, you just need to have the admin rights on remote system to execute any commands with psexec.

Can you tell me what exact message you are getting after executing psexec from your system to 2008 server.

Also make sure RPC service is running on the 2008 server, coz psexec use RPC  to communicate to the remote pc / server's.

To set RPC to auto and start you can use following command.

sc config "RpcSs" start= auto
NET START RpcS

Thanks
Saugata
Lead SaaS Infrastructure Engineer
Commented:
@  Marmoor99:

Windows 2003 Does not HAVE UAC.  That is why your settings are the same in both places and it works in one and not the other.  You need to turn off UAC either on the machine or through Group policy.  Your group Policy shows that UAC is still enabled for some actions.

While I'm not an Expert on the UAC Group policy, you may be able to simply modify these to fix your issue, you should at the least try one iteration where UAC is completely disabled.
Detect application installations and prompt -- set to disabledonly elevate applications which are installed in secure locations -- set to disabled

Author

Commented:
Hi Guys
Below are my current settings for UAC on server 2008.
I am executing this .bat file from a remote XP computer and it still does not work.....
psexec.exe \\{computer Name} -u user -p password calc.exe
What am I doing wrong???
Picture-1.png
TechnoChatWintel Administrator / Cloud Computing

Commented:
After execute the command. what message are you getting in console..?

Thanks
Saugata

Author

Commented:
I'm not able to see the message - the windows closes instantaneously...
TechnoChatWintel Administrator / Cloud Computing

Commented:
Just run it from cmd, so you will get the error message..

Thanks
Saugata

Author

Commented:
This is the error message I got:
Picture-2.png
TechnoChatWintel Administrator / Cloud Computing

Commented:
There was a topic on ee regarding the error message you are getting.. Hope this might help you..

Thanks
Saugata
Ben Personick (Previously QCubed)Lead SaaS Infrastructure Engineer

Commented:
Have you thought about just using a method that uses only standard OS commands?

When i run remote tasks I like to do it like this:



@EchoOff
SET Domain=Contosso
SET User=DAdmin
SET Password=1234
SET RemoteServer=Serv2
SET URLofBatch='\\Serv1\BatchShare\%RemoteServer%.bat'
SET TaskName=%RemoteServer%Batch

CALL Serv1.bat

Echo Serv1.bat Completed!

::Create a Task on the remote server to execute the batch file from the local server
SCHTasks /Create /S %RemoteServer% /U %Domain%\%User% /P %Password% /RU %Domain%\%User% /RP %Password% /SC ONCE /TN "%TaskName%" /TR "%URLofBatch%" /V1 /Z
:: SCHTasks is a standard MS command scheduler interface.  See Wikipedia site maintained here http://en.wikipedia.org/wiki/Schtasks
:: /Create instructs the command to create a task
:: /S Specifies a remote system's name is to follow
:: /U Specidfies a Username that can connect to this server is to follow in Domain\User format
:: /P Specifies the User's PW is to follow
:: /RU Specifies the username for the task to run as once it's scheduled
:: /RP Specifies the above user's PW will follow
:: /SC Specifies the schedule's recurance
:: /TN Specifies the task's name
:: /TR Specifies the location including file name of the executable to run
:: /V1 Specifies to use the format for tasks in use prior to Windows Vista
:: /Z Specifies the task should be removed once it is run

::Run The Task on the remote server.
SCHTasks /Run /S %RemoteServer% /U %Domain%\%User% /P %Password% /I /TN "%TaskName%"
:: SCHTasks is a standard MS command scheduler interface.  See Wikipedia site maintained here http://en.wikipedia.org/wiki/Schtasks
:: /Run instructs the command to Run a task
:: /S Specifies a remote system's name is to follow
:: /U Specidfies a Username that can connect to this server is to follow in Domain\User format
:: /P Specifies the User's PW is to follow
:: /I Specifies that the task should be run immediately.

Echo %URLofBatch% is running

:End

Open in new window

Author

Commented:
I have not tried to use standard commands like you suggest here.
But, I need to figure out why psexec does not work with my Server 2008 machine...

Ben Personick (Previously QCubed)Lead SaaS Infrastructure Engineer

Commented:
so, it is not that you want the command to run remotely via batch commands, it is that you specifically want to use PSExec?
TechnoChatWintel Administrator / Cloud Computing

Commented:
Hi marmoor99,

I forgot to add the link,

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Windows/XP/Q_23419631.html

Above link for automatic update service, but as you are getting same error message, hence requesting you to go through..

Thanks
Saugata

Author

Commented:
I Just want to use VBScript for this task but since the only option that was suggested for remote access through VBScript is by using psexec, I want to know why is it not working with Server 2008 and working well on server 2003...

Author

Commented:
Can I perform this task by using WMI? If so, how?
Ben Personick (Previously QCubed)Lead SaaS Infrastructure Engineer

Commented:
Why write this in WMI or VBScript if you can run it with the script I gave you?

  You are running a batch file on the remote machine so why not run a batch file on the local machine to call it?

Author

Commented:
You are right, It is much easier doing this in a batch file...but since it is a very long script already written in VBScript and I'm not the only one working on it...I cannot change the scripting language and re-write it in a batch file, so I am responsible for the part of the script which execute a batch file on a remote PC with seems to work on all platforms except Windows Server 2008....
I know it will be much longer and probably more difficult but I need help with writing this function in VBScript Using WMI or to find out why psexec does not work.

Thanks
Roi
Ben Personick (Previously QCubed)Lead SaaS Infrastructure Engineer
Commented:
but you already execute the command from the VBScript correct?  So just run two commands From my script via your VB Script, or even run the entire batch file from the vb script if you like, since that woudl just be one command shell instance in vb-script. simple as that.

the commands you can call from VBScript if you don't want to call my whole batch file are as follows, I put the parameters you will need to enter in square braces []

SCHTasks /Create /S [RemoteServerName] /U [Domain\User] /P [Password] /RU [Domain\User] /RP [Password] /SC ONCE /TN "[TaskName]" /TR "[URLofBatch]" /V1 /Z

SCHTasks /Run /S  [RemoteServerName] /U  [Domain\User]  /P [Password] /I /TN "[TaskName]"

Author

Commented:
Hi

I didn't know I can do that...I'm kind of new at this...
Can you give me an example on how to embed a batch script in a VBSript?
In this script for example? Instead of the psexec command...


et objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")

strPSExec = "\\server\share\psexec"
strBatchFile = "\\server\share\BatchToRun.bat"
strUser = InputBox("Enter username:", "Username", objNetwork.UserDomain & "\Administrator")
strPass = InputBox("Enter password for " & strUser & ":", "Password", "")

strComputer = InputBox("Enter the remote computer to run the script on:", "Remote Computer")

strPSExec = objFSO.GetFile(strPSExec).ShortPath
strBatchFile = objFSO.GetFile(strBatchFile).ShortPath
strCommand = strPSExec & " -accepteula -e -u " & strUser & " -p " & strPass & " \\" &  strComputer & " cmd /c " & strBatchFile
intReturn = objShell.Run(strCommand, 0, True)
If intReturn = 0 Then
      MsgBox "Command executed successfully."
Else
      MsgBox "Command failed with return code " & intReturn
End If


Thanks
Ben Personick (Previously QCubed)Lead SaaS Infrastructure Engineer
Commented:
In the code attached I have changed your code to call the commands.

  (It would probably make sense to make an actual sub function for the commands in a future vbs/wsh file but I'm just doing this quick and dirty because I haven't scripted VBS in a while and don't have my existing scripts on this computer.)



Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")

' Set initial Values
strSCHTasks = "C:\Windows\System32\SCHTasks.exe"
strBatchFile = "\\server\share\BatchToRun.bat"
strTaskName = "RemoteBatchTemp"

' Get Data from user
strUser = InputBox("Enter username:", "Username", objNetwork.UserDomain & "\Administrator")
strPass = InputBox("Enter password for " & strUser & ":", "Password", "")
strComputer = InputBox("Enter the remote computer to run the script on:", "Remote Computer")

' Not sure why you bother to call these functions..
strSCHTasks = objFSO.GetFile(strSCHTasks).ShortPath
strBatchFile = objFSO.GetFile(strBatchFile).ShortPath

' NOTE: chr(34) is a double quote character
strCommand = strSCHTasks & " /Create /S " &  strComputer & " /U " & strUser & " /P " & strPass & " /RU " & strUser & " /RP " & strPass & " /SC ONCE /TN "& chr(34) &  strTaskName & chr(34) &" /TR " & chr(34) & strBatchFile & chr(34) & " /V1 /Z"
strCommand2 = strSCHTasks & " /Run /S " &  strComputer & " /U " & strUser & " /P " & strPass & " /I /TN "& chr(34) &  strTaskName & chr(34)

' Execute Command to create the scheduled task here
MsgBox "Executing Command 1: " & strCommand
intReturn = objShell.Run(strCommand, 0, True)

' Check Return Code generated from task above and Echo the Outcome Below
If intReturn = 0 Then
      MsgBox "Command 1 (Schedule Remote Task) Executed Successfully."
Else
      MsgBox "Command 1 (Schedule Remote Task) Failed with return code: " & intReturn
End If

' Execute Command to create the scheduled task here
MsgBox "Executing Command 2: " & strCommand2
intReturn = objShell.Run(strCommand2, 0, True)

' Check Return Code generated from task above and Echo the Outcome Below
If intReturn = 0 Then
      MsgBox "Command 2 (Run Remote Task) Executed Successfully."
Else
      MsgBox "Command 2 (Run Remote Task) Failed with return code: " & intReturn
End If

'
' ------------------------------------------------------------------------------------
' -- NOTE: Below are your Original commands and my Original commands for reference. --
' ------------------------------------------------------------------------------------
'
'strCommand = strSCHTasks & " -accepteula -e -u " & strUser & " -p " & strPass & " \\" &  strComputer & " cmd /c " & strBatchFile
'intReturn = objShell.Run(strCommand, 0, True)
'If intReturn = 0 Then
'      MsgBox "Command executed successfully."
'Else
'      MsgBox "Command failed with return code " & intReturn
'End If
'

'
'SCHTasks /Create /S [RemoteServerName] /U [Domain\User] /P [Password] /RU [Domain\User] /RP [Password] /SC ONCE /TN "[TaskName]" /TR "[URLofBatch]" /V1 /Z
'
'SCHTasks /Run /S  [RemoteServerName] /U  [Domain\User]  /P [Password] /I /TN "[TaskName]"
'

Open in new window

Ben Personick (Previously QCubed)Lead SaaS Infrastructure Engineer

Commented:
@ Marmoor99,

     Thanks Very Much for the Points!  In honesty, I had practically forgotten about this thread.  I'm glad you found my suggestions and coding useful, and also that you took the time to assign credit to the questions which helped you the most.

~Q

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial