Skip to content

Instantly share code, notes, and snippets.

@sneal
Created December 11, 2013 06:09
Show Gist options
  • Save sneal/7905775 to your computer and use it in GitHub Desktop.
Save sneal/7905775 to your computer and use it in GitHub Desktop.
package main
import (
"os"
"fmt"
"code.google.com/p/go.crypto/ssh"
)
type password string
func (p password) Password(user string) (string, error) {
return string(p), nil
}
func runCmd(client *ssh.ClientConn, cmd string) {
session, err := client.NewSession()
if err != nil {
panic("Failed to create session: " + err.Error())
}
session.Stdout = os.Stdout
session.Stderr = os.Stderr
err = session.Run(cmd)
if err != nil {
fmt.Println("Failed to run: " + err.Error())
}
session.Close()
}
func main() {
config := &ssh.ClientConfig{
User: "vagrant",
Auth: []ssh.ClientAuth{
ssh.ClientAuthPassword(password("vagrant")),
},
}
client, err := ssh.Dial("tcp", "192.168.211.209:22", config)
if err != nil {
panic("Failed to dial: " + err.Error())
}
runCmd(client, "cmd /c dir") // <-- comment this line out for the dism cmd to suceed, or...
//client, _ = ssh.Dial("tcp", "192.168.211.209:22", config) // <-- uncomment this line
runCmd(client, "cmd /c dism.exe /online /LogLevel:4 /enable-feature /featurename:NetFx3 /norestart")
fmt.Println("All done!")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment