Windows 10: Create Shortcut of Hyper-V Virtual Machine in Windows

Discus and support Create Shortcut of Hyper-V Virtual Machine in Windows in Windows 10 Tutorials to solve the problem; I actually have just 3 files now if you include a shortcut to the vbs file. The vbs file looks like this Code: command = "powershell.exe -nologo... Discussion in 'Windows 10 Tutorials' started by Ztruker, Oct 9, 2014.

  1. flybynite Win User

    Create Shortcut of Hyper-V Virtual Machine in Windows


    I actually have just 3 files now if you include a shortcut to the vbs file. The vbs file looks like this Code: command = "powershell.exe -nologo -command %SYSTEMDRIVE%\Customizations\HyperV\StartVM.ps1"set shell = CreateObject("Wscript.Shell") shell.Run command,0[/quote] and the ps1 file is this Code: param([switch]$Elevated) function Test-Admin { $currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent()) $currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator) } if ((Test-Admin) -eq $false) { if ($elevated) { # tried to elevate, did not work, aborting } else { Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition)) } exit } 'running with full privileges' $t = '[DllImport("user32.dll")] public static extern bool ShowWindow(int handle, int state);' add-type -name win -member $t -namespace native [native.win]::ShowWindow(([System.Diagnostics.Process]::GetCurrentProcess() | Get-Process).MainWindowHandle, 0) Start-VM "test" cmd /c %SYSTEMROOT%\System32\vmconnect.exe localhost "test" | Out-Null Stop-VM "test" Stop-Process -processname powershell[/quote] I put a shortcut to the vbs in the same folder, and check run as administrator under properties -> advanced. I pin it to Start.
     
    flybynite, Oct 23, 2016
    #16
  2. SteveFL99 Win User

    Actually, I have found that you only need the .ps1 file. You can run it from a shortcut and get the same behavior. Just make a shortcut to the powershell executable and then go to the shortcut's properties and change the "target" field to call the .ps1 file as follows. (This also overcomes any execution policy issue. And you should also change the "Start in" field to the file directory path.)

    C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File "C:\[file directory path]\StartVM.ps1"

    And even better, to avoid the UAC window popping up every time you run it, make it into a task and then make a shortcut to the task using the instructions here:
    http://www.sevenforums.com/tutorials...pt-create.html

    Follow the instructions, except in steps 7 and 8.

    In step 7, in the "Program" field enter the path to the powershell executable:
    C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

    In step 8, in the "Add Arguments" field enter:
    -ExecutionPolicy Bypass -File "C:\[file directory path]\StartVM.ps1"
    and in the "Start in" field enter the file directory path
     
    SteveFL99, Oct 26, 2016
    #17
  3. flybynite Win User
    I never have a UAC prompt appear, and I don't have any other windows appear at all. I just click the shortcut, and the Hyper-V VM starts. No additional windows popping up, no UAC prompts. Nothing.
     
    flybynite, Oct 26, 2016
    #18
  4. SteveFL99 Win User

    Create Shortcut of Hyper-V Virtual Machine in Windows

    I took the powershell code and added to it so that it will start a VM from any state and then gives you options on how you want to shut it down. You can use a shortcut (to powershell or a task, as explained above) to run the code.

    When launched, this code starts or resumes the virtual machine and then connects to it. When finished, just close the connection window and you will get a popup asking how you want to exit. You can pause (suspend), hibernate (save), or shut down (stop) the VM, or leave it running, by clicking the appropriate button or typing a letter. A short popup alerts you when that action (e.g., save or shutdown) is complete. I thought others might find this useful for managing a VM using just a shortcut.

    Code: $t = '[DllImport("user32.dll")] public static extern bool ShowWindow(int handle, int state);' add-type -name win -member $t -namespace native [native.win]::ShowWindow(([System.Diagnostics.Process]::GetCurrentProcess() | Get-Process).MainWindowHandle, 0) $TestVM = Get-VM "Windows 10 VM" $StartOnState = { switch -wildcard ($_.State) { "Pa*" {Resume-VM "Windows 10 VM"} "Of*" {Start-VM "Windows 10 VM"} "Save*" {Start-VM "Windows 10 VM"} default {} } } $TestVM | ? $StartOnState cmd /c %SYSTEMROOT%\System32\vmconnect.exe localhost "Windows 10 VM" | Out-Null [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") $objForm = New-Object System.Windows.Forms.Form $objForm.Text = "Windows 10 VM" $objForm.Size = New-Object System.Drawing.Size(330,152) $objForm.StartPosition = "CenterScreen" $objForm.KeyPreview = $True $objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter") {$script:selection=$objTextBox.Text;$objForm.Close()}}) $objForm.Add_KeyDown({if ($_.KeyCode -eq "R") {$script:selection="R";$objForm.Close()}}) $objForm.Add_KeyDown({if ($_.KeyCode -eq "P") {$script:selection="P";$objForm.Close()}}) $objForm.Add_KeyDown({if ($_.KeyCode -eq "H") {$script:selection="H";$objForm.Close()}}) $objForm.Add_KeyDown({if ($_.KeyCode -eq "S") {$script:selection="S";$objForm.Close()}}) $objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape") {$script:selection=0;$objForm.Close()}}) $RButton = New-Object System.Windows.Forms.Button $RButton.Location = New-Object System.Drawing.Size(4,75) $RButton.Size = New-Object System.Drawing.Size(75,23) $RButton.Text = "Running" $RButton.Add_Click({$script:selection="R";$objForm.Close()}) $objForm.Controls.Add($RButton) $PButton = New-Object System.Windows.Forms.Button $PButton.Location = New-Object System.Drawing.Size(81,75) $PButton.Size = New-Object System.Drawing.Size(75,23) $PButton.Text = "Pause" $PButton.Add_Click({$script:selection="P";$objForm.Close()}) $objForm.Controls.Add($PButton) $HButton = New-Object System.Windows.Forms.Button $HButton.Location = New-Object System.Drawing.Size(158,75) $HButton.Size = New-Object System.Drawing.Size(75,23) $HButton.Text = "Hibernate" $HButton.Add_Click({$script:selection="H";$objForm.Close()}) $objForm.Controls.Add($HButton) $SButton = New-Object System.Windows.Forms.Button $SButton.Location = New-Object System.Drawing.Size(235,75) $SButton.Size = New-Object System.Drawing.Size(75,23) $SButton.Text = "Shut down" $SButton.Add_Click({$script:selection="S";$objForm.Close()}) $objForm.Controls.Add($SButton) $objLabel = New-Object System.Windows.Forms.Label $objLabel.Location = New-Object System.Drawing.Size(7,10) $objLabel.Size = New-Object System.Drawing.Size(300,30) $objLabel.Text = "How to exit VM: [P]ause, [H]ibernate, hut down, or Keep [R]unning" $objForm.Controls.Add($objLabel) $objTextBox = New-Object System.Windows.Forms.TextBox $objTextBox.Location = New-Object System.Drawing.Size(4,44) $objTextBox.Size = New-Object System.Drawing.Size(305,20) $objForm.Controls.Add($objTextBox) $objForm.Topmost = $True $objForm.Add_Shown({$objForm.Activate()}) [void] $objForm.ShowDialog() switch -wildcard ($script:selection) { "R*" {} "P*" {Suspend-VM "Windows 10 VM"} "H*" {Save-VM "Windows 10 VM"} "S*" {Stop-VM "Windows 10 VM"} default {} } $g = new-object -comobject wscript.shell $b = $g.popup("Done",3,"Windows 10 VM",1088) Stop-Process -processname powershell [/quote]

    Note that my virtual machine is named "Windows 10 VM". Substitute the name of your VM in the code. Also, if you make it a task, be sure to lower the prioirty of the task to 5 or 6. The default is 7, which causes it to run slow if other processes are using resources.
     
    SteveFL99, Nov 11, 2016
    #19
  5. flybynite Win User
    I had to put this code in it to get it to work. Without it I do not have administrator privilidges. Code: param([switch]$Elevated)function Test-Admin { $currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent()) $currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)}if ((Test-Admin) -eq $false) { if ($elevated) { # tried to elevate, did not work, aborting } else { Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))}exit}'running with full privileges'[/quote] Your code works with this in it. I like my code better though. There are no pop up windows, and when you turn it off, it turns off. No questions or extra steps.
     
    flybynite, Nov 11, 2016
    #20
  6. SteveFL99 Win User
    I don't need that code, but I have my shortcut (or task) set to run as admin.

    If you always shut down the VM, your code is much simpler. I pop on and off of my VM frequently, so I close the connection but want to pause or save it for quicker restart. My code gives me the option of how to exit each time without having to do it through the connection window menus. But yours is probably better for many people's applications.
     
    SteveFL99, Nov 12, 2016
    #21
  7. It worked for me and there was no need to create Task with admin rights.
     
    MetalSaint, Apr 4, 2018
    #22
Thema:

Create Shortcut of Hyper-V Virtual Machine in Windows

Loading...
  1. Create Shortcut of Hyper-V Virtual Machine in Windows - Similar Threads - Create Shortcut Hyper

  2. How to create Hyper-V Virtual Machine Desktop Shortcut in Windows 11/10

    in Windows 10 News
    How to create Hyper-V Virtual Machine Desktop Shortcut in Windows 11/10: [ATTACH]In this post, we show you how to create Hyper-V Virtual Machine Desktop Shortcut in Windows 11/10. With Hyper-V, PC users can create, configure and enable running virtualized computer systems on top of a physical host machine that supports virtualization....
  3. Hyper V Manager unable to create new virtual machine

    in Windows 10 Gaming
    Hyper V Manager unable to create new virtual machine: Hyper V Manager is unable to create new virtual machine. When I went and checked the event viewer I found this error message The Hyper-V Virtual Machine Management service encountered an unexpected error: %%2147778704 0x80048090....
  4. Hyper V Manager unable to create new virtual machine

    in Windows 10 Software and Apps
    Hyper V Manager unable to create new virtual machine: Hyper V Manager is unable to create new virtual machine. When I went and checked the event viewer I found this error message The Hyper-V Virtual Machine Management service encountered an unexpected error: %%2147778704 0x80048090....
  5. Hyper-V - Optimizing Virtual Machines

    in Windows 10 Tutorials
    Hyper-V - Optimizing Virtual Machines: How to: Hyper-V - Optimizing Virtual Machines Running Windows on a virtual machine can naturally never be as fast as same version of Windows on same computer running on physical hardware. However, by tweaking virtual machine settings, you can greatly impact the speed and...
  6. Backing up Hyper-V Virtual Machines

    in Windows 10 Virtualization
    Backing up Hyper-V Virtual Machines: Hi, I was wondering if all I really need to do to backup activated virtual machines but not associated virtual hard drives is just to copy the virtual hard drive folder to another drive (or even one drive) . All I am really interested is in saving the machines which have...
  7. Virtual network is not created in Hyper-V

    in Windows 10 Virtualization
    Virtual network is not created in Hyper-V: Hi guys, I enabled Hyper-V feature in Windows 10 but unable to create a virtual switch. I tried to create private and internal types of virtual switch but every time the process stuck on "Applying changes". What could be the reason of that? Thank you. 61906
  8. Hyper-V - Create Custom Virtual Machine Gallery

    in Windows 10 Tutorials
    Hyper-V - Create Custom Virtual Machine Gallery: How to: Hyper-V - Create Custom Virtual Machine Gallery [img] Information Quick Create is a feature in Hyper-V allowing users to setup new virtual machines with a few mouse clicks. At the moment, Quick Create offers users a quick setup of Windows 10 Developer Environment,...
  9. Hyper-V Quick Create - Create or Copy a Virtual Machine

    in Windows 10 Tutorials
    Hyper-V Quick Create - Create or Copy a Virtual Machine: How to: Hyper-V Quick Create - Create or Copy a Virtual Machine [img] Information Windows 10 Insider Preview Build 15002 gave a facelift to Hyper-V as told earlier on Ten Forums. One of the new cool things is a new feature in Hyper-V Manager called Quick Create. With it...
  10. Create Hyper-V Virtual Machine Connection shortcut in Windows 10

    in Windows 10 Tutorials
    Create Hyper-V Virtual Machine Connection shortcut in Windows 10: How to: Create Hyper-V Virtual Machine Connection shortcut in Windows 10 How to Create a Hyper-V Virtual Machine Connection shortcut in Windows 10 The Windows 10 Pro, Enterprise, and Education editions include the Hyper-V virtualization technology. Hyper-V enables...
Tags:

Users found this page by searching for:

  1. what is the shortcut to login vm in Hyper-v