Run a VBS Script as Current User that Prompts User for OK

I am trying to package up Symantec Endpoint Encryption… One of the things that needs done prior to install is having a vbs script run which prompts the user to click OK…

Here is the script that runs when clicking ok:

'   Copyright (C) 2014 Symantec Corporation. All rights reserved.
'
' THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE SECRETS OF SYMANTEC
' CORPORATION.  USE, DISCLOSURE OR REPRODUCTION IS PROHIBITED WITHOUT THE PRIOR
' EXPRESS WRITTEN PERMISSION OF SYMANTEC CORPORATION.
'
'  The Licensed Software and Documentation are deemed to be commercial computer
'  software as defined in FAR 12.212 and subject to restricted rights as defined
'  in FAR Section 52.227-19 "Commercial Computer Software - Restricted Rights"
'  and DFARS 227.7202, "Rights in Commercial Computer Software or Commercial
'  Computer Software Documentation", as applicable, and any successor
'  regulations.  Any use, modification, reproduction release, performance,
'  display or disclosure of the Licensed Software and Documentation by the
'  U.S. Government shall be solely in accordance with the terms of this
'  Agreement.
'
'  Modified to only shutdown processes.

Const DISPLAYTIME = 1



Set objShell = Wscript.CreateObject( "WScript.Shell" )
Set WshShell = Wscript.CreateObject( "WScript.Shell" )

Set objFSO = CreateObject("Scripting.FileSystemObject")

objShell.Popup "ATTENTION: This install will stop and close PGP AND OUTLOOK. Please Save and close anything you need to prior to Clicking OK to Continue."

' Check to see if tray is running
trayRunning = 0
Set netob = CreateObject( "Wscript.Network" )
Set service = GetObject ("winmgmts:")
For Each Process in Service.InstancesOf ("Win32_Process")
	If (Process.Name = "PGPtray.exe") Or (Process.Name = "PGPdesk.exe") Or (Process.Name="OUTLOOK.EXE") Then
		pOwner = Process.GetOwner(userName, userDomain)
		' Only kill the process if we own it
		If userName = netob.UserName Then
				trayPath = Process.ExecutablePath
			End If
			If Process.Terminate() <> 0 Then
				Wscript.echo "ERROR: Unable to kill process " & Process.Name & ", cannot continue; Please Contact Helpdesk for assistance."
				Wscript.quit
			End If
			trayRunning = 1
		End If
Next

dim filesys
 Set filesys = CreateObject("Scripting.FileSystemObject") 
 dim strdir 
 set WshShell2 = WScript.CreateObject("WScript.Shell")

'pgp corporation folder  backup and if desired deletion
 strdir = WshShell2.ExpandEnvironmentStrings("%appdata%")
 dim strdir2
 strdir2 = strdir & "\PGP Corporation\PGP"
 dim strdir3
 strdir3 = strdir2  & "_" & Right("0" & Month(Now), 2) & "-" & Right("0" & Day(Now), 2) & "-" & Year(Now) & "-" & Hour(Now) & "-" & Minute(Now)
 
 If filesys.FolderExists(strdir2) Then
  If filesys.FolderExists(strdir3) Then
    filesys.DeleteFolder strdir3
  End If
  filesys.CopyFolder strdir2, strdir3 
	' uncomment following line if you need to delete the PGP Corporation\PGP folder.
	'filesys.DeleteFolder strdir2
 End If


'delete user\pgp backup and if desired deletion folder

 strdir = WshShell2.ExpandEnvironmentStrings("%USERPROFILE%")
 strdir2 = strdir & "\PGP"
 strdir3 = strdir2  & "_" & Right("0" & Month(Now), 2) & "-" & Right("0" & Day(Now), 2) & "-" & Year(Now) & "-" & Hour(Now) & "-" & Minute(Now)
 
 If filesys.FolderExists(strdir2) Then
  If filesys.FolderExists(strdir3) Then
    filesys.DeleteFolder strdir3
  End If
  filesys.CopyFolder strdir2, strdir3 
	' uncomment following line if you need to delete the user\PGP folder.
	'filesys.DeleteFolder strdir2
 End If
 

I would just use PSADT’s feature of closing applications but this script appears to do a little more…

I tried using this code:

Execute-ProcessAsUser -Path 'cscript.exe' -Parameters '"$dirSupportFiles\Close_PGP_outlook.vbs"'

Here is the output:

