Forum Discussion
ixxo09
Nov 21, 2024Copper Contributor
Strange chraracters in the powershell command PS_GetOutputFile("netsh wlan show interfaces")
I´m creating a sub that lay out in a textbox of a form with strange chrs. my sub is as follow: Private Sub Form_Load()
'Redondear las esquinas del formulario
Call UISetRoundRect(Me, 40, Fal...
arnel_gp
Nov 22, 2024Steel Contributor
here is another code and without you needing to add attribution:
Private Sub Form_Load()
Dim content As String
Dim cmd As String
Dim outputfile As String
outputfile = Environ$("temp") & "\PSTemp.txt"
cmd = "cmd.exe /c netsh wlan show interfaces > """ & outputfile & """"
'Redondear las esquinas del formulario
Call UISetRoundRect(Me, 40, False)
'This sets an exact position using MoveSize if form´s parent is loaded, otherwiseccenter de form on screen
If IsLoaded("frmDashBoard") Then DoCmd.MoveSize 15050, 2400 Else Call gfncCenterForm(Me)
With Me
'Encabezado de la información de la red Wi-Fi
If Not IsNull(Me.OpenArgs) Then Me!lblInfo.Caption = "INFORMACIÓN " & Me.OpenArgs
Shell cmd, vbHide
'Cargar la información de la red Wi-Fi
!txtInfo.Value = ReadTextFileContent(outputfile)
End With
End Sub
' chatgpt
Public Function ReadTextFileContent(ByVal filepath As String) As String
Dim fso As Object
Dim fileContent As String
Dim textFile As Object
' Create a FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
' Check if the file exists
If fso.FileExists(filepath) Then
' Open the file as a text stream
Set textFile = fso.OpenTextFile(filepath, 1) ' 1 = ForReading
' Read the entire file content
fileContent = textFile.ReadAll
' Close the file
textFile.Close
Else
MsgBox "File not found: " & filepath, vbExclamation, "Error"
End If
' Clean up
Set textFile = Nothing
Set fso = Nothing
ReadTextFileContent = fileContent
End Function