Dim bExplorer As Boolean = False
Dim myPID As Integer = System.Diagnostics.Process.GetCurrentProcess().Id
Dim myParentProcessName As String = ""
Dim objWMIService, objProcess, colProcess
Dim myPPID As Integer
objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
colProcess = objWMIService.ExecQuery("Select * from Win32_Process where ProcessID=" & myPID)
For Each objProcess In colProcess
myPPID = objProcess.ParentProcessID()
Try
myParentProcessName = (Process.GetProcessById(myPPID).ProcessName).ToString()
If myParentProcessName <> "cmd" Then bExplorer = True
Catch
'May have elevated
bExplorer = True
End Try
Next
If bExplorer Then
sMachineName = InputBox("What machine would you like to connect? Leave blank for localhost")
Else
Try
sMachineName = arguments(1)
Catch
debug.print("You must specify a remote machine")
End
End Try
End If
If bExplorer Then
Debug.Print("press ENTER to quit")
Console.ReadLine()
End If
Dim arguments As String() = Environment.GetCommandLineArgs()
If arguments.Length > 1 Then
'Console.ForegroundColor = ConsoleColor.Blue
Console.WriteLine("Machine: " & arguments(1).ToString)
End If
'My.Computer.FileSystem.WriteAllBytes("c:\temp\test.exe", My.Resources.psfile, False)
Dim sTEMPpath As String = "c:\temp" ' Environment.GetEnvironmentVariable("TEMP")
Console.WriteLine(sTEMPpath)
My.Computer.FileSystem.WriteAllBytes(sTEMPpath & "\psfile.exe", My.Resources.psfile, False)
Imports System.Diagnostics
Dim aModuleName As String = Diagnostics.Process.GetCurrentProcess.MainModule.ModuleName
Dim aProcName As String = System.IO.Path.GetFileNameWithoutExtension(aModuleName)
If Process.GetProcessesByName(aProcName).Length > 1 Then
Application.Exit()
End If