Running Console application on remote server

The program is intended to run on the client computers...

I've got a .NET Form setup to request the user's name and password.  When the user clicks the Form's command button, the code runs a batch file on the remote server which then sets variables and starts an executable file in the console window.  The executable file (FilePro) is console based.

I've got everything working except the console window closes as soon as the batch file completes.  
I NEED to keep the console window open.

Also, on the "WaitForExit" line of code.  What is it waiting for to close: cmd.exe or the executable file (FilePro)?

P.S. Remote Desktop Connecting into the server and running the batch file is the only way I can get the executable file to open in a console window and stay open.
Private Sub StartBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartBtn.Click

        ' *Testing using hardcoded username and password
        Dim fp As Diagnostics.Process = New Diagnostics.Process
        fp.StartInfo.UserName = "########" 'TxtUNAME.ToString
        fp.StartInfo.Domain = "ABCDEFG"  'Environment.UserDomainName.ToString

        Dim spwd As New System.Security.SecureString
        Dim pwd As String = "********" 'TxtPWORD.ToString

        Array.ForEach(pwd.ToCharArray(), AddressOf spwd.AppendChar)
        fp.StartInfo.Password = spwd



        fp.StartInfo.FileName = "\\servername\c$\FP_Logins\DefaultUser.bat"
        fp.StartInfo.UseShellExecute = False
        'fp.StartInfo.RedirectStandardOutput = True

        fp.StartInfo.CreateNoWindow = False

        fp.Start()

        fp.WaitForExit()
        fp.Close()
End Sub

Open in new window

shelbyinfotechAsked:
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.

dougaugCommented:
Could you post the code of DefaultUser.bat here?
0
shelbyinfotechAuthor Commented:
@echo on
rem This File created by install shield on 9-24-2008
set PATH=c:\windows\system32
set PFDSK=C
set PFDATA=C:
set PFPROG=C:\appl
set PFDIR=\appl
rem set PFMENU=C:\appl\fp\menus  changed on 4/6/10
set PFMENU=C:\fp\menus
set PFGLOB=
set PFCONFIG=
set PATH=%pfprog%;%PFPROG%\fp;%path%
echo stuff > fp$$$$$$.bat
del fp$$*.bat>NUL
rem %pfprog%\fp\p.exe
%pfprog%\fp\p ARA
0
SStoryCommented:
I think you should execute cmd.exe with args of
/K  \\servername\c$\FP_Logins\DefaultUser.bat

However UNC paths may not work from the command-line.
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

shelbyinfotechAuthor Commented:
Changed code:
        fp.StartInfo.Arguments = "/k \\servername\c$\FP_Logins\Example.bat"
        fp.StartInfo.FileName = "\\servername\c$\WINDOWS\system32\cmd.exe"

DOS window "\\servername\c$\WINDOWS\system32\cmd.exe" attempts to open and I receive error:
"The procedure entry point NeedCurrentDirectoryForExePathW could not be located in the dynamic link library KERNEL32.dll"
0
shelbyinfotechAuthor Commented:
I can run \\servername\c$\FP_Logins\Example.bat from the local cmd.exe window.

On the last line: "C:\appl\fp\p ARA
It says "the system cannot find the path specified"

I wonder if I can change the batch file to specify the servername for the commands?
0
dougaugCommented:
If I've understood, you have the path C:\appl\fp\p on the remote computer.
Since you execute \\servername\c$\FP_Logins\Example.bat from the local computer the above directory is not found because it's referenced on local machine.

Try to change the bat file like this:

@echo on
rem This File created by install shield on 9-24-2008
set PATH=c:\windows\system32
set PFDSK=C
set PFDATA=C:
set PFPROG=\\servername\C:\appl
set PFDIR=\appl
rem set PFMENU=C:\appl\fp\menus  changed on 4/6/10
set PFMENU=C:\fp\menus
set PFGLOB=
set PFCONFIG=
set PATH=%pfprog%;%PFPROG%\fp;%path%
echo stuff > fp$$$$$$.bat
del fp$$*.bat>NUL
rem %pfprog%\fp\p.exe
%pfprog%\fp\p ARA
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
shelbyinfotechAuthor Commented:
I got an error message from the executable file (FilePro) which led me to map a drive to "C:\" on the server and add "Set FPLMHOST=serverIPaddress:6556" after the@echo on line.

I now can run the batch file from the client.  

Now I have to edit the .NET application to map a drive (catch it if it errors out) and then run the batch file.
0
shelbyinfotechAuthor Commented:
Using the mapped drive I can navigate to the folder z:\FP_Logins and run the TestDefaultUser.bat successfully.

However, when I run my application in .net, the console window closes before the code even gets to: "fp.WaitForExit()"

Any way to keep the console window open?
0
dougaugCommented:
Are you receiving any error messages in your .NET application?

Are you still testing with this arguments?

  fp.StartInfo.Arguments = "/k \\servername\c$\FP_Logins\Example.bat"
0
shelbyinfotechAuthor Commented:
I've got it running, but now have some FilePro issues.

I did not use the Argument parameters.
0
dougaugCommented:
Maybe if you use the /k switch the console window doesn't close...
0
SStoryCommented:
/k
is so that the console window won't close.

He said he wanting the batch to run, but the window to stay open.
0
CodeCruiserCommented:
>Any way to keep the console window open?

If its your own console program then add this line to keep the window open

Console.ReadLine

If its the batch file window you want to keep open then add PAUSE at the end of it.
0
SStoryCommented:
What CodeCruiser mentioned is true except that I assumed you wanted the batch to finish and the console to still be open. If so a Pause wouldn't be what you'd want.  If it is your own DOTNET console, then ReadLine would make it wait for input. What is the reason that you wish to leave it open? Is it to see the results?
0
CodeCruiserCommented:
Did my comment answer your question:>Any way to keep the console window open?
0
shelbyinfotechAuthor Commented:
For some reason, my previous comment didn't post.

I had a mapping error in the batch file.  Due to the error, the Console Program would never open, and the window would close.  Once I got the mapping figured out, the window stayed open.

Since it was a batch issue related to drive mapping, I gave "dougaug" the credit with the solution.
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
.NET Programming

From novice to tech pro — start learning today.

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.