View Single Post
Old 03-14-2012, 11:36 PM   #76
Hypernova
Hyperreader
Hypernova began at the beginning.
 
Posts: 66
Karma: 10
Join Date: Feb 2009
Device: Kindle DXG;Pocketbook 360
Powershell script for starting the vnc viewer

I put together something so it's more convenient to start/quit the whole process. It's a powershell script to run UltraVNC, wake up the Kindle, prevent sleep using kaffeine(optional), and start vncviewer. When you hit enter, it will close the viewer, exit kaffeine and UltraVNC. I use the script from http://velemental.com/2012/01/11/pro...th-powershell/ and SharpSSH.

You have to put your ssh/vnc's username/password at the beginning of the script and place the content of the 7z file in the same directory as UltraVNC folder (or just change the path yourself).

Here's the Powershell script for reference
Code:
$vncpassword=""
$sshuser="root"
$sshpassword=""
$hostname="192.168.2.2"

#Script path
$spath=Split-Path -parent $MyInvocation.MyCommand.Definition

#Start winvnc if not already running
if (-not($ultravnc=Get-Process winvnc -ea 0))
{
    Start-Process($spath+"\UltraVNC\winvnc.exe")
    $ultravnc=Get-Process winvnc
}

#dot source ssh_function
. ($spath+"\ssh_function.ps1")

#Create ssh session
New-SshSession -UserName $sshuser -Password $sshpassword -HostName $hostname
#Wake up the kindle
Send-Ssh("lipc-set-prop com.lab126.powerd wakeUp 1")
#Run vncviewer
Send-Ssh("/mnt/us/kindlevncviewer/kvncviewer.sh -password $vncpassword 192.168.2.1:1 &")
#Prevent sleep using kaffeine
Send-Ssh("/mnt/us/system/kaffeine")

#Wait for Enter key
Read-Host -Prompt 'Press Enter to close VNC' | Out-Null
#Kill vncviewer
Send-Ssh("killall kindlevncviewer")
#Exit kaffeine
Send-Ssh("/mnt/us/system/kaffeine 3")
#Kill winvnc
Stop-Process($ultravnc)

#Close ssh session
Remove-SshSession
Now I can simply run the script. Thanks hawhill and everyone again for your work. This is awesome.
Attached Files
File Type: zip KindleVNCPowershell.zip (155.0 KB, 92 views)

Last edited by Hypernova; 03-15-2012 at 06:05 PM. Reason: Add attachment
Hypernova is offline   Reply With Quote