How to start outlook minimized (vb.net) - vb.net

Following code starts excel minimized.
Dim psi As New ProcessStartInfo("excel.exe")
psi.WindowStyle = ProcessWindowStyle.Minimized
Process.Start(psi)
Following code starts notepad minimized.
Dim psi As New ProcessStartInfo("notepad.exe")
psi.WindowStyle = ProcessWindowStyle.Minimized
Process.Start(psi)
Following code does not start outlook minimized.
Dim psi As New ProcessStartInfo("outlook.exe")
psi.WindowStyle = ProcessWindowStyle.Minimized
Process.Start(psi)
Why?
Related link: (C#)
How to start Outlook minimized?

Related

The process tried to write to a nonexistent pipe vb.net

I'm currently writing a sub in vb.net that is supposed to create and/or erase tasks in the task scheduler that comes with windows 10. The creation part works fine, but when I try to erase the task I get this error in the visual studio console: "The process tried to write to a nonexistent pipe", and the task is (of course) still there. I've looked for a solution but can't find anything similar. Here is the code:
Private Sub SimpleButton2_Click(sender As Object, e As EventArgs) Handles sbAutoRun.Click
Dim CMDThread As New Threading.Thread(AddressOf CMDAutomate)
CMDThread.Start()
End Sub
Private Sub CMDAutomate()
Dim myprocess As New Process
Dim StartInfo As New System.Diagnostics.ProcessStartInfo
Dim sTime As String = teAutoRun.Time.ToString("HH:mm")
Dim sCmdCommand As String = "SCHTASKS /CREATE /SC DAILY /TN ""MyTasks\task"" /TR ""'" & My.Application.Info.DirectoryPath & "\program.exe' Auto"" /ST " & sTime & " /RL HIGHEST"
Dim sCmdCommand2 As String = "SCHTASKS /DELETE /TN ""MyTasks\task"""
My.Settings.AutoRun = ceAutoRun.Checked
StartInfo.FileName = "cmd" 'starts cmd window
StartInfo.RedirectStandardInput = True
StartInfo.RedirectStandardOutput = True
StartInfo.CreateNoWindow = True '<---- if you want to not create a window
StartInfo.UseShellExecute = False 'required to redirect
myprocess.StartInfo = StartInfo
myprocess.Start()
Dim SR As System.IO.StreamReader = myprocess.StandardOutput
Dim SW As System.IO.StreamWriter = myprocess.StandardInput
If My.Settings.AutoRun And Not My.Settings.AutoRunExists Then
SW.WriteLine(sCmdCommand)
My.Settings.AutoRunExists = True
Console.WriteLine(sCmdCommand)
ElseIf My.Settings.AutoRun And My.Settings.AutoRunExists Then
SW.WriteLine(sCmdCommand2)
SW.WriteLine("y")
SW.WriteLine(sCmdCommand)
Else
SW.WriteLine(sCmdCommand2)
SW.WriteLine("y")
My.Settings.AutoRunExists = False
Console.WriteLine(sCmdCommand2)
End If
SW.WriteLine("exit") 'exits command prompt window
SW.Close()
SR.Close()
My.Settings.Save()
End Sub
Thanks..
Ps: The commands work fine when entered by hand in the cmd.
Update: Changed this
sCmdCommand2 As String = "SCHTASKS /DELETE /TN ""MyTasks\task"""
SW.WriteLine(sCmdCommand2)
SW.WriteLine("y")
and wrote it like this
sCmdCommand2 As String = "SCHTASKS /DELETE /TN ""MyTasks\task"" /F"
SW.WriteLine(sCmdCommand2)
Now it works fine.

VB.Net: Unable to get Standard Output from cmd Process.start over network

I'm encountering an issue with the Process.start() method in VB.Net.
I'm trying to execute an ipconfig /all and set a variable with the StandardOutput.ReadToEnd() method.
It works well if I execute the application locally, but when I place the EXE on a network share, my variable is not set with the result of the command.
It seems it cannot retrieve the output of the command.
Can you please help me?
Thank you in advance.
Here is my code:
Dim p As New Process
Dim psi As New ProcessStartInfo
psi.FileName = "cmd.exe"
psi.Arguments = "/c ipconfig /all"
psi.UseShellExecute = False
psi.RedirectStandardOutput = True
p.StartInfo = psi
p.Start()
Dim output As String = p.StandardOutput.ReadToEnd
p.WaitForExit()
MsgBox(output)

VB.net Launcher Application Error

i've been created launcher application with vb.net, but when the target application began, there was an error "Can not Read Start.ini file".
I tried with this code
Dim psi As New ProcessStartInfo()
With psi
.FileName = sb.ToString
.UseShellExecute = True
End With
Process.Start(psi)
how to fix it ?
Daniel probably has it right. Try setting the WorkingDirectory property based off your FileName:
Dim psi As New ProcessStartInfo()
With psi
.FileName = sb.ToString
.WorkingDirectory = System.IO.Path.GetDirectoryName(.FileName)
.UseShellExecute = True
End With
Process.Start(psi)

Need to prompt user for UAC when attempting to open a share using Process.Start

This works, if the current user has rights to the UNC path. Opens it right up.
Process.Start("\\USERSHARE\VALUE\EMPLOYEES\")
However, I have to run the entire program as a user that doesn't have access to the UNC path due to SQL permissions in the code.
I made a button in the app that will open the UNC path in an explorer window, but I cannot figure out how to force a runas for the operation.
I have tried the following as well:
Dim procStartInfo As New ProcessStartInfo
Dim procExecuting As New Process
With procStartInfo
.UseShellExecute = True
.FileName = "Notepad.exe"
.WindowStyle = ProcessWindowStyle.Normal
.Verb = "runas" 'add this to prompt for elevation
End With
procExecuting = Process.Start(procStartInfo)
This works and prompts with UAC to open "notepad".
This doesn't work to open the UNC path:
Dim procStartInfo As New ProcessStartInfo
With procStartInfo
.UseShellExecute = True
.FileName = "\\USERSHARE\VALUE\EMPLOYEES\"
.WindowStyle = ProcessWindowStyle.Normal
.Verb = "runas" 'add this to prompt for elevation
End With
Process.Start(procStartInfo)
I understand opening the fileshare isn't the same as pointing the .FileName at an executable.
I'm having problems trying to have the app prompt for UAC before attempting to open the remote folder.
You don't want to execute the folder itself, but rather explorer.exe with the folder as an argument:
Dim procStartInfo As New ProcessStartInfo
With procStartInfo
.UseShellExecute = True
.FileName = "explorer.exe"
.Arguments = "\\USERSHARE\VALUE\EMPLOYEES\"
.WindowStyle = ProcessWindowStyle.Normal
.Verb = "runas" 'add this to prompt for elevation
End With
Process.Start(procStartInfo)

Run CMD Silently

I'm trying to run CMD silently, but each time I get an error. Could someone please tell me where I'm going wrong?
Dim myProcess As Process
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
myProcess.StartInfo.CreateNoWindow = True
myProcess.StartInfo.FileName = ("cmd.exe" & CmdStr)
myProcess.Start()
CmdStr is already a string to do certain things that I want in the application.
I suppose your cmdStr is a string with parameters for CMD.
If so you need to use the Arguments property of StartInfo.
You get a Null Exception on the myProcess variable because it is never instatiated with new.
You could create a ProcessStartInfo var to use with the static Process.Start method and set the UseShellExecute to False
Dim startInfo As New ProcessStartInfo("CMD.EXE")
startInfo.WindowStyle = ProcessWindowStyle.Hidden
startInfo.CreateNoWindow = True
startInfo.UseShellExecute = False
startInfo.Arguments = CmdStr
Process.Start(startInfo)
or edit your code to add
myProcess = new Process()
before using the var myProcess