How can i execute a batch file
ive tried it with the shell function: Shell("c:\text.bat")
but i keep getting a file not found error.
is there another way for executing an batch file
thanks
How can i execute a batch file
ive tried it with the shell function: Shell("c:\text.bat")
but i keep getting a file not found error.
is there another way for executing an batch file
thanks
you should not be using shell but use the .NET Framework classes otherwise you are sticking to old (and some buggy) methods and defeating the purpose of upgrading and using the .NET Framework.
you should be using the Process class in the System.Diagnostics namespace like so:
System.Diagnostics.Process.Start("C:\text.bat")
Hope this helps!
hi,
it works but is it possible to add a window style = hidden propperty
what i want to do with the code is run the batch file with username/pass propperty and hidden.
thanks
yes it is, just set the WindowStyle Property like so....
Dim psi as new System.Diagnostics.ProcessStartInfo("C:\test.bat")
psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden
System.Diagnostics.Process.Start(psi)
hope this helps ;-)
thanks for your reply
ive come up with the following code:
Dim psi As New System.Diagnostics.ProcessStartInfo("C:\test.bat")
psi.UserName =
"test"psi.Password =
New System.Security.SecureString() For Each c As Char In "test"psi.Password.AppendChar(c)
Nextpsi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden
psi.UseShellExecute =
FalseSystem.Diagnostics.Process.Start(psi)
it launches the application with the username and password but the window shows up again even with the processwindowstyle.hidden propperty
try setting the "CreateNoWindow" property to true in the psi object.
psi.CreateNoWindow = true
thanks for your reply
it still doesnt work.
is it possible to hide the application after it starts for exaple hide application with title "CMD C:\test.bat"
etc. etc.
I don't understand why it doesnt work for you as it works fine for me - even without the CreateNoWindow property being set to true.
What does the batch file actually do
can you post the code you are using in VB.NET
Dim psi As New System.Diagnostics.ProcessStartInfo("C:\test.bat")
psi.UserName = "test"
psi.Password = New System.Security.SecureString()
For Each c As Char In "test!"
psi.Password.AppendChar(c)
Next
psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden
psi.UseShellExecute = False
psi.CreateNoWindow = True
System.Diagnostics.Process.Start(psi)
I see. It helps when you explain every thing ;-)
The reason is because the batch file is running other exe files which causes it to "pop" up in the same window.
will see what else I can find
If I remember correctly, you could use the ShowWindow and give it the SW_HIDE parameter to it to hide the window when you use the FindWindow method. These methods are part of the Win32 API however I would advise not to use them unless absolutely necessary as these are "old" functions which means going deep down into Windows (in a sense) and invoking them - can cause performance issues sometimes. Better to try and do everything in the .NET Framework as much as possible.
http://www.pinvoke.net/default.aspx/user32/FindWindow.html (first find the window)
http://www.pinvoke.net/default.aspx/user32/ShowWindow.html (then hide it)
http://www.pinvoke.net/default.aspx/Constants/SW.html (give ShowWindow the SW_HIDE constant)
try not using UseShellExecute property at all - what happens if you do that (dont use it at all, comment it out)
Use the above docs/links to implement the ShowWindow and FindWindow API's - this should then hide the window
hmm yes of course, forgot about that, as you are providing those credentials.
Can you try and implement the Win32 API's suggested and see if that helps, that should now hide the window if you implemented it correctly :-)