alrlms Posted March 15, 2017 Share Posted March 15, 2017 (edited) i'm having a problem with making an hta file to run a powershell commands to get local computer MAC address and then send it to the dhcp allow filter, i managed to the part to get the mac address but i could'nt manage the part to send it to the dhcp filter. i hope that there is some on can help. best regards to you all. Quote <html> <head> <title>Execution a powershell file with HTA by Hackoo</title> <HTA:APPLICATION APPLICATIONNAME="Execution a powershell file with HTA by Hackoo" SCROLL="yes" SINGLEINSTANCE="yes" WINDOWSTATE="maximize" ICON="Winver.exe" SCROLL="no" /> <script language="VBScript"> Option Explicit Sub Run_PS_Script1() ExampleOutput.value = "" btnClick1.disabled = True document.body.style.cursor = "wait" btnClick1.style.cursor = "wait" Dim WshShell,Command,PSFile,return,fso,file,text,Temp Set WshShell = CreateObject("WScript.Shell") Temp = WshShell.ExpandEnvironmentStrings("%Temp%") Command = "cmd /c echo Get-NetAdapter ^| select Name,MacAddress ^| Where-Object {$_.Name -like 'Ethernet' -or $_.Name -like 'Wi-Fi'} ^| Out-File %temp%\output.txt -Encoding ascii > %temp%\process.ps1" PSFile = WshShell.Run(Command,0,True) return = WshShell.Run("powershell.exe -ExecutionPolicy Unrestricted -File %temp%\process.ps1", 0, true) Set fso = CreateObject("Scripting.FileSystemObject") Set file = fso.OpenTextFile(Temp &"\output.txt", 1) text = file.ReadAll ExampleOutput.Value=text file.Close document.body.style.cursor = "default" btnClick1.style.cursor = "default" btnClick1.disabled = False End Sub Sub Run_PS_Script2() ExampleOutput.value = "" btnClick2.disabled = True document.body.style.cursor = "wait" btnClick2.style.cursor = "wait" Dim WshShell,Command,PSFile,return,fso,file,text,Temp Set WshShell = CreateObject("WScript.Shell") Temp = WshShell.ExpandEnvironmentStrings("%Temp%") Command = "cmd /c echo Get-NetAdapter ^| select Name,MacAddress ^| Where-Object {$_.Name -like 'Ethernet'} ^| Out-File %temp%\output.txt -Encoding ascii > %temp%\process.ps1" PSFile = WshShell.Run(Command,0,True) return = WshShell.Run("powershell.exe -ExecutionPolicy Unrestricted -File %temp%\process.ps1", 0, true) Set fso = CreateObject("Scripting.FileSystemObject") Set file = fso.OpenTextFile(Temp &"\output.txt", 1) text = file.ReadAll ExampleOutput.Value=text file.Close document.body.style.cursor = "default" btnClick2.style.cursor = "default" btnClick2.disabled = False End Sub </script> </head> <body bgcolor="123456"> <center> <textarea id="ExampleOutput" style="width:35%" rows="7"></textarea> </center> <br> <center><input type="button" name="btnClick1" value="Get MAC Address Teacher " onclick="Run_PS_Script1()"></center> <br> <center><input type="button" name="btnClick2" value="Get MAC Address Student " onclick="Run_PS_Script2()"></center> </body> </html> Edited March 15, 2017 by alrlms Link to comment Share on other sites More sharing options...
gunsmokingman Posted March 15, 2017 Share Posted March 15, 2017 Here is a rewrite of your code that you posted, I removed all the redundant code and added a function to process the text file. <script language="VBScript"> Option Explicit '-> Objects For Run Time Dim fso :Set fso = CreateObject("Scripting.FileSystemObject") Dim WshShell :Set WshShell = CreateObject("WScript.Shell") Dim Temp :Temp = Temp = WshShell.ExpandEnvironmentStrings("%Temp%") '-> Varibles For Run Time Dim Command, PSFile, return, file,text '-> Button 01 Click Function Run_PS_Script1() ExampleOutput.value = "" btnClick1.disabled = True document.body.style.cursor = "wait" btnClick1.style.cursor = "wait" Command = "cmd /c echo Get-NetAdapter ^| select Name,MacAddress ^| Where-Object {$_.Name -like 'Ethernet' -or $_.Name -like 'Wi-Fi'} ^| Out-File %temp%\output.txt -Encoding ascii > %temp%\process.ps1" PSFile = WshShell.Run(Command,0,True) return = WshShell.Run("powershell.exe -ExecutionPolicy Unrestricted -File %temp%\process.ps1", 0, true) '-> Replace It With A Function, So It Can Be Access More than Once ReadTheFile() document.body.style.cursor = "default" btnClick1.style.cursor = "default" btnClick1.disabled = False End Function '-> Button 02 Click Function Run_PS_Script2() ExampleOutput.value = "" btnClick2.disabled = True document.body.style.cursor = "wait" btnClick2.style.cursor = "wait" Command = "cmd /c echo Get-NetAdapter ^| select Name,MacAddress ^| Where-Object {$_.Name -like 'Ethernet'} ^| Out-File %temp%\output.txt -Encoding ascii > %temp%\process.ps1" PSFile = WshShell.Run(Command,0,True) return = WshShell.Run("powershell.exe -ExecutionPolicy Unrestricted -File %temp%\process.ps1", 0, true) Set fso = CreateObject("Scripting.FileSystemObject") '-> Replace It With A Function, So It Can Be Access More than Once ReadTheFile() document.body.style.cursor = "default" btnClick2.style.cursor = "default" btnClick2.disabled = False End Function '-> Read The Text File Dislay The Results, From Button 01 And Button 02 Function ReadTheFile() Set file = fso.OpenTextFile(Temp &"\output.txt", 1) text = file.ReadAll ExampleOutput.Value=text file.Close End Function </script> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now