scarm
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\stchec k.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.
:\>
I'm using the following command
psexec \\computername -c \\23usacb90\netapps\stchec
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.
:\>
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\stchec k.vbs \\colgate-ff4eb13\Admin$\s ystem32
psexec \\colgate-ff4eb13 cscript.exe stcheck.vbs
del \\colgate-ff4eb13\Admin$\s ystem32\st check.vbs
Example:
@echo off
copy \\23usacb90\netapps\stchec
psexec \\colgate-ff4eb13 cscript.exe stcheck.vbs
del \\colgate-ff4eb13\Admin$\s
Maybe try:
psexec \\computername [flags] wscript.exe stcheck.vbs
psexec \\computername [flags] wscript.exe stcheck.vbs
ahhhh you people are fast - this was blank when I started!
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
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("Scriptin g.FileSyst emObject")
set fi=fso.OpenTextFile("D:\Te mp\test.tx t", 2, true)
fi.WriteLine("PsExec Test")
set fi=nothing
set fso=CreateObject("Scriptin
set fi=fso.OpenTextFile("D:\Te
fi.WriteLine("PsExec Test")
set fi=nothing
Keep in mind AV's hate vbs scripts.
Might be an AV stopping the execution.
Might be an AV stopping the execution.
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\stche ck.vbs"
PsExec v1.56 - Execute processes remotely
Copyright (C) 2001-2004 Mark Russinovich
Sysinternals - www.sysinternals.com
Password:
PsExec could not start \\23usacb90\netapps\stchec k.vbs on colgate-ff4eb13:
Logon failure: unknown user name or bad password.
" 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\stche
PsExec v1.56 - Execute processes remotely
Copyright (C) 2001-2004 Mark Russinovich
Sysinternals - www.sysinternals.com
Password:
PsExec could not start \\23usacb90\netapps\stchec
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\stchec k.vbs \\colgate-ff4eb13\Admin$\s ystem32
psexec \\colgate-ff4eb13 cscript.exe stcheck.vbs
del \\colgate-ff4eb13\Admin$\s ystem32\st check.vbs
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\stchec
psexec \\colgate-ff4eb13 cscript.exe stcheck.vbs
del \\colgate-ff4eb13\Admin$\s
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
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
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.LocalM achine")
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:{ impersonat ionLevel=i mpersonate }!\\" & _
strComputer & "\root\default:StdRegProv" )
strKeyPath = "SOFTWARE\Microsoft\Window s\CurrentV ersion\App Paths\notes.exe"
strValueName = "Path"
On Error Resume Next
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyP ath,strVal ueName,str Value
NotesPath = strValue
'------------------ Get file date of nstclientu.dll -------------------------- ---
'Gets Path, Date, and Version
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
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.Fi leSystemOb ject")
Set objTextFile = objFSO.OpenTextFile _
("\\23usacb90\netapps\same timelog\st log.txt", ForAppending, True)
objTextFile.WriteLine(Writ eLine1)
objTextFile.Close
--------------------------
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Dim NotesPath, WriteLine1, FVer, FPath, FDate, CName, CUser
strComputer = "."
Set objComputer = CreateObject("Shell.LocalM
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:{
strComputer & "\root\default:StdRegProv"
strKeyPath = "SOFTWARE\Microsoft\Window
strValueName = "Path"
On Error Resume Next
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyP
NotesPath = strValue
'------------------ Get file date of nstclientu.dll --------------------------
'Gets Path, Date, and Version
Set objFSO = CreateObject("Scripting.Fi
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.Fi
Set objTextFile = objFSO.OpenTextFile _
("\\23usacb90\netapps\same
objTextFile.WriteLine(Writ
objTextFile.Close
ASKER
anything????
Try to specify user name and password (-u and -p) in the command line
@echo off
copy \\23usacb90\netapps\stchec k.vbs \\colgate-ff4eb13\Admin$\s ystem32
psexec -u SomeDomain\SomeUser -p SomePassword \\colgate-ff4eb13 cscript.exe stcheck.vbs
del \\colgate-ff4eb13\Admin$\s ystem32\st check.vbs
To do this for a list of machines, use
@echo off
for /f %%a in ('type "MachineList.txt"') do (
copy \\23usacb90\netapps\stchec k.vbs \\%%a\Admin$\system32
psexec -u SomeDomain\SomeUser -p SomePassword \\%%a cscript.exe stcheck.vbs
del \\%%a\Admin$\system32\stch eck.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\stchec k.vbs \\colgate-ff4eb13\Admin$\s ystem32
psexec -u SomeDomain\SomeUser -p SomePassword \\colgate-ff4eb13 cscript.exe stcheck.vbs
del \\colgate-ff4eb13\Admin$\s ystem32\st check.vbs
type \\colgate-ff4eb13\C$\stlog .txt >>"\\23usacb90\netapps\sam etimelog\s tlog.txt"
del \\colgate-ff4eb13\C$\stlog .txt
On the other hand: If it's working in the logon script, why use psexec?
@echo off
copy \\23usacb90\netapps\stchec
psexec -u SomeDomain\SomeUser -p SomePassword \\colgate-ff4eb13 cscript.exe stcheck.vbs
del \\colgate-ff4eb13\Admin$\s
To do this for a list of machines, use
@echo off
for /f %%a in ('type "MachineList.txt"') do (
copy \\23usacb90\netapps\stchec
psexec -u SomeDomain\SomeUser -p SomePassword \\%%a cscript.exe stcheck.vbs
del \\%%a\Admin$\system32\stch
)
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\stchec
psexec -u SomeDomain\SomeUser -p SomePassword \\colgate-ff4eb13 cscript.exe stcheck.vbs
del \\colgate-ff4eb13\Admin$\s
type \\colgate-ff4eb13\C$\stlog
del \\colgate-ff4eb13\C$\stlog
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:{ impersonat ionLevel=i mpersonate }!\\" & _
strComputer & "\root\default:StdRegProv" )
strKeyPath = "SOFTWARE\Microsoft\Window s\CurrentV ersion\App Paths\notes.exe"
strValueName = "Path"
On Error Resume Next
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyP ath,strVal ueName,str Value
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.Netw ork")
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.
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:{
strComputer & "\root\default:StdRegProv"
strKeyPath = "SOFTWARE\Microsoft\Window
strValueName = "Path"
On Error Resume Next
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyP
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.Netw
objNetwork.MapNetworkDrive
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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%
>>"%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
CShenberger
ASKER