Link to home
Start Free TrialLog in
Avatar of scarm
scarmFlag for United States of America

asked on

I cannot get psexec to execute an .vbs file on any machine

I need a method to run a program now on all machines in a domain.  - all machines are in an ad domain.

I'm using the following command

psexec \\computername -c \\23usacb90\netapps\stcheck.vbs               (I have the stcheck.vbs on in the same directory as psexec and in the location specified in the command line)

All I get is .....the system cannot find the file specified



:\>psexec \\colgate-ff4eb13 -c \\23usacb90\netapps\sameti

sExec v1.56 - Execute processes remotely
opyright (C) 2001-2004 Mark Russinovich
ysinternals - www.sysinternals.com


sExec could not start stcheck.vbs on colgate-ff4eb13:
he system cannot find the file specified.

:\>
Avatar of scarm
scarm
Flag of United States of America image

ASKER

also, how do I close out a question and award points -
Avatar of oBdA
oBdA

Make that a two- or three-step process; copy the script file first, then run cscript with the script name as argument.
Example:

@echo off
copy \\23usacb90\netapps\stcheck.vbs \\colgate-ff4eb13\Admin$\system32
psexec  \\colgate-ff4eb13 cscript.exe stcheck.vbs
del \\colgate-ff4eb13\Admin$\system32\stcheck.vbs
Maybe try:
psexec \\computername [flags] wscript.exe stcheck.vbs
ahhhh you people are fast - this was blank when I started!
Avatar of scarm

ASKER

Getting there but no dice yet

I can execute the command using

psexec \\computername cscript.exe stcheck.vbs

but I'm getting the below output and the script is not running - I can run this thing fine from the local console - the .vbs writes to a text file and it is not doing it from psexec.




Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

Input Error: There is no script engine for file extension ".bat".
cscript.exe exited on colgate-ff4eb13 with error code 1.

C:\>psexec \\pcname-ff4eb13 cscript.exe stcheck.vbs

PsExec v1.56 - Execute processes remotely
Copyright (C) 2001-2004 Mark Russinovich
Sysinternals - www.sysinternals.com


Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

cscript.exe exited on colgate-ff4eb13 with error code 0.

C:\>psexec \\pcname-ff4eb13 cscript.exe stcheck.vbs
That must be a problem in your script; if I copy this little script to a remote machine and run it as described above, it will create the file as it should.

set fso=CreateObject("Scripting.FileSystemObject")
set fi=fso.OpenTextFile("D:\Temp\test.txt", 2, true)
fi.WriteLine("PsExec Test")
set fi=nothing
Keep in mind AV's hate vbs scripts.
Might be an AV stopping the execution.
Avatar of scarm

ASKER

Well... according to the documentation, you have to specify a username and password; however, I'm getting an error.

" If you omit a username the remote process runs in the same account from which you execute PsExec, but because the remote process is impersonating it will not have access to network resources on the remote system. When you specify a username the remote process executes in the account specified, and will have access to any network resources the account has access to. Note that the password is transmitted in clear text to the remote system."

My error (I amusing the correct password):

C:\>psexec \\colgate-ff4eb13 -u "SA" "\\23usacb90\netapps\stcheck.vbs"

PsExec v1.56 - Execute processes remotely
Copyright (C) 2001-2004 Mark Russinovich
Sysinternals - www.sysinternals.com

Password:

PsExec could not start \\23usacb90\netapps\stcheck.vbs on colgate-ff4eb13:
Logon failure: unknown user name or bad password.
If SA is a domain account, you might have to specify the domain name as YourDomainName\SA.
But you still won't be able to run the vbs script directly; you need to run cscript, specifying the script name as argument.

Try it with this little batch script:

@echo off
copy \\23usacb90\netapps\stcheck.vbs \\colgate-ff4eb13\Admin$\system32
psexec  \\colgate-ff4eb13 cscript.exe stcheck.vbs
del \\colgate-ff4eb13\Admin$\system32\stcheck.vbs
Scarm,

Post the contents of your VBS here so that we can look at that code as well.  maybe your vbs is trying to open a file that doesn't exist, instead of creating it first.


CShenberger
Avatar of scarm

ASKER

Here is the contents of the VBS file.  oBdA's way works if the computer is currently on the domain; however, we need to do this to every PC in the domain (around 200 computers).  The problem is that when I connect to the PC using psexec, the computer does not have any of it's network drives through that session.  I can map the drive, and run the script, but I am not sure how to do this if I can't connect to the drive and only run 1 file to do every computer in the domain.  Also, the file the vbs script is trying to write to is there.  I put the below script in our login script, and it works fine.

