Run console hidden - vb.net

I'm trying to run a console window hidden while using CreateProcess(I can't use the ProcessStartInfo class because I have to run it with some other special settings)
I have tried to use the CREATE_NO_WINDOWS flag, but somehow, the console still pops up. This is the code I have:
Dim ProzessInfo = New Process_Information
Dim StartInfo = New Startup_Information, PS = New Security_Flags, TS = New Security_Flags
If CreateProcess(Nothing, target, PS, TS, False, PROCESS_CREATION_FLAG.CREATE_NO_WINDOW, Nothing, Nothing, StartInfo, ProzessInfo) = 0 Then MsgBox("Couln't start application")
What have I missed to run it hidden?

You may want to try
AppwinStyle.Hide, True
MSDN AppWinStyle
Or
EDIT:
Try This for Processes
Dim psi1 As New ProcessStartInfo("file path here")
Process.CreateNoWindow = True
Depending on what your end goal is you can always change the application type to Windows Forms Application. (Assuming you are running a console app now.)

Related

Error thrown trying launch a webpage from a button

I created a button and a menu item in vb.net (.NET 6). I found several answers here on SO that say the process to launching a webpage from such an event can be launched with this code:
Dim webAddress As String = "http://www.example.com/"
Process.Start(webAddress)
However, trying launch the code, I'm given the error of "system cannot find the file specified".
Looking more into it, I know that .NET 6 is running a bit differently and changed the code to the following:
Using link As New Process()
link.StartInfo.UseShellExecute = True
link.Start(New ProcessStartInfo("https://example.com"))
End Using
But still to no avail, and I am given the same error. "System cannot find the file specified." I can run addresses via the regular Windows Run prompt... but the program still cannot launch.
Following Jimi's comment to my original question, I changed the Sub to the following:
Sub LaunchWebsite(strWebpageURL As String)
Using Process.Start(New ProcessStartInfo(strWebpageURL) With {.UseShellExecute = True})
End Using
End Sub
Using this, the webpage launched in my desktop's default browser with no problem.
You can use
Respone.Redirect("http://www.example.com/")
or use javascript in server side code
Dim url As String = "http://www.example.com"
Dim s As String = "window.open('" & url + "', 'popup_window', 'width=300,height=100,left=100,top=100,resizable=yes');"
ClientScript.RegisterStartupScript(Me.GetType(), "script", s, True)
Above code open webpage in new popup window.
Regards
Aravind

VB.Net Process.Start - Verb

I want my vb.net Program to launch notepad and elevate the credentials however there is no prompt and the program just opens.
Dim process As System.Diagnostics.Process = Nothing
Dim processStartInfo As System.Diagnostics.ProcessStartInfo
processStartInfo = New System.Diagnostics.ProcessStartInfo()
processStartInfo.FileName = "notepad.exe"
processStartInfo.Verb = "runas"
processStartInfo.Arguments = ""
processStartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal
processStartInfo.UseShellExecute = True
process = System.Diagnostics.Process.Start(processStartInfo)
There's a lot of unnecessary code there. You're using two lines to declare and set your two variables when you only need one each time. You're setting the FileName property explicitly when you can pass an argument to the constructor and you're also setting three properties to their default values. I just stripped it down to the bare minimum:
Dim psi As New ProcessStartInfo("notepad.exe") With {.Verb = "runas"}
Dim proc = Process.Start(psi)
When I ran that code from a new WinForms app with just a Button on the form and I got a UAC prompt as expected.

Run Internet Explorer as a different user

I'm trying to launch Internet Explorer with a different user to access a website that requires single sign on.
Below is the code that I'm using. It doesn't produce any errors but IE doesn't launch at all, not even the process.
Try
System.Diagnostics.Process.Start(IExplorerPath, Username, ConvertToSecureString(Password), Domain)
Success = True
Catch ex As Exception
Success = False
Error_Message = ex.Message
End Try
I also tried the following variation with the same result (nothing):
Try
Dim psi As New ProcessStartInfo()
psi.Filename = IExplorerPath
psi.UserName = Username
psi.Domain = Domain
psi.Password = ConvertToSecureString(Password)
psi.UseShellExecute = False
Process.Start(psi)
Success = True
Catch ex As Exception
Success = False
Error_Message = ex.Message
End Try
This is the ConvertToSecureString function:
Function ConvertToSecureString(ByVal str As String)
Dim password As New SecureString
For Each c As Char In str.ToCharArray
password.AppendChar(c)
Next
Return password
End Function
Ok, I've been searching a lot a solution for this and if you have it you deserve a Nobel price. In the mean time, if it helps anyone this is the workaround that I had to use:
Use Process.Start to run a .bat file that contains the following code:
runas /user:User#Domain.com "C:\Program Files\Internet Explorer\iexplore.exe"
Then, when the command prompt appears I use the Send Keys to type in the password and press Enter.
This launches IE with different credentials. But again, there should be a better way.
This may / may not work. Try to launch your website that requires single sign on in "CHROME", hit F-12, go to Application Tab -> Cookies -> Click on your site link. on left hand side look for something that represent your session id, may be JSESSIONID or similar, copy that. Now open your Internet Explorer, hit F-12 and manually create that JSESSIONID by running this command in console window
document.cookie = "JSESSIONID=<your-session-id-from-chrome"
hit play button to execute script
Refresh your browser

Writing to Command Line Not Working

An application I need to use (USB capture utility) has a .cmd version that I can call from my Visual Basic code. I am able to launch the application and put it in "command line mode" like this:
Public Class MyClass
Dim StreamWriteUtility As System.IO.StreamWriter
Dim StreamReadUtility As System.IO.StringReader
Dim ProcessInfo As ProcessStartInfo
Dim Process As Process
Public Sub StartUSBCapture(ByVal DataStorageLocation As String)
Dim ProcessInfo As ProcessStartInfo
Dim Process As New Process
ProcessInfo = New ProcessStartInfo("C:\FW_Qualification_Suite\data-center-windows\data-center\bin\datacenter.cmd", "-c ")
ProcessInfo.CreateNoWindow = True
ProcessInfo.UseShellExecute = False 'Must be changed if redirect set to True
ProcessInfo.RedirectStandardInput = True
Process = Process.Start(ProcessInfo)
SWUtility = Process.StandardInput
While True
SWUtility.WriteLine("run") 'Looping for test to ensure this isn't a timing issue
End While
End Sub
End Class
This launches the application and opens a separate command line window that should accept further commands (i.e., capture, run, stop, etc). However, I am having trouble getting those subsequent commands to show up in the command line window. I've tried redirecting the standard input of the process, but still nothing shows up in the console window.
Can anyone tell how I'm supposed to actually get these commands from my Visual Basic program into this application?

Execute DOS command within console application VB

I need to be able to execute a DOS command, such as 'ipconfig', using a command line application in Visual Basic. I can simply use start.process("CMD", "ipconfig"), but that opens a new instance of CMD. I want to be able to run a command like I would with CMD, using a console application, without opening another CMD window. Thanks!
You can use this to run the ipconfig command in hidden console window and redirect the output to local variable. From here you can manipulate it as needed:
Dim cmdProcess As New Process
With cmdProcess
.StartInfo = New ProcessStartInfo("cmd.exe", "/C ipconfig")
With .StartInfo
.CreateNoWindow = True
.UseShellExecute = False
.RedirectStandardOutput = True
End With
.Start()
.WaitForExit()
End With
' Read output to a string variable.
Dim ipconfigOutput As String = cmdProcess.StandardOutput.ReadToEnd