Page 2 of 3 FirstFirst 123 LastLast
  1.    22 Jan 2016 #10
    Join Date : Feb 2015
    Bamberg Germany
    Posts : 16,951
    Win10 Pro, Win10 Pro N, Win10 Home, Win10 Pro Insider Fast Ring, Windows 8.1 Pro, Ubuntu

    @Kari here are two CentOS icons I made for you:
    2 CentOS icons.zip

    Here are the PNG versions to show what they look like.
    Name:  CentOS VM.png.png
Views: 410
Size:  9.8 KB Name:  CentOS alternative.png.png
Views: 423
Size:  23.8 KB
      My ComputersSystem Spec
  2.    22 Jan 2016 #11
    Join Date : Oct 2013
    A Finnish expat in Germany
    Posts : 12,628
    Windows 10 Pro
    Thread Starter

    Thanks! I like them, especially the blue one.
      My ComputerSystem Spec
  3.    22 Jan 2016 #12
    Join Date : Feb 2015
    Bamberg Germany
    Posts : 16,951
    Win10 Pro, Win10 Pro N, Win10 Home, Win10 Pro Insider Fast Ring, Windows 8.1 Pro, Ubuntu

    You're welcome, the blue came out better, because the other was originally a gif with transparency, but after changing it to PNG then ICO it lost the transparency and got a white background.
      My ComputersSystem Spec
  4.    28 Aug 2016 #13
    Join Date : Mar 2016
    Aberdeen
    Posts : 205
    Windows 10

    I know this is an old thread, but I think the original intent was forgotten. That is to start a Hyper-V virtual machine from a shortcut. I put all of these files I am about to relate into a folder called HyperV inside a folder on my C-drive called Customizations where I have various other stuff stored. So I have C:\Customizations\HyperV. My first file is StartVM.ps1 it has this code in it. My Hyper-V machine, I might add, is called test.
    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
    My next file is StartVM.cmd, and it contains this
    Code:
    @REM [This code block detects if the script is running with ADMIN PRIVILEGES. If it isn't it pauses, and then quits.]echo OFFcls
    NET SESSION >nul 2>&1
    IF %ERRORLEVEL% EQU 0 (
        ECHO Administrator PRIVILEGES Detected! 
    ) ELSE (
       echo ######## ########  ########   #######  ########  
       echo ##       ##     ## ##     ## ##     ## ##     ## 
       echo ##       ##     ## ##     ## ##     ## ##     ## 
       echo ######   ########  ########  ##     ## ########  
       echo ##       ##   ##   ##   ##   ##     ## ##   ##   
       echo ##       ##    ##  ##    ##  ##     ## ##    ##  
       echo ######## ##     ## ##     ##  #######  ##     ## 
       echo.
       echo.
       echo ####### ERROR: ADMINISTRATOR PRIVILEGES REQUIRED #########
       echo This script must be run as administrator to work properly!  
       echo If you are seeing this right click on All_In_One.CMD and select "Run As Administrator."
       echo ##########################################################
       echo.
       PAUSE
       EXIT /B 1
    )
    @echo ON
    
    
    
    
    %~d0
    cd %~d0%~p0
    cls
    powershell "& "".\StartVM.ps1"""
    My third file is for aesthetics so I will not see any command windows running in the background. It is VirtualMachine.vbs, and contains this
    Code:
    command = "powershell.exe -nologo -command %SYSTEMDRIVE%\Customizations\HyperV\StartVM.cmd"set shell = CreateObject("Wscript.Shell")
    shell.Run command,0
    My fourth file is a shortcut to VirtualMachine.vbs. I named it VirtualMachine. I pinned it to the Start Menu, opened the file location, and set it to run as administrator. That is all there is to it. Be sure to change the name of the virtual machine in the code from my "test" to whatever you have named yours!
      My ComputerSystem Spec
  5.    23 Oct 2016 #14
    Join Date : Oct 2016
    Posts : 4
    Windows 10

    Quote Originally Posted by flybynite View Post
    I know this is an old thread, but I think the original intent was forgotten. That is to start a Hyper-V virtual machine from a shortcut. I put all of these files I am about to relate into a folder called HyperV inside a folder on my C-drive called Customizations where I have various other stuff stored. So I have C:\Customizations\HyperV. My first file is StartVM.ps1 it has this code in it. My Hyper-V machine, I might add, is called test.

    [CODE]

    My fourth file is a shortcut to VirtualMachine.vbs. I named it VirtualMachine. I pinned it to the Start Menu, opened the file location, and set it to run as administrator. That is all there is to it. Be sure to change the name of the virtual machine in the code from my "test" to whatever you have named yours!
    Thanks for this. It was just what I was looking for. But note that it has some errors due to missing line breaks.

    In the second file (.cmd), the first line should be broken into three lines:
    @Rem [This code block detects if the script is running with ADMIN PRIVILEGES. If it isn't it pauses, and then quits.]
    echo OFF
    cls

    And in the third file (.vbs), the first line should be broken into two lines:
    command = "powershell.exe -nologo -command %SYSTEMDRIVE%\Users\Steve\Desktop\VMLaunch\StartVM.cmd"
    set shell = CreateObject("Wscript.Shell")

    Also note that Windows would not let me elevate the vbs file or its shortcut, to Run As Admin. This was solved by setting the shortcut to point to the windows script host executable, making it's target:
    C:\Windows\System32\wscript.exe "C:\[file directory path]\VirtualMachine.vbs"

    I also ran into a problem with powershell scripts being restricted from running on my computer (this is the default Windows setting). I overcame this by adding the Set-ExecutionPolicy command to the .cmd file. I also decided to set the policy back to restricted after the VM was closed, but this is optional. So I replaced the last line of the .cmd file with the following three lines (last line optional):
    powershell Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
    powershell "& "".\StartVM.ps1"""
    powershell Set-ExecutionPolicy -ExecutionPolicy Undefined

    One other note, if you want to control how the VM exits, just remove the Stop-VM "test" line from the first (.ps1) file. Then you can choose to pause, save, or shutdown before closing the connect window, or you can even just close the connect window and let the VM continue running. You can then use the shortcut to reconnect to the VM regardless of which state was chosen.

    Hope this helps others.
      My ComputerSystem Spec
  6.    23 Oct 2016 #15
    Join Date : Mar 2016
    Aberdeen
    Posts : 205
    Windows 10

    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
    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
    I put a shortcut to the vbs in the same folder, and check run as administrator under properties -> advanced. I pin it to Start.
      My ComputerSystem Spec
  7.    27 Oct 2016 #16
    Join Date : Oct 2016
    Posts : 4
    Windows 10

    Quote Originally Posted by flybynite View Post
    I actually have just 3 files now if you include a shortcut to the vbs file. The vbs file looks like this

    ...code...
    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
      My ComputerSystem Spec
  8.    27 Oct 2016 #17
    Join Date : Mar 2016
    Aberdeen
    Posts : 205
    Windows 10

    Quote Originally Posted by SteveFL99 View Post
    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
    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.
      My ComputerSystem Spec
  9.    11 Nov 2016 #18
    Join Date : Oct 2016
    Posts : 4
    Windows 10

    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, [S]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
    
    


    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.
      My ComputerSystem Spec
  10.    11 Nov 2016 #19
    Join Date : Mar 2016
    Aberdeen
    Posts : 205
    Windows 10

    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'
    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.
      My ComputerSystem Spec

 
Page 2 of 3 FirstFirst 123 LastLast


Similar Threads
Tutorial Category
Virtualization Hyper-V - Create and Use VHD of Windows 10 with Disk2VHD
How to Create VHD of Windows 10 Installation and Use in Hyper-V The tutorial has been updated today (20-MAR-2017). Please post all your questions about this process in this thread. Please notice: some screenshots are from pre-release builds of...
Tutorials
Virtualization Create and Use Hyper-V Checkpoints in Windows 10
How to Create and Use Hyper-V Checkpoints in Windows 10 Checkpoint is a powerful Hyper-V feature to easily undo all changes on a virtual machine. You can play with virtual machines testing apps, changing settings, editing registry and so on as...
Tutorials
Customization Create This PC Shortcut in Windows 10
How to Create a This PC Shortcut in Windows 10 My Computer was changed to This PC in Windows 8.1 and Windows RT 8.1. You would open File Explorer to view This PC. In Windows 10, File Explorer now opens to Quick access by default instead of...
Tutorials
Best Virtual machine software to try W10 TP on Windows 8.1
Can anyone recommend the least heavy (change in system prefs) and size, virtual machine software to test W10 TP on a Windows 8.1 Pro x86 desktop. I have tried VMWare Workstation in the past but find it is no longer free, I would like to have a quick...
Virtualization
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd
All times are GMT -5. The time now is 01:10.
Find Us
Twitter Facebook Google+ Ten Forums iOS App Ten Forums Android App



Windows 10 Forums