----------------------------------------------------------------------------
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Dim NotesPath, WriteLine1, FVer, FPath, FDate, CName, CUser
strComputer = "."
 
Set objComputer = CreateObject("Shell.LocalMachine")
CName = objComputer.MachineName

'---------- Gets Username ---------------------
Set objSysInfo = CreateObject("ADSystemInfo")

On Error Resume Next
CUser = objSysInfo.UserName

'------------- Gets Notes Path from Registry -----------------
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
    strComputer & "\root\default:StdRegProv")
 
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\notes.exe"
strValueName = "Path"
On Error Resume Next
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
NotesPath = strValue


'------------------ Get file date of nstclientu.dll -----------------------------
'Gets Path, Date, and Version
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(NotesPath & "nstclientu.dll")
FPath = "Path: " & objFile.Path
FDate = "Date Modified: " & objFile.DateLastModified

WriteLine1 = CName & " : " & CUser & " : " & objFile.Path & " Date: " & objFile.DateLastModified
Const ForAppending = 8

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
 ("\\23usacb90\netapps\sametimelog\stlog.txt", ForAppending, True)

objTextFile.WriteLine(WriteLine1)
objTextFile.Close
Avatar of scarm

ASKER

anything????
Try to specify user name and password (-u and -p) in the command line

@echo off
copy \\23usacb90\netapps\stcheck.vbs \\colgate-ff4eb13\Admin$\system32
psexec -u SomeDomain\SomeUser -p SomePassword \\colgate-ff4eb13 cscript.exe stcheck.vbs
del \\colgate-ff4eb13\Admin$\system32\stcheck.vbs

To do this for a list of machines, use

@echo off
for /f %%a in ('type "MachineList.txt"') do (
  copy \\23usacb90\netapps\stcheck.vbs \\%%a\Admin$\system32
  psexec -u SomeDomain\SomeUser -p SomePassword \\%%a cscript.exe stcheck.vbs
  del \\%%a\Admin$\system32\stcheck.vbs
)


Or, if this is a one-time thing, the brute force method:
Change the export file to create a local file instead of appending to the network share, then append it from the batch:
Set objTextFile = objFSO.OpenTextFile ("C:\stlog.txt", ForWriting, True)

@echo off
copy \\23usacb90\netapps\stcheck.vbs \\colgate-ff4eb13\Admin$\system32
psexec -u SomeDomain\SomeUser -p SomePassword \\colgate-ff4eb13 cscript.exe stcheck.vbs
del \\colgate-ff4eb13\Admin$\system32\stcheck.vbs
type \\colgate-ff4eb13\C$\stlog.txt >>"\\23usacb90\netapps\sametimelog\stlog.txt"
del \\colgate-ff4eb13\C$\stlog.txt

On the other hand: If it's working in the logon script, why use psexec?
scarm,

Sorry about the delay.  A couple of bad days.

I don't see how your vbs is working.  

In this section

'------------- Gets Notes Path from Registry -----------------
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
    strComputer & "\root\default:StdRegProv")
 
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\notes.exe"
strValueName = "Path"
On Error Resume Next
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
NotesPath = strValue


NotesPath is set to strValue  but that has no value which makes this line invalid

Set objFile = objFSO.GetFile(NotesPath & "nstclientu.dll")

If you need to have a mapped drive for psexec to work you could add these lines to your script to map a network drive:

Dim objNetwork, strDrive, objShell, objUNC
Dim strRemotePath, strDriveLetter, strNewName
'
strDriveLetter = "z:"
strRemotePath = "\\23usacb90\netapps"

' Section to map the network drive
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath

This would give you the mapped drive you are needing, but psexec should work without it.  Did you try using oBdA's suggestion of username and password with psexec? Why doesn't using this in a login script work?  If you only have to run it for machines in the domain then a login script would work for you.








ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry, but change the log line (%computername% should be %Machine%, and %username% is unnecessary, if not to say useless):
>>"%LogFile%" echo %Machine% : Path: %NotesPath% Date: %dllDate%
I would say that oBDA should get the points.  He gave most of the information that led to what seems to be the resolution to this problem.  Along with the fact that he put in the most effort to help scarm.

CShenberger