Results 1 to 5 of 5

Thread: run ProcessStartInfo as hidden

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2008
    Posts
    72

    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?

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Apr 2008
    Posts
    72

    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

  3. #3
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    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.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    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.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: run ProcessStartInfo as hidden

    By the way, you may like the more verbose option but this:
    vb.net Code:
    1. Dim psi As New ProcessStartInfo()
    2.  
    3. psi.Verb = "runas"
    4. psi.FileName = ("cmd.exe")
    5. psi.Arguments = "/k " & "C:\temp\value1.bat"
    could be written like this:
    vb.net Code:
    1. 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
  •  



Click Here to Expand Forum to Full Width