VB.NET + Powershell

Asked

Viewed 223 times

1

I would like to create a program in VB.NET that runs the following code in Powershell

Get-AppXPackage -AllUsers | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"} 

I created a file . ps1 with this code above and put this way in VS:

Shell("powershell -noexit Start-Process powershell -Verb runAs ""C:\Users\netov\Desktop\teste.ps1""", AppWinStyle.NormalFocus, True)

It runs, calls PS as administrator, but gives the error that the script execution has been disabled on this system and tells me to query about_Execution_Policies

I searched and saw that if I run this command Set-ExecutionPolicy Unrestricted in PS it allows me (after typing’S', for yes) to execute scripts.

The problem is that I can’t run this code by VS. I tried to add it to test.ps1 and also does not execute.

Has anyone been there, or do you have another way to go? I just want to run this Powershell command in a simple way (for ordinary users) in order to solve Windows start problem to work in a few moments.

  • What code can’t run on VS? What exactly is the problem?

  • Want a way to run the command in PS Get-Appxpackage...and I’m trying with the command Shell("powershell ...) as the text above... Would you have some other way? What I want is simple, not so much execution.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.