[Pre-Installation] :: Create scheduled task to run the process [cscript.exe "$dirSupportFiles\Close_PGP_outlook.vbs"] as the logged-on user [Domain\User]...	Execute-ProcessAsUser	6/24/2020 3:17:15 PM	105288 (0x19B48)
[Pre-Installation] :: [C:\WINDOWS\System32\schtasks.exe] is a valid fully qualified path, continue.	Execute-Process	6/24/2020 3:17:15 PM	105288 (0x19B48)
[Pre-Installation] :: Working Directory is [C:\WINDOWS\System32].	Execute-Process	6/24/2020 3:17:15 PM	105288 (0x19B48)
[Pre-Installation] :: Executing [C:\WINDOWS\System32\schtasks.exe /create /f /tn PSAppDeployToolkit-ExecuteAsUser /xml "C:\Users\Public\PSAppDeployToolkit\PSAppDeployToolkit-ExecuteAsUser.xml"]...	Execute-Process	6/24/2020 3:17:15 PM	105288 (0x19B48)
[Pre-Installation] :: Execution completed with exit code [0].	Execute-Process	6/24/2020 3:17:15 PM	105288 (0x19B48)
[Pre-Installation] :: Trigger execution of scheduled task with command [cscript.exe "$dirSupportFiles\Close_PGP_outlook.vbs"] as the logged-on user [Domain\user]...	Execute-ProcessAsUser	6/24/2020 3:17:15 PM	105288 (0x19B48)
[Pre-Installation] :: [C:\WINDOWS\System32\schtasks.exe] is a valid fully qualified path, continue.	Execute-Process	6/24/2020 3:17:15 PM	105288 (0x19B48)
[Pre-Installation] :: Working Directory is [C:\WINDOWS\System32].	Execute-Process	6/24/2020 3:17:15 PM	105288 (0x19B48)
[Pre-Installation] :: Executing [C:\WINDOWS\System32\schtasks.exe /run /i /tn PSAppDeployToolkit-ExecuteAsUser]...	Execute-Process	6/24/2020 3:17:15 PM	105288 (0x19B48)
[Pre-Installation] :: Execution completed with exit code [0].	Execute-Process	6/24/2020 3:17:15 PM	105288 (0x19B48)
[Pre-Installation] :: Delete scheduled task [PSAppDeployToolkit-ExecuteAsUser].	Execute-ProcessAsUser	6/24/2020 3:17:16 PM	105288 (0x19B48)
[Pre-Installation] :: [C:\WINDOWS\System32\schtasks.exe] is a valid fully qualified path, continue.	Execute-Process	6/24/2020 3:17:16 PM	105288 (0x19B48)
[Pre-Installation] :: Working Directory is [C:\WINDOWS\System32].	Execute-Process	6/24/2020 3:17:16 PM	105288 (0x19B48)
[Pre-Installation] :: Executing [C:\WINDOWS\System32\schtasks.exe /delete /tn PSAppDeployToolkit-ExecuteAsUser /f]...	Execute-Process	6/24/2020 3:17:16 PM	105288 (0x19B48)
[Pre-Installation] :: Execution completed successfully with exit code [0].	Execute-Process	6/24/2020 3:17:16 PM	105288 (0x19B48)

I do see a window flash quickly but no option to click OK…

Any ideas? Thanks

Do you use two sets of quotes for parameters or it just isn’t displayed correctly?

Also, displaying a simple window can be done through one line in powershell even without our toolkit.
The script above is displaying a window about closing processes, then closes them and after that its removing 2 folders. You dont have to run under the user nor use this script.

Thanks a lot for the reply… Yea, I figured I could just display the window with PSADT and have it close the 3 processes…

What I don’t know how to do is what the rest of the script is doing which is deleting folders, creating folders with date, etc, as the current user…

The script I believe is running… Here’s my PSADT code that happens preinstall…

Execute-ProcessAsUser -Path 'cscript.exe' -Parameters '"$dirSupportFiles\Close_PGP_outlook.vbs"'

Do I have too many quotes? I have -Parameters then (i’ll put spaces in between):

’ " $dirSupportFiles\Close_PGP_outlook.vbs" ’

Well double quotes allow variables expansion. Single quotes don’t.

>$text = "foo"

>'$text'
$text

>"$text"
foo

For closing processes you can use Show-InstallationWelcome -CloseApps “outlook”.
For the name - You can just get the name of the logged in user and put their name in the path. For date time in the name you can just use Get-Date -Format to format it and save into a variable and then just put it inside the path. Test-Path to verify it exists before copying and youre done.

If you want to see a “prompt” from a VBS you need to use wscript.exe and not cscript.
cscript is a console application, so you would have to run it from CMD and it would show you the output and/or prompt in cmd.
While wscript.exe is a Windows application which will show you an actual prompt.

That being said…
Everything this VBS script does can be easily scripted in PSAD.
The prompt, the closure of application (with a dialogue to the user if you want), the creation and deletion of folders (yes, even folders in the %userprofile%)

This should do the same as what your VBS does…
Maybe needs some finetuning. Don’t really have time to look any further.

        Show-InstallationPrompt `
            -Title "ATTENTION: Symantec Endpoint Encryption" `
            -MessageAlignment Left `
            -Message "ATTENTION: This install will stop and close PGP AND OUTLOOK.`n`nPlease Save and close anything you need to prior to Clicking OK to Continue." `
            -ButtonRightText "OK" `
            -Icon Information `
            -Timeout 150 `
            -ExitOnTimeout $false

        Show-InstallationWelcome -CloseApps 'PGPdesk,OUTLOOK' -PersistPrompt -CloseAppsCountdown 900 -PromptToSave


        $loggedonUser = Get-LoggedOnUser | select -ExpandProperty UserName
        $pgpcorporationfolder = [System.IO.Path]::Combine('C:\Users\', $loggedonUser,'Appdata', 'Roaming', 'PGP Corporation', 'PGP')
        $userpgp = [System.IO.Path]::Combine('C:\Users\', $loggedonUser,'PGP')

        if (Test-Path $pgpcorporationfolder) {
            Remove-Folder $pgpcorporationfolder
        }

        if (Test-Path $userpgp) {
            Remove-Folder $userpgp
        }

btw…
if you want to test this…

Open Powershell ISE (or VSCode) as Admin.
Open Deploy \AppDeployToolkit\AppDeployToolkitMain.ps1
Run this script. It will load all functions and cmdlets of the toolkit.

Now open Deploy-Application.ps1 and you can test your code.
You can run each line individually if you like.