Help logging into remote server

Dickman, Scott 21 Reputation points
2020-11-27T20:15:27.917+00:00

I need to create a program to restart 3 remote, non AD joined servers. Using VS2019 and I added the LoginForm to the project. Now I am lost. Can anybody point me in the right direction to collect a username and password and then pass that to a restart command to restart these 3 servers? I have this written in PowerShell, however when I turn it into an executable, it no longer works in Citrix, so I am having to knock off the VB.NET rust and try it this way.

Thanks
Scott

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,594 questions
0 comments No comments
{count} votes

Accepted answer
  1. Peter Fleischer (former MVP) 19,231 Reputation points
    2020-11-28T19:16:52.767+00:00

    Hi,
    you can use following console demo:

    Option Infer On
    Option Strict On
    
    Imports System.Management
    Imports System.Management.Instrumentation
    
    Module Module1
      Sub main()
    
        Dim sComp As String = "192.168.0.96"
    
        Dim opts As New ConnectionOptions
        With opts
          .Username = InputBox("Please enter your user name:")
          .Password = InputBox("Please enter your password:")
        End With
    
        Dim ms As New ManagementScope("\\" & sComp & "\root\cimv2", opts)
        ms.Connect()
    
        Dim oq As New ObjectQuery("Select * From Win32_OperatingSystem")
    
        Dim mos As New ManagementObjectSearcher(ms, oq)
    
        Dim col = mos.Get
    
        For Each mo As ManagementObject In mos.Get
          Dim ss As String() = {""}
          mo.InvokeMethod("Reboot", ss)
        Next
    
        Console.ReadLine()
      End Sub
    
    End Module
    

0 additional answers

Sort by: Most helpful