Get and execute command in HTA - hta

I'm new in scripting. I need the code to receive some arguments and execute it in hidden cmd in HTA.
the command to execute is
netsh wlan set hosted mode=allow ssid="name" key="pwd"
Here i want to get "name" and "pwd" from submit box and execute the above command in hidden hta.
I made it, but not working properly. See
<script language="VBScript" type="text/vbscript">
set objShell = CreateObject("WScript.Shell")
strOut=""
sub StartProgram
cmdarg="%comspec% /c netsh wlan set hosted mode=allow ssid=" & T1.value "key=" & T2.value
iReturn=objShell.Run(cmdarg, 0, True)
If iReturn = 0 Then
MsgBox "Success"
Else
MsgBox "Cannot Start"
End If
TraceOut.innerHTML= strOut
end sub
</script>

I don't know if this is the whole problem, but at the very least:
cmdarg="%comspec% /c netsh wlan set hosted mode=allow ssid=" & T1.value "key=" & T2.value
should be
cmdarg="%comspec% /c netsh wlan set hosted mode=allow ssid=" & T1.value & " key=" & T2.value
In other words, you left an ampersand out after T1.value, and left a space out before key=.

Related

Need help adding a "Kill Switch"

I am writing a code in AutoIt, but need help with a kill switch to stop any processes that I accidently started.
Below is the example of the code that I started that I need a kill switch added to it.
HotKeySet('{PGDN}', 'Intro')
HotKeySet('{F3}', 'ENTgac')
HotKeySet('{F4}', 'LockedENT')
HotKeySet('{F5}', 'VDI')
HotKeySet('{F6}', 'SecurityHold')
HotKeySet('{F7}', 'Printer')
HotKeySet('{F9}', 'AllThingsZ')
HotKeySet('{F10}', 'Bitlocker')
HotKeySet('{F11}', 'Chrome')
While 1
Sleep(50)
WEnd
Func Intro ()
Send('Username: ' & #CRLF)
Send('Computer name: ' & #CRLF)
Send('R' & #CRLF)
Send('Callback number: ' & #CRLF)
Send('Teleworking: ')
EndFunc
Func ENTgac ()
Send("User unable to login and receiving error: 'Must Use Windows Hello error'" & #CRLF)
Send('Had user moved into Pending OU for No Valid Card' & #CRLF)
Send('Had allownongac pushed to INSERT CPU NAME' & #CRLF)
Send('Confirmed user was able to login')
EndFunc
Func LockedENT ()
Send('Confirmed account lock through cmd > Account Active: Locked' & #CRLF)
Send('Unlocked in NIQ, advised user to login' & #CRLF)
Send('Confirmed user was able to login')
EndFunc
Func AllThingsZ ()
Send('In Zscaler Updated Policy, Updated App, Clear Logs, Repair App, Restart Service' & #CRLF)
EndFunc
Func Bitlocker ()
Send('User was prompted for Bitlocker Recovery Key' & #CRLF)
Send('Verified user' & #CRLF)
Send('Recited Bitlocker Recovery Key to user' & #CRLF)
Send('Confirmed user was able to login')
EndFunc
Func VDI ()
Send('Guided user through obtaining an secureauth otp code: otp.gsa.gov' & #CRLF)
Send('Guided user through logging into vdi.anywhere.gsa.gov and selecting Light Version for web access' & #CRLF)
Send('User was successfully able to open Standard Desktop')
EndFunc
Func Chrome ()
Send('Made sure Google Chrome was up to date' & #CRLF)
Send('Cleared cookies/cache/history (Settings > Privacy and Security > Clear Browsing Data > Time Range (All Time) > Clear Data)')
EndFunc
Func SecurityHold ()
Send('Provided user with RISSO group email address to contact for approval: risso#gsa.gov' & #CRLF)
Send('User was put in a Security Hold due to failure to complete ROB' & #CRLF)
Send('Submitted Re-Enable request for the user: Enter RITM' & #CRLF)
Send('Submitted Security Compliance Training on users behalf: Enter RITM')
EndFunc
Func Printer ()
Send('Remoted in COMPUTER NAME via BigFix' & #CRLF)
Send('Pressed the “Windows” and “R” keys at the same time' & #CRLF)
Send('Ran printer server by location listed in KB0026350' & #CRLF)
Send('Connected to printer' & #CRLF)
Send('Confirmed test page printed successfully')
EndFunc
Thank you again for any assistance provided. I will provide any information that is needed as quickly as I can.
I have attempted to add like a "Terminate" like below:
Func Terminate()
Exit
;EndSwitch
EndFunc ;==>Terminate
But when I attempt to run it, it does not work

Use slash option in R system function

I am trying to use following cmd function inside R
rmdir /q /s myDir
I tried:
system("rmdir /q /s myDir")
but it returns an error:
rmdir: failed to remove '/q': No such file or directory
rmdir: failed to remove '/s': No such file or directory
rmdir: failed to remove 'public_html/croecon.contentio.biz': Directory not empty
How should I use slash option, e.g. /q?
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set objEvents = objWMIService.ExecNotificationQuery("SELECT * FROM Win32_ProcessStartTrace")
Do
Set objReceivedEvent = objEvents.NextEvent
Set colItems = objWMIService.ExecQuery("Select * From Win32_Process where ProcessID=" & objReceivedEvent.ProcessID)
For Each objItem in colItems
wscript.echo objItem.name & " " & objItem.ProcessID & " " & objItem.CommandLine
Next
Loop
Then type in a command prompt
cscript //nologo C:\folder\MonitorProcessCreation.vbs
This will monitor what starts when you run your command.

AutoIt Firefox _FFClick doesn't work on button? (FF.au3)

Using the firefox plugin ("ff-au3") for AutoIt, how do I click a button?
Here is the HTML of the item I'd like to click:
<input accesskey="s" class="aui-button" id="login-form-submit" name="login" title="Press Alt+s to submit this form" type="submit" value="Log In">
And here is the code snippet to click the button:
;Click the "Log In" button, id is "login-form-submit"
_FFClick("login-form-submit", "id")
At this point, my script is already connected to firefox, already on the page I need, and everything else works (except for this click part!)
Here is the error I get back:
_FFClick ==> No match: $sElement: FFau3.WCD.getElementById('login-form-submit')
Also, this works when I manually run it on the page using a javascript console:
document.getElementById("login-form-submit")
And here is the API for the plugin: http://english.documentation.ff-au3.thorsten-willert.de/ff_functions/_FFClick.php
Anyone see anything I'm doing wrong?
Versions:
Firefox 44.0.1
AutoIt v3.3.14.2
FF V0.6.0.1b-15.au3 (Firefox plugin)
MozRepl v.1.1.2
SciTE-Lite v. 3.5.4
Well this didn't get much traffic but I found the solution! Pretty simple... I disconnected from firefox before executing the click!
When using firefox, you first need to open the firefox exe with the "Run" command, then you need to connect to firefox using the "_FFConnect" command. Next you can start clicking elements. Once you're done, disconnect from firefox using the "ProcessClose" command. The problem I was running into was I connected to firefox, then disconnected immediately, then I tried clicking. So, I made sure I disconnected after I did the clicking...
Working solution: myScript.au3 (See the "LogIn" function at the bottom)
#include <Constants.au3>
#include <MsgBoxConstants.au3>
#include <File.au3>
#include <EventLog.au3>
#include <FF V0.6.0.1b-15.au3> ;FireFox
OpenLog()
OpenFirefox()
ConnectToFirefox()
LogIn()
; ////////////////////////////////////////////////////
; Configure the Log
; ////////////////////////////////////////////////////
Func OpenLog()
Global $log = FileOpen("K:\Log.txt", 2)
; Check if file opened for reading OK
If $log == -1 Then
FileWrite($log,"[ERROR] Could not open log file." & #CRLF)
MsgBox(0, "Error", "Unable to open log file.", [ timeout = 0])
Exit
Else
FileWrite($log,"[INFO] Opened log file successfully." & #CRLF)
EndIf
EndFunc
; ////////////////////////////////////////////////////
; Open Firefox
; ////////////////////////////////////////////////////
Func OpenFirefox()
;Run Firefox in Maximized
Global $ffPid = Run("C:\Program Files (x86)\Mozilla Firefox\firefox.exe","",#SW_MAXIMIZE)
; Check if firefox was opened OK
If #error <> 0 Then
FileWrite($log,"[ERROR] Could not open firefox." & #CRLF)
MsgBox(0, "Error", "Could not open firefox.", [ timeout = 0])
Exit
Else
FileWrite($log,"[INFO] Firefox opened successfully." & #CRLF)
EndIf
;Wait 10 seconds for Firefox to open
$result = WinWait("[CLASS:MozillaWindowClass]","",10)
; Check if file opened for reading OK
If $result == 0 Then
FileWrite($log,"[ERROR] Unable to open firefox class." & #CRLF)
MsgBox(0, "Error", "Unable to open firefox class.", [ timeout = 0])
Exit
Else
FileWrite($log,"[INFO] Opened firefox class successfully." & #CRLF)
EndIf
;Wait for 2 seconds after opening
Sleep(2000)
EndFunc
; ////////////////////////////////////////////////////
; Connect To Firefox
; ////////////////////////////////////////////////////
Func ConnectToFirefox()
; trying to connect to a running FireFox with MozRepl on
If _FFConnect(Default, Default, 3000) Then
FileWrite($log,"[INFO] Connected to Firefox." & #CRLF)
Else
FileWrite($log,"[ERROR] Can't connect to FireFox!" & #CRLF)
MsgBox(64, "", "Can't connect to FireFox!")
EndIf
;Wait for 2 seconds after opening
Sleep(2000)
EndFunc
; ////////////////////////////////////////////////////
; Log into page
; ////////////////////////////////////////////////////
Func LogIn()
;Load Login Page
_FFOpenURL("http://localhost/login.jsp")
Sleep(2000)
If #error <> 0 Then
FileWrite($log,"[ERROR] Could not open URL." & #CRLF)
MsgBox(0, "Error", "Could not open URL.", [ timeout = 0])
Exit
Else
FileWrite($log,"[INFO] Opened URL successfully." & #CRLF)
EndIf
Sleep(2000)
;Click the "Log In" button, id is "login-form-submit"
;<input accesskey="s" class="aui-button" id="login-form-submit" name="login" title="Press Alt+s to submit this form" type="submit" value="Log In">
_FFClick("login-form-submit", "id")
If #error <> 0 Then
FileWrite($log,"[ERROR] Could not click login button." & #CRLF)
MsgBox(0, "Error", "Could not click login button:", [ timeout = 0])
Exit
Else
FileWrite($log,"[INFO] Found and clicked login button successfully." & #CRLF)
EndIf
EndFunc

Cursor Engine error '80004005'

There is a server in my company and its IP address has changeed yesterday !
And now there is a asp page could not work !
it shows:
Microsoft Cursor Engine error '80004005'
Data provider or other service returned an E_FAIL status.
/ccall/split.inc, line 23
here is the code:
<%
mypage=request("whichpage")
If mypage="" then
mypage=1
end if
mypagesize=request("pagesize")
If mypagesize="" then
mypagesize=200
end if
mysql=request("SQLquery")
IF mySQL="" THEN
mySQL=SQL
END IF
myrs.cursorlocation=3
myrs.cachesize=5
myrs.Open sql,myconn,adOpenStatic
if not myrs.eof and not myrs.bof then
myrs.movefirst
myrs.pagesize=mypagesize
maxpages=cint(myrs.pagecount)
maxrecs=cint(myrs.pagesize)
myrs.AbsolutePage=mypage
howmanyrecs=0
howmanyfields=myrs.fields.count -1
end if
%>
what make me confused is that it can work fine before ip changing.
-- EDIT --
set myconn=server.createobject("ADODB.CONNECTION")
myconn.open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("order.mdb") & ";"

RDP session launch applications

I have opened an RDP session using AutoIt. Here is the code:
$host = "" ; <---- IP
$hGUI = GUICreate("Terminal Serveur", 952, 675, -1, -1, $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
$oRDP = ObjCreate("MsTscAx.MsTscAx.2")
$oRDP_Ctrl = GUICtrlCreateObj($oRDP, 64, 44, 800, 600)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
GUICtrlSetStyle($oRDP_Ctrl , $WS_VISIBLE)
$oRDP.DesktopWidth = 800
$oRDP.DesktopHeight = 600
$oRDP.Fullscreen = False
$oRDP.ColorDepth = 16
$oRDP.AdvancedSettings3.SmartSizing = True
$oRDP.Server = $host
$oRDP.UserName = "" ; <--- Username
$oRDP.Domain = ""
$oRDP.AdvancedSettings2.ClearTextPassword = "" ; <--- Password
$oRDP.ConnectingText = "Connecting to " & $host
$oRDP.DisconnectedText = "Disconnected from " & $host
$oRDP.StartConnected = True
$oRDP.Connect()
$oShel = ObjCreate("shell.application")
$oShel_Ctrl = GUICtrlCreateObj($oShel, 64, 44, 800, 600)
GUICtrlSetStyle($oShel_Ctrl , $WS_VISIBLE)
GUISetState(#SW_SHOW, $hGUI)
Send ("#r") ; !!
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
$oRDP.Disconnect()
Exit
EndSwitch
WEnd
Now, I want to launch an application in the RDP session. I tried " Send(#r) " in order to send the path with a function like SendKeys but this command is execute on my computer and not on the remote computer.
How can I do please?
Send alt + home. This open the windows search in the rdp session, which you can then send it text e.g. send("notepad")
send({enter})
Update:
A much simpler alternative:
Change the Remote Desktop Connection Settings (not in the control
code, but in the usual windows shorcut. But it seems that could be done in the AutoIt code with the keyboardhook setting keyboardhook setting ) .
Look for the Options button, in the window when launching remote desktop.
On the Local Resources Tab select Windows key combinations are applied in full-screen mode only.
Change this line in your code:
$oRDP.Fullscreen = True
Include a pause to ensure the control has been loaded
Sleep(5000)
Send ("#r")
Previous answer:
Let my suggest a workaround not very 'elegant' but should work (tested ok):
In the remote desktop make a shorcut to the Windows Virtual Keyword (On-Screen Keyboard or OSK)
Find the position of the shorcut icon
In your code send a double click at this position to start the on-screen keyboard
Then send clicks to the positions of the desired keys
Something like this:
Sleep(5000)
MouseClick("left",512,191,2) ;start virtual keyword
Sleep(1000)
MouseClick("left",553,807,1) ;click
Sleep(100)
MouseClick("left",633,740,1)
Sleep(1000)
Send("notepad")
Sleep(1000)
Send("{ENTER}")
(Aside note: For any executable with a shortcut on the remote desktop simply send double click, without the need of the virtual keyboard)

Resources