locked
New line in powershell msgbox nested inside a VBS Script. RRS feed

  • Question

  • Hello, 

    I am trying to add a line break inside the message box, but it seems the usual `n does not work. 

    The script is as follows:

    showASyncMessage "Messge text`nnewline", "Title"
    
    Sub showASyncMessage (myDesc, myTitle)
    
    Const HIDDEN_WINDOW = 12
    Dim strIconType
    Dim strComputer: strComputer = "."
    Dim objWMIService: Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Dim objStartup: Set objStartup = objWMIService.Get("Win32_ProcessStartup")
    Dim objConfig: Set objConfig = objStartup.SpawnInstance_
    objConfig.ShowWindow = HIDDEN_WINDOW
    
    Dim objProcess: Set objProcess = GetObject("winmgmts:{impersonationLevel=impersonate}!Win32_Process")
    objProcess.Create "powershell.exe -executionpolicy bypass -nologo -command [reflection.assembly]::loadwithpartialname('System.Windows.Forms'); " &_ 
    "[System.Windows.Forms.MessageBox]::Show('" & myDesc & "','" & myTitle & "','Ok','Information') ", NULL, objConfig
    Set objWMIService = Nothing
    Set objStartup = Nothing
    Set objConfig = Nothing
    
    End Sub

    But what i get is this: 

    Messge text`nnewline

    (seems i can't upload screenshots yet :( )

    This function will be inserted in a much bigger vbs script. I know i can use a 2nd small vbs or ps1 script and run it asynchronously from the main script, but i would rather do it from one script. 

    Any help will be appreciated. 

    Thanks in advance.

    Wednesday, June 27, 2018 8:11 AM

All replies

  • Try:

    showASyncMessage "Messge text" & vbCrLf & "newline", "Title"


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    Wednesday, June 27, 2018 9:27 AM
  • Thank you, it worked. 

    Come to think about it, it's pretty obvious :)

    Wednesday, June 27, 2018 10:45 AM
  • You are welcome.

    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    Wednesday, June 27, 2018 11:38 AM