-
Jul 9th, 2019, 12:28 PM
#1
Thread Starter
Lively Member
run ProcessStartInfo as hidden
Hey again! I'm trying to figure out how to run the following as hidden:
Code:
Dim psi As New ProcessStartInfo() ' Initialize ProcessStartInfo (psi)
psi.Verb = "runas" ' runas = Run As Administrator
psi.FileName = ("cmd.exe")
psi.Arguments = "/k " & "C:\temp\value1.bat"
Try
Process.Start(psi)
Catch
MsgBox("User cancelled the operation", 16, "") ' User pressed No
End Try
It's not exactly life or death but I'd like to know if it's possible?
-
Jul 9th, 2019, 12:33 PM
#2
Thread Starter
Lively Member
Re: run ProcessStartInfo as hidden
I know the user will be prompted to run it as it's being run as admin but I just don't want the final cmd window to be displayed....... If you get me?
Last edited by theyikes; Jul 9th, 2019 at 12:34 PM.
Reason: poor spelling
-
Jul 9th, 2019, 02:42 PM
#3
Re: run ProcessStartInfo as hidden
I'm surprised that you're using /k to execute the command since that says to keep the cmd process (and its window) available after the command has completed.
I would think you would use /c so when the command is done, the cmd executable and window go away.
That said, you may also want to add psi.CreateNoWindow = True, to see if that keeps the window from showing up.
-
Jul 10th, 2019, 12:28 AM
#4
Re: run ProcessStartInfo as hidden
You also need to set UseShellExecute to False or else CreatNoWindow will be ignored. I think that you can set WindowStyle to Hidden if UseShellExecute is True.
-
Jul 10th, 2019, 12:31 AM
#5
Re: run ProcessStartInfo as hidden
By the way, you may like the more verbose option but this:
vb.net Code:
Dim psi As New ProcessStartInfo() psi.Verb = "runas" psi.FileName = ("cmd.exe") psi.Arguments = "/k " & "C:\temp\value1.bat"
could be written like this:
vb.net Code:
Dim psi As New ProcessStartInfo("cmd", "/k C:\temp\value1.bat") With {.Verb = "runas"}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|