Last active
January 13, 2023 23:03
-
-
Save markgodiy/4ff859ee06197d4bb9c2d949eeefd4bf to your computer and use it in GitHub Desktop.
Write PowerShell code within a windows scripting file (.wsf) script. Useful for PowerShell GUI, and scripts that do not require elevated privileges.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script language="VBScript"> | |
| '<).job.powershell | Invoke-Expression""" | |
| If CreateObject("WScript.Shell").Run("powershell -noexit -command ""([xml](Get-Content '" & WScript.ScriptFullName & "')).job.powershell.'#cdata-section' | Invoke-Expression""",2, False) Then | |
| MsgBox "Script failed to run." | |
| End If | |
| ']]></script><powershell><![CDATA[ | |
| #-------------------- BEGIN POWERSHELL CODE -------------------- | |
| Add-Type -AssemblyName System.Windows.Forms | |
| $FileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{ InitialDirectory = [Environment]::GetFolderPath('Desktop') } | |
| [void]$FileBrowser.ShowDialog() | |
| $message = "You chose the file: $($FileBrowser.FileName)" | |
| Invoke-WmiMethod -Class win32_process -ComputerName $env:COMPUTERNAME -Name create -ArgumentList "c:\windows\system32\msg.exe * $message" | |
| Exit | |
| #-------------------- END POWERSHELL CODE -------------------- | |
| ]]></powershell></job> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment