Re: how to use psexec to defrag all my computers

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Well, I'm not sure about the script but from the Command Prompt this simple command gets it going on my remotes:

psexec \\ComputerName defrag.exe c: -f

That is all that I need to have it run, no need for the -s - u or -p switches. With the FOR /f command as suggested by Shenan you should be able to get it going.

John

Rich wrote:
Yeah, all my machines have the same administrator username and password, i just think maybe I'm doing something wrong. below is what i was trying to do. I get a bunch of cmd windows to pop up, then they all close fairly quickly, i think saying the file or path can't be found. it disappears too quickly to see for sure.

set objFSO = CreateObject("Scripting.FileSystemObject")
set objShell = CreateObject("Wscript.Shell")
set objFile = objFSO.OpenTextFile("C:\documents and settings\Rich\desktop\computers.txt")

Do while not objFile.AtEndOfStream
currentpc = objFile.Readline
objShell.Run "c:\tools\psexec -s \\" &currentpc &" -u administrator -p password " &Chr(34) & "c:\windows\system32\defrag.exe c: -f" &Chr(34)
Loop

"John John - MVP" wrote:

If you run it from a local administrator account it should have administrative privileges on the remote machine. You can also run it under the all powerful System account if you have to. Are all the remote machines using the same Administrator name and password? If yes run it from a local Administrator account with the same credentials, but if you are logged on as an administrator I don't think that should be necessary.

John

Rich wrote:
I have a text file named computers.txt that lists all my workstations, one per line. For the life of me I can't figure out how to use this with psexec logging in as the local admin with a -u administrator to defrag all my workstations in this file. anyone have a working command line with the -u and -p in it they could share?
.



Relevant Pages

  • Re: remote machine execution
    ... i tried and it only pass the exe over the remote machine without the ... What happens when you execute the command line locally on machine nol-b0000586? ... you use any credentials to run the command via psexec, ... I suspect that the process spawned by psexec on the remote PC needs some network ...
    (microsoft.public.windows.server.scripting)
  • Re: remote machine execution
    ... The current problem in psexec is they cannot pass "=" sign over to remote ... machines. ... version of psexec. ... What happens when you execute the command line locally on machine ...
    (microsoft.public.windows.server.scripting)
  • Re: How to run a script on a remote host
    ... There is a utility called psexec to execute command on remote ... Those tools are a great addition to my library, but how would I execut a set of vbscript on a remote host, such as a simple MsgBoxwithout using logon script functions of AD? ... you can copy the scripts to the remote computers first and execute them. ...
    (microsoft.public.scripting.wsh)
  • Re: How to run a script on a remote host
    ... > You can download the free pstools from There is a utility called psexec to execute command on remote computers. ... There are usually some odd response on the remote machine like graphics going a little strange or just a single windows critical stop noise occuring but nothing more. ... The only one I've actually been successful in getting to work properly on a remote machine is the lock workstation command. ...
    (microsoft.public.scripting.wsh)
  • Re: Is there any reset local admin password remotely?
    ... Here are some command line alternatives: ... CryptPwd.exe (local and remote) ... "A better method for changing the local Administrator password on all your ... You can use the "NET USER" command: ...
    (microsoft.public.win2000.security)