簡體   English   中英

使用C#/ C ++的Windows遠程登錄api

[英]windows remote login api using c#/c++

我想編寫一個程序來使用域管理員用戶憑據登錄到遠程計算機,並執行以下任務

  1. 獲取一些系統信息,例如OS,IIS版本,.net版本等
  2. 將一些文件從遠程傳輸到本地計算機,反之亦然。

是否有Windows API可以執行此操作?

我嘗試執行的任務可以使用遠程桌面應用程序手動完成,但是我不想使用GUI,因為我希望實現自動化,以便從我們的環境中定期獲取機器信息並顯示在儀表板中。

您可以使用winrm並使用powershell將其自動化https://msdn.microsoft.com/zh-cn/library/aa384426%28v=vs.85%29.aspx

這是一個vb 示例 (您可以在c#中使用相同的COM對象)

Const RemoteComputer = "ComputerName.domain.com"
Set objWsman = CreateObject("Wsman.Automation")
Set objConnectionOptions = objWsman.CreateConnectionOptions
objConnectionOptions.UserName = "Username"
objConnectionOptions.Password = "Password"
iFlags = objWsman.SessionFlagUseKerberos Or _
  objWsman.SessionFlagCredUserNamePassword
Set objSession = objWsman.CreateSession("https://" & RemoteComputer, _
  iFlags, objConnectionOptions)
strResource = "http://schemas.microsoft.com/wbem/wsman/1/" & _
  "wmi/root/cimv2/Win32_OperatingSystem"
Set objResponse = objSession.Enumerate(strResource)

While Not objResponse.AtEndOfStream
    DisplayOutput(objResponse.ReadItem) 
Wend

'****************************************************
' Displays WinRM XML message using built-in XSL
'****************************************************
Sub DisplayOutput(strWinRMXml)
    Dim xmlFile, xslFile
    Set xmlFile = CreateObject("MSXml2.DOMDocument.3.0") 
    Set xslFile = CreateObject("MSXml2.DOMDocument.3.0")
    xmlFile.LoadXml(strWinRMXml)
    xslFile.Load("WsmTxt.xsl")
    Wscript.Echo xmlFile.TransformNode(xslFile) 
End Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM