windows remote login api using c#/c++

2k Views Asked by At

I want to write a program to login into remote machine using domain admin user credential and do following tasks

  1. Get some system information like OS, IIS version, .net version etc
  2. Transfer some files from remote to local machine and vice versa.

Is there any windows API to do this?

Task I am trying to do can done manually using remote desktop application, but I don't want to use GUI as I would like to automate this, to get machine info periodically from our environment and display in a Dashboard.

1

There are 1 best solutions below

1
rravuri On

you can use winrm and automate it using powershell https://msdn.microsoft.com/en-us/library/aa384426%28v=vs.85%29.aspx

here is a vb example (you can use the same COM objects in c#)

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