{"id":13413641,"url":"https://github.com/masterzen/winrm","last_synced_at":"2025-05-14T12:10:58.561Z","repository":{"id":12857705,"uuid":"15533753","full_name":"masterzen/winrm","owner":"masterzen","description":"Command-line tool and library for Windows remote command execution in Go","archived":false,"fork":false,"pushed_at":"2024-07-02T20:56:01.000Z","size":255,"stargazers_count":441,"open_issues_count":43,"forks_count":131,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-04-13T10:50:33.514Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/masterzen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-12-30T18:29:15.000Z","updated_at":"2025-04-11T03:49:15.000Z","dependencies_parsed_at":"2023-11-20T16:47:35.397Z","dependency_job_id":"a15860e8-aba3-4adb-9745-ee216bf8ac8f","html_url":"https://github.com/masterzen/winrm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masterzen%2Fwinrm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masterzen%2Fwinrm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masterzen%2Fwinrm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masterzen%2Fwinrm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/masterzen","download_url":"https://codeload.github.com/masterzen/winrm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254140760,"owners_count":22021219,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T20:01:45.213Z","updated_at":"2025-05-14T12:10:58.535Z","avatar_url":"https://github.com/masterzen.png","language":"Go","readme":"# WinRM for Go\n\n_Note_: if you're looking for the `winrm` command-line tool, this has been splitted from this project and is available at [winrm-cli](https://github.com/masterzen/winrm-cli)\n\nThis is a Go library to execute remote commands on Windows machines through\nthe use of WinRM/WinRS.\n\n_Note_: this library doesn't support domain users (it doesn't support GSSAPI nor Kerberos). It's primary target is to execute remote commands on EC2 windows machines.\n\n[![Build Status](https://travis-ci.org/masterzen/winrm.svg?branch=master)](https://travis-ci.org/masterzen/winrm)\n[![Coverage Status](https://coveralls.io/repos/masterzen/winrm/badge.png)](https://coveralls.io/r/masterzen/winrm)\n\n## Contact\n\n- Bugs: https://github.com/masterzen/winrm/issues\n\n\n## Getting Started\nWinRM is available on Windows Server 2008 and up. This project natively supports basic authentication for local accounts, see the steps in the next section on how to prepare the remote Windows machine for this scenario. The authentication model is pluggable, see below for an example on using Negotiate/NTLM authentication (e.g. for connecting to vanilla Azure VMs) or Kerberos authentication (using domain accounts).\n\n_Note_: This library only supports Golang 1.7+\n\n### Preparing the remote Windows machine for Basic authentication\nThis project supports only basic authentication for local accounts (domain users are not supported). The remote windows system must be prepared for winrm:\n\n_For a PowerShell script to do what is described below in one go, check [Richard Downer's blog](http://www.frontiertown.co.uk/2011/12/overthere-control-windows-from-java/)_\n\nOn the remote host, a PowerShell prompt, using the __Run as Administrator__ option and paste in the following lines:\n\n\t\twinrm quickconfig\n\t\ty\n\t\twinrm set winrm/config/service/Auth '@{Basic=\"true\"}'\n\t\twinrm set winrm/config/service '@{AllowUnencrypted=\"true\"}'\n\t\twinrm set winrm/config/winrs '@{MaxMemoryPerShellMB=\"1024\"}'\n\n__N.B.:__ The Windows Firewall needs to be running to run this command. See [Microsoft Knowledge Base article #2004640](http://support.microsoft.com/kb/2004640).\n\n__N.B.:__ Do not disable Negotiate authentication as the `winrm` command itself uses this for internal authentication, and you risk getting a system where `winrm` doesn't work anymore.\n\n__N.B.:__ The `MaxMemoryPerShellMB` option has no effects on some Windows 2008R2 systems because of a WinRM bug. Make sure to install the hotfix described [Microsoft Knowledge Base article #2842230](http://support.microsoft.com/kb/2842230) if you need to run commands that use more than 150MB of memory.\n\nFor more information on WinRM, please refer to \u003ca href=\"http://msdn.microsoft.com/en-us/library/windows/desktop/aa384426(v=vs.85).aspx\"\u003ethe online documentation at Microsoft's DevCenter\u003c/a\u003e.\n\n### Preparing the remote Windows machine for kerberos authentication\nThis project supports domain users via kerberos authentication. The remote windows system must be prepared for winrm:\n\nOn the remote host, a PowerShell prompt, using the __Run as Administrator__ option and paste in the following lines:\n\n                winrm quickconfig\n                y\n                winrm set winrm/config/service '@{AllowUnencrypted=\"true\"}'\n                winrm set winrm/config/winrs '@{MaxMemoryPerShellMB=\"1024\"}'\n\nAll __N.B__ points of \"Preparing the remote Windows machine for Basic authentication\" also applies.\n\n\n### Building the winrm go and executable\n\nYou can build winrm from source:\n\n```sh\ngit clone https://github.com/masterzen/winrm\ncd winrm\nmake\n```\n\n_Note_: this winrm code doesn't depend anymore on [Gokogiri](https://github.com/moovweb/gokogiri) which means it is now in pure Go.\n\n_Note_: you need go 1.5+. Please check your installation with\n\n```\ngo version\n```\n\n## Command-line usage\n\nFor command-line usage check the [winrm-cli project](https://github.com/masterzen/winrm-cli)\n\n## Library Usage\n\n**Warning the API might be subject to change.**\n\nFor the fast version (this doesn't allow to send input to the command) and it's using HTTP as the transport:\n\n```go\npackage main\n\nimport (\n\t\"github.com/masterzen/winrm\"\n\t\"os\"\n)\n\nendpoint := winrm.NewEndpoint(host, 5986, false, false, nil, nil, nil, 0)\nclient, err := winrm.NewClient(endpoint, \"Administrator\", \"secret\")\nif err != nil {\n\tpanic(err)\n}\nctx, cancel := context.WithCancel(context.Background())\ndefer cancel()\nclient.RunWithContext(ctx, \"ipconfig /all\", os.Stdout, os.Stderr)\n```\n\nor\n```go\npackage main\nimport (\n  \"github.com/masterzen/winrm\"\n  \"fmt\"\n  \"os\"\n)\n\nendpoint := winrm.NewEndpoint(\"localhost\", 5985, false, false, nil, nil, nil, 0)\nclient, err := winrm.NewClient(endpoint,\"Administrator\", \"secret\")\nif err != nil {\n\tpanic(err)\n}\n\nctx, cancel := context.WithCancel(context.Background())\ndefer cancel()\n_, err := client.RunWithContextWithInput(ctx, \"ipconfig\", os.Stdout, os.Stderr, os.Stdin)\nif err != nil {\n\tpanic(err)\n}\n\n```\n\nBy passing a TransportDecorator in the Parameters struct it is possible to use different Transports (e.g. NTLM)\n\n```go\npackage main\nimport (\n  \"github.com/masterzen/winrm\"\n  \"fmt\"\n  \"os\"\n)\n\nendpoint := winrm.NewEndpoint(\"localhost\", 5985, false, false, nil, nil, nil, 0)\n\nparams := DefaultParameters\nparams.TransportDecorator = func() Transporter { return \u0026ClientNTLM{} }\n\nclient, err := NewClientWithParameters(endpoint, \"test\", \"test\", params)\nif err != nil {\n\tpanic(err)\n}\n\n_, err := client.RunWithInput(\"ipconfig\", os.Stdout, os.Stderr, os.Stdin)\nif err != nil {\n\tpanic(err)\n}\n\n```\n\nPassing a TransportDecorator also permit to use Kerberos authentication\n\n```go\npackage main\nimport (\n  \"os\"\n  \"fmt\"\n  \"github.com/masterzen/winrm\"\n)\n\nendpoint := winrm.NewEndpoint(\"srv-win\", 5985, false, false, nil, nil, nil, 0)\n\nparams := winrm.DefaultParameters\nparams.TransportDecorator = func() Transporter {\n        return \u0026winrm.ClientKerberos{\n\t\tUsername: \"test\",\n\t\tPassword: \"s3cr3t\",\n\t\tHostname: \"srv-win\",\n\t\tRealm: \"DOMAIN.LAN\",\n\t\tPort: 5985,\n\t\tProto: \"http\",\n\t\tKrbConf: \"/etc/krb5.conf\",\n\t\tSPN: fmt.Sprintf(\"HTTP/%s\", hostname),\n\t}\n}\n\nclient, err := NewClientWithParameters(endpoint, \"test\", \"s3cr3t\", params)\nif err != nil {\n        panic(err)\n}\n\nctx, cancel := context.WithCancel(context.Background())\ndefer cancel()\n_, err := client.RunWithContextWithInput(ctx, \"ipconfig\", os.Stdout, os.Stderr, os.Stdin)\nif err != nil {\n        panic(err)\n}\n\n```\n\n\nBy passing a Dial in the Parameters struct it is possible to use different dialer (e.g. tunnel through SSH)\n\n```go\npackage main\n     \n import (\n    \"github.com/masterzen/winrm\"\n    \"golang.org/x/crypto/ssh\"\n    \"os\"\n )\n \n func main() {\n \n    sshClient, err := ssh.Dial(\"tcp\",\"localhost:22\", \u0026ssh.ClientConfig{\n        User:\"ubuntu\",\n        Auth: []ssh.AuthMethod{ssh.Password(\"ubuntu\")},\n        HostKeyCallback: ssh.InsecureIgnoreHostKey(),\n    })\n \n    endpoint := winrm.NewEndpoint(\"other-host\", 5985, false, false, nil, nil, nil, 0)\n \n    params := winrm.DefaultParameters\n    params.Dial = sshClient.Dial\n \n    client, err := winrm.NewClientWithParameters(endpoint, \"test\", \"test\", params)\n    if err != nil {\n        panic(err)\n    }\n \n    ctx, cancel := context.WithCancel(context.Background())\n    defer cancel()\n    _, err = client.RunWithContextWithInput(ctx, \"ipconfig\", os.Stdout, os.Stderr, os.Stdin)\n    if err != nil {\n        panic(err)\n    }\n }\n\n```\n\n\nFor a more complex example, it is possible to call the various functions directly:\n\n```go\npackage main\n\nimport (\n  \"github.com/masterzen/winrm\"\n  \"fmt\"\n  \"bytes\"\n  \"os\"\n)\n\nstdin := bytes.NewBufferString(\"ipconfig /all\")\nendpoint := winrm.NewEndpoint(\"localhost\", 5985, false, false,nil, nil, nil, 0)\nclient , err := winrm.NewClient(endpoint, \"Administrator\", \"secret\")\nif err != nil {\n\tpanic(err)\n}\nshell, err := client.CreateShell()\nif err != nil {\n  panic(err)\n}\nctx, cancel := context.WithCancel(context.Background())\ndefer cancel()\nvar cmd *winrm.Command\ncmd, err = shell.ExecuteWithContext(ctx, \"cmd.exe\")\nif err != nil {\n  panic(err)\n}\n\ngo io.Copy(cmd.Stdin, stdin)\ngo io.Copy(os.Stdout, cmd.Stdout)\ngo io.Copy(os.Stderr, cmd.Stderr)\n\ncmd.Wait()\nshell.Close()\n```\n\nFor using HTTPS authentication with x 509 cert without checking the CA\n```go\npackage main\n\nimport (\n    \"github.com/masterzen/winrm\"\n    \"log\"\n    \"os\"\n)\n\nfunc main() {\n    clientCert, err := os.ReadFile(\"/home/example/winrm_client_cert.pem\")\n    if err != nil {\n        log.Fatalf(\"failed to read client certificate: %q\", err)\n    }\n\n    clientKey, err := os.ReadFile(\"/home/example/winrm_client_key.pem\")\n    if err != nil {\n        log.Fatalf(\"failed to read client key: %q\", err)\n    }\n\n    winrm.DefaultParameters.TransportDecorator = func() winrm.Transporter {\n        // winrm https module\n        return \u0026winrm.ClientAuthRequest{}\n    }\n\n    endpoint := winrm.NewEndpoint(\n        \"192.168.100.2\", // host to connect to\n        5986,            // winrm port\n        true,            // use TLS\n        true,            // Allow insecure connection\n        nil,             // CA certificate\n        clientCert,      // Client Certificate\n        clientKey,       // Client Key\n        0,               // Timeout\n    )\n    client, err := winrm.NewClient(endpoint, \"Administrator\", \"\")\n    if err != nil {\n        log.Fatalf(\"failed to create client: %q\", err)\n    }\n    ctx, cancel := context.WithCancel(context.Background())\n    defer cancel()\n    _, err = client.RunWithContext(ctx, \"whoami\", os.Stdout, os.Stderr)\n    if err != nil {\n        log.Fatalf(\"failed to run command: %q\", err)\n    }\n}\n```\n\nNote: canceling the `context.Context` passed as first argument to the various\nfunctions of the API will not cancel the HTTP requests themselves, it will\nrather cause a running command to be aborted on the remote machine via a call to\n`command.Stop()`.\n\n## Developing on WinRM\n\nIf you wish to work on `winrm` itself, you'll first need [Go](http://golang.org)\ninstalled (version 1.5+ is _required_). Make sure you have Go properly installed,\nincluding setting up your [GOPATH](http://golang.org/doc/code.html#GOPATH).\n\nFor some additional dependencies, Go needs [Mercurial](http://mercurial.selenic.com/)\nand [Bazaar](http://bazaar.canonical.com/en/) to be installed.\nWinrm itself doesn't require these, but a dependency of a dependency does.\n\nNext, clone this repository into `$GOPATH/src/github.com/masterzen/winrm` and\nthen just type `make`.\n\nYou can run tests by typing `make test`.\n\nIf you make any changes to the code, run `make format` in order to automatically\nformat the code according to Go standards.\n\nWhen new dependencies are added to winrm you can use `make updatedeps` to\nget the latest and subsequently use `make` to compile.\n","funding_links":[],"categories":["Networking","网络相关库","\u003cspan id=\"网络-networking\"\u003e网络 Networking\u003c/span\u003e","網絡","网络","Windows Specific","\u003ca id=\"b478e9a9a324c963da11437d18f04998\"\u003e\u003c/a\u003e工具","Go","Relational Databases"],"sub_categories":["Transliteration","Strings","暂未分类","Advanced Console UIs","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","Uncategorized","高級控制台界面","音译","\u003ca id=\"1afda3039b4ab9a3a1f60b179ccb3e76\"\u003e\u003c/a\u003e其他","交流","暂未分类这些库被放在这里是因为其他类别似乎都不适合。","高级控制台界面"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmasterzen%2Fwinrm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmasterzen%2Fwinrm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmasterzen%2Fwinrm/lists"}