• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 916
  • Last Modified:

psexec script

Is it possible to use psexec script to check tell whether a server is still alive or not ?

Can we use psexec script to shutdown a NT 4.0 server ?

  • 5
  • 4
3 Solutions
Will SzymkowskiSenior Solution ArchitectCommented:
Instead of using psexec to accomplish this you might want to use psshutdown which should do the trick...

psshutdown - http://technet.microsoft.com/en-us/sysinternals/bb897541.aspx

If you want to know if a server is still alive in most cases a simple "ping" to the servers name or IP will tell you this. Sometimes ping can be false (when ping-able) if a server is unresponsive due to a stopped or halted service or core windows files are corrupt or damaged.

You can shutdow a remote machine from the command line using this:
shutdown -m \\machinename -r -f
-r = Restart.
-f = Close programs and force shutdown.
Out of interest -s will shut the machine down.

You could use a vb ping script to check if the servers are responding. The script below will ping a predefined list of servers and then write to a file the servers that did not respond. Save the following into a text file and save with .vbs

Option Explicit

Const ForReading = 1

Dim objFSO, objFile
Set objFSO = CreateObject("Scripting.FileSystemObject")

'List of hosts to ping - set path. Hosts listed in the file, one host per line.
Set objFile = objFSO.OpenTextFile("C:\path\hosts.txt", ForReading)

Dim fso, f1
Set fso = CreateObject("Scripting.FileSystemObject")

'List of hosts that did not respond. Set path.
Set f1 = fso.CreateTextFile("C:\path\noresponse.txt", True)

Dim Shell, strCommand, strHost, ReturnCode

'Host or IP to ping
Do Until objFile.AtEndOfStream
strHost = objFile.ReadLine

'Create shell object
Set Shell = wscript.createObject("wscript.shell")

'What to run in command line
strCommand = "ping -n 1 -w 300 " & strHost

'Run command and get return code
ReturnCode = Shell.Run(strCommand, 0, True)

'0 = pingable, 1 = no response
If ReturnCode <> 0 Then
f1.WriteLine ""& strHost &" is down"
End If

'Remove comment to have optional status message display when the script is complete.
'msgbox("Ping complete!")

Hope that helps.
AXISHKAuthor Commented:
Try the shutdown command but doesn't work.. The entered computer name is not valid or remote shutdown is not sup
ported on the target computer. Check the name and then try again or contact your
 system administrator.(53)

The workstation can be pinged...

Any idea ?
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

Apologies, should look like this:

shutdown /m \\machinename /r /f

You will need permissions to run this you can not run as a normal user. A quick way to establish a connection to a remote server from the command line as an administrator is to do this:

net use \\machinename\c$ /user:domain\username password
AXISHKAuthor Commented:
Result for PsShutdown command.

C:\Scripts>psshutdown \\ -f -t 10

PsShutdown v2.52 - Shutdown, logoff and power manage local and remote systems
Copyright (C) 1999-2006 Mark Russinovich
Sysinternals - www.sysinternals.com

Couldn't access
The network path was not found.

Make sure that the default admin$ share is enabled on

If is already performing a shutdown operation you must
abort it before issuing a different command.
Is the default admin share enabled?
AXISHKAuthor Commented:
Try net use \\machinename\c$ from my DC, it said network path not found.

The workstation is rebuilt without change anything and already granted to the domain. THe domain administrator has been added in the local adminstrators of the workstation.

Anything I can check ?

It would appear the admin shares are not present. I am sure you could correct this with a GPO or script.
AXISHKAuthor Commented:
if i can access c$ on remote pc, does it mean admin share is opened?
In all likelihood. But you can try \\machinename\admin$ this points to the windows folder. The admin$ share is what you need to be in place.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now