Data is not getting appended to the text file as expected when running LiveUpdate on Remote Server

I'm trying to execute the following command so I can get output data regarding "Psexec.exe" error result but it will not pipe the screens output data to the file. Could someone please verify my syntax or let me know if there's another way to do it?
Second, I'm eventually going to port this MS-DOS Syntax over into a VBScript. Please see VBScript code below to get an idea of what I'm doing.
Thank you Experts,
Wallace
------- MS-DOS Command to run LiveUpdate and append to text file----------- 
Syntax #1 
H:\>\\Server01\c$\windows\system32\psexec.exe \\Server01 -accepteula -i -u 
 Domain1\so_User1 -p APassword cmd /c "c:\program files\symantec antivirus\vpdn 
_lu.exe" /f Update /s > SavLuText.txt 
Syntax #2 
C:\>cmd /c \\Server01\c$\windows\system32\psexec.exe -accepteula -i -u Domain1 
\User1 -p APassword \\Server01 "c:\program files\symantec antivirus\vpdn 
_lu.exe" /f Update /s > livupd.txt 
--------- VBScript to automate LiveUpdate update ------------ 
'On Error Resume Next 
 
Set objShell = CreateObject("WScript.Shell") 
Set objFSO = CreateObject("Scripting.FileSystemObject") 
 
strParentPath = objFSO.GetParentFolderName(WScript.ScriptFullName) 
strServers = WScript.Arguments.Item(0) 
strFilePath = strParentPath & "\" & strServers 
 
Set objInputFile = objFSO.OpenTextFile(strFilePath, 1) 
 
strDomain = InputBox("Enter Domain: ") 
strUsername = InputBox("Enter Username: ") 
strPassword = InputBox("Enter Password: ") 
 
If IsEmpty (strDomain) Or IsEmpty (strUsername) Or IsEmpty (strPassword) Then 
        WScript.Echo "Your Domain, Username and Password are required to process this script." 
        WScript.Quit 
End If 
 
Do While objInputFile.AtEndOfStream <> True 
        strServer = "" 
        strServer = objInputFile.ReadLine 
         
        strPsExecPath = "\\" & strServer & "\c$\Windows\System32\psexec.exe " 
         
        If Not (objFSO.FileExists(strPsExecPath)) Then 
                objFSO.CopyFile "c:\psexec.exe", strPsExecPath, True 
                If Not objFSO.FileExists("c:\psexec.exe") Then 
                        WScript.Echo "Psexec.exe file does not exit on local PC." & vbCrLf & _ 
                        "Unable to copy to destination server " & "" & strServer & "" & "." 
                End If 
        End If 
         
        If Not IsNull(strServer) Then 
                Set objLocator = CreateObject("WbemScripting.SWbemLocator") 
                Set objWMIService = objLocator.ConnectServer(strServer, "\root\cimv2", strDomain & _ 
                                                        "\" & strUsername, strPassword) 
                objWMIService.Security_.ImpersonationLevel = 3 
                objWMIService.Security_.AuthenticationLevel = 6 
                 
                objName = objFSO.GetTempName() 
                objTempFile = objName 
                 
'               WScript.Echo """" & "cmd /k " & strPsExecPath & " \\" & strServer & " -accepteula " & " -e -i -u " & _ 
'                                               strDomain & "\" & strUsername & " -p " & strPassword & " CMD > " & _ 
'                                                       objTempFile, 1, True & """" 
                WScript.Echo strPsExecPath & "\\" & strServer & " -accepteula" & " -i -u " & _ 
                                                strDomain & "\" & strUsername & " -p " & strPassword & " cmd /c " & _ 
                                                        """c:\program files\symantec antivirus\vpdn_lu.exe"" /f Update /s > " & _ 
                                                                objTempFile, 1, True 
                objShell.Run strPsExecPath & "\\" & strServer & " -accepteula" & " -i -u " & _ 
                                                strDomain & "\" & strUsername & " -p " & strPassword & " cmd /c " & _ 
                                                        """c:\program files\symantec antivirus\vpdn_lu.exe"" /f Update /s > " & _ 
                                                                objTempFile, 1, True 
                                                         
                Set objTempTextFile = objFSO.OpenTextFile(objTempFile, 1) 
                 
                Do While objTempTextFile.AtEndOfLine <> True 
                        strResults = objTempTextFile.ReadAll 
                        If InStr(strResults, "error code 0") > 0 Then 
                                WScript.Echo "Uninstall execution successful." 
                                Exit Do 
                        Else 
                                WScript.Echo "Uninstall execution unsuccessful." 
                        End If 
                Loop 
        '       strPsExecPath & "\\" & strServer & " -accepteula " & " -e -i -u " & strDomain & "\" & strUsername & _ 
        '       " -p " & strPassword & " MsiExec.exe /norestart /q /x " & strSavSubKey & " REMOVE=ALL" , 1, True 
        objTempTextFile.Close 
        objFSO.DeleteFile objTempFile, True 
        Set objTempTextFile = Nothing 
        objName = vbEmpty 
        objTempFile = vbEmpty 
        strResults = vbEmpty 
        strPsExecPath = vbEmpty 
        End If 
Loop

Open in new window

wally_davisAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tighecCommented:
Are you just trying to get the return code from psexec?  Or the output from the exe that you are executing remotely?
After psexec.exe returns check %errorlevel% for the return code.  When you use > after the psexec line you will just get the output from the command you execute (if it is a command line executable), not the actual return code per se.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
wally_davisAuthor Commented:
Well my hope was to get the output from the psexec I ran remotely. I thought that running cmd /c on the remote server would work. Isn't there a way to get that output from the command I execute?
For instance, if I go to the Command prompt and type --> cmd /c "dir c:\" test.txt it works. I thought the same concept would have applied to my code and I would think there has to be a way.
   I opened up a MS-DOS Cmd prompt, typed echo %errorlevel% and it returned 0 right away. I then ran psexec and caused it to fail. I echoed %errorlevel% and I in fact received an error of "1".
Can you set the errorlevel variable to be something else other than 0 or 1? For instance, what psexec runs but something happens on the other end where the update didn't happen and it returned an error of 0. That's just assuming the worst. I don't want to report to my output file that the command issued was successful when it fact it wasn't.
0
wally_davisAuthor Commented:
Sorry, I meant to say if I type  --> cmd /c"dir c:\" > test.txt I get the output saved in the test.txt file.
0
wally_davisAuthor Commented:
Ran some tests and this will work:

retErrLevel = objShell.Run("cmd /c " & strPsExecPath & "\\" & strServer & " -accepteula" & " -i -u " & _
                                     strDomain & "\" & strUsername & " -p " & strPassword & " " & _
                                           """c:\program files\symantec antivirus\vpdn_lu.exe"" /f Update /s", 1, True)
WScript.Echo retErrLevel
Thanks for the pointer Tighec... :)
0
tighecCommented:
You can omit the cmd /c altogether... doesn't affect anything.

Also, don't bother copying psexec.exe to the server, and then execute it from there... just stick it in your own system32 directory and it will work fine:

Also, you could probably simplify it a LOT by sticking with a cmd file rather than a vbscript.
Add the following to a cmd file, might need a little tweaking (I'd suggest running the batc hfile under a user context that has access to the servers, thus eliminating the need to prompt for username and password altogether)

set /P User=Enter your username: (domain\user)
set /P Password=Enter your password: (domain\user)

for /F %%a in servers.txt) DO (
psexec \\%a /U:%USER% /P:%PASSWORD% "c:\program files\symantec antivirus\vpdn_lu.exe" /f Update /s > %%a.log
findstr /I /C:"error code 0" %%a.log
SET RC=%ERRORLEVEL%
If "%RC%"=="0" @ECHO %%a SUCCESSFUL
If "%RC%" NEQ "0" @ECHO %%a NOT SUCCESSFUL
DEL %%a.log

)


0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.