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)
Related
I am new to OMNET++ (version 5.4) simulator and i have been trying to do some tutorials to learn it. Now I am working on doing an example Ethernet connections as in the picture.
and I have the following configuration in my ´net.ini´ file
[General]
# Configurator settings
*.net_configurator.dumpAddresses = true
*.net_configurator.dumpTopology = true
*.net_configurator.dumpLinks = true
*.net_configurator.dumpRoutes = true
# Routing settings
**.networkLayer.configurator.networkConfiguratorModule = ""
*.*.networkLayer.arpType = "GlobalARP"
*.*.routingTable.netmaskRoutes = ""
# Visualizer settings
*.visualizer.interfaceTableVisualizer.displayInterfaceTables = true
*.visualizer.interfaceTableVisualizer.nodeFilter = "not (*switch* or *Switch* or *AP*)"
[Config Step1]
network = net
description = "Fully automatic IP address assignment"
when I lunch the simulation i don't see any IP assigning . what could be the problem?
Change the line:
**.networkLayer.configurator.networkConfiguratorModule = ""
into:
**.networkLayer.configurator.networkConfiguratorModule = "net_configurator"
Other way is to do:
Change the name of IPv4NetworkConfigurator object to configurator.
Remove the line:
**.networkLayer.configurator.networkConfiguratorModule = ""
i'm running into an error in trying to start up the selenium firefox driver. it seems like others have hit snags at this step, and there is no readily available solution online, so hopefully this question will be broadly helpful. it seems like firefox is failing to establish an http server interface when initiated through selenium's driver. it appears that i can run firefox from the command line with no errors.
i should specify that i am doing this via ssh login to a linux container. i'm running python2.7 on Ubuntu 14.04 LTS (GNU/Linux 3.16.3-elastic x86_64). i have the latest version of selenium (2.44) installed, and i'm using firefox 34.0. i'm using xvfb to spoof a display.
below is my code, the error logs, and some related source code.
from selenium import webdriver
d = webdriver.Firefox()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 59, in __init__
self.binary, timeout),
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 47, in __init__
self.binary.launch_browser(self.profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 66, in launch_browser
self._wait_until_connectable()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 105, in _wait_until_connectable
raise WebDriverException("Can't load the profile. Profile "
selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Profile Dir: %s If you specified a log_file in the FirefoxBinary constructor, check it for details.
that error is raised here, due to a timeout:
def _wait_until_connectable(self):
"""Blocks until the extension is connectable in the firefox."""
count = 0
while not utils.is_connectable(self.profile.port):
if self.process.poll() is not None:
# Browser has exited
raise WebDriverException("The browser appears to have exited "
"before we could connect. If you specified a log_file in "
"the FirefoxBinary constructor, check it for details.")
if count == 30:
self.kill()
raise WebDriverException("Can't load the profile. Profile "
"Dir: %s If you specified a log_file in the "
"FirefoxBinary constructor, check it for details.")
count += 1
time.sleep(1)
return True
in the log_file:
tail -f logs/firefox_binary.log
1418661895753 addons.xpi DEBUG checkForChanges
1418661895847 addons.xpi DEBUG No changes found
1418661895853 addons.manager DEBUG Registering shutdown blocker for XPIProvider
1418661895854 addons.manager DEBUG Registering shutdown blocker for LightweightThemeManager
1418661895857 addons.manager DEBUG Registering shutdown blocker for OpenH264Provider
1418661895858 addons.manager DEBUG Registering shutdown blocker for PluginProvider
System JS : ERROR (null):0 - uncaught exception: 2147746065
JavaScript error: file:///tmp/tmplkLsLs/extensions/fxdriver#googlecode.com/components/driver-component.js, line 11507: NS_ERROR_NOT_AVAILABLE: Component is not available'Component is not available' when calling method: [nsIHttpServer::start]
*** Blocklist::_preloadBlocklistFile: blocklist is disabled
1418661908552 addons.manager DEBUG Registering shutdown blocker for <unnamed-provider>
one more point of information. early on, in the firefox driver initalization, socket.bind(('127.0.0.1',0)) was failing with a "can't assign requested address" error. i changed the location to (0.0.0.0,0) and edited the localhost entry in my /etc/hosts, and was able to bind that way. not sure if that could be causing the current failure though.
VV edits per louis's request VV . i specify the two lines where i change the localhost address.
def free_port():
"""
Determines a free port using sockets.
"""
free_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
free_socket.bind(('0.0.0.0', 0)) # changed from 127.0.0.1
free_socket.listen(5)
port = free_socket.getsockname()[1]
free_socket.close()
return port
def is_connectable(port):
"""
Tries to connect to the server at port to see if it is running.
:Args:
- port: The port to connect.
"""
try:
socket_ = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socket_.settimeout(1)
socket_.connect(("0.0.0.0", port)) # changed again
socket_.close()
return True
except socket.error:
return False
here's the constructor from webdriver:
def __init__(self, firefox_profile=None, firefox_binary=None, timeout=30,
capabilities=None, proxy=None):
self.binary = firefox_binary
self.profile = firefox_profile
if self.profile is None:
self.profile = FirefoxProfile()
self.profile.native_events_enabled = (
self.NATIVE_EVENTS_ALLOWED and self.profile.native_events_enabled)
if self.binary is None:
self.binary = FirefoxBinary()
if capabilities is None:
capabilities = DesiredCapabilities.FIREFOX
if proxy is not None:
proxy.add_to_capabilities(capabilities)
RemoteWebDriver.__init__(self,
command_executor=ExtensionConnection("127.0.0.1", self.profile,
self.binary, timeout),
desired_capabilities=capabilities,
keep_alive=True)
self._is_remote = False
here's the constructor from extension_connector:
def __init__(self, host, firefox_profile, firefox_binary=None, timeout=30):
self.profile = firefox_profile
self.binary = firefox_binary
HOST = host
if self.binary is None:
self.binary = FirefoxBinary()
if HOST is None:
HOST = "127.0.0.1"
PORT = utils.free_port()
self.profile.port = PORT
self.profile.update_preferences()
self.profile.add_extension()
self.binary.launch_browser(self.profile)
_URL = "http://%s:%d/hub" % (HOST, PORT)
RemoteConnection.__init__(
self, _URL, keep_alive=True)
in posting my edits to louis's comment, i saw that my localhost issue turned up in other locations, as the host is hardcoded in twice more. i had my server master address the issue, changed everything in the source back to 127, and the problem was solved. thanks for prompting me, #louis, and i'm sorry my question wasn't more interesting. will accept my own answer after 2 days when SO allows me.
I have an AutoIt script in which I open a settings dialog from a system tray menu entry. When opening the dialog this way, messages via button clicks are not handled.
On the other hand, when opening the dialog directly (as indicated in the code below, which you can easily test by uncommenting this call and commenting out the call for the system tray entry), then the messages are handled successfully.
Here is my script. When calling SettingsDialog directly (without going via the systray menu), the OK and Cancel buttons work, but otherwise not.
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
;; Start program in system tray
SetupSystemTrayEntry()
;; When calling settings dialog directly, messages are handled properly
;;SettingsDialog()
Func SetupSystemTrayEntry()
Opt("TrayMenuMode", 1)
$settingsitem = TrayCreateItem("Settings")
TrayCreateItem("")
$exititem = TrayCreateItem("Exit")
TraySetState()
While 1
Local $traymsg = TrayGetMsg()
Select
Case $traymsg = 0
ContinueLoop
Case $traymsg = $settingsitem
SettingsDialog() ;; Bring up settings dialog
Case $traymsg = $exititem
Exit ;; Exit program
EndSelect
WEnd
EndFunc
Func SettingsDialog()
GUICreate("Settings", 400, 150, #DesktopWidth / 2 - 200, #DesktopHeight / 2 - 75)
$ok_button = GUICtrlCreateButton("OK", 100, 100, 80, 25, $BS_DEFPUSHBUTTON)
$cancel_button = GUICtrlCreateButton("Cancel", 200, 100, 80, 25)
GUISetState()
Do
;; These messages are never handled when the dialog is brought up from
;; the system tray menu entry above, but when calling this function
;; directly, it works
Local $settmsg = GUIGetMsg()
Select
Case $settmsg = $ok_button
ExitLoop
Case $settmsg = $cancel_button
ExitLoop
EndSelect
Until $settmsg = $GUI_EVENT_CLOSE
EndFunc
Seems all fine, except you should do something after you left the Do/Until loop.
Func SettingsDialog()
GUICreate("Settings", 400, 150, #DesktopWidth / 2 - 200, #DesktopHeight / 2 - 75)
$ok_button = GUICtrlCreateButton("OK", 100, 100, 80, 25, $BS_DEFPUSHBUTTON)
$cancel_button = GUICtrlCreateButton("Cancel", 200, 100, 80, 25)
GUISetState()
Do
;; These messages are never handled when the dialog is brought up from
;; the system tray menu entry above, but when calling this function
;; directly, it works
Local $settmsg = GUIGetMsg()
ConsoleWrite(#HOUR & ":" & #MIN & ":" & #SEC & "," & #MSEC & "msg = " & $settmsg & #CRLF)
Select
Case $settmsg = $ok_button
ExitLoop
Case $settmsg = $cancel_button
ExitLoop
EndSelect
Until $settmsg = $GUI_EVENT_CLOSE
Return GUIDelete()
Endfunc
I added 2 lines, the ConsoleWrite after calling GUIGetMessage and the Return after the loop.
When I run this script the Settings Dialog is properly closed by either clicking 'Ok' or 'Cancel'.
As per solution provided on the AutoIt forum, here is a version of the script that hides and shows the dialog on each usage. There is a big caveat (read the forum thread for details) in that on creation of the dialog, it must be explicitly hidden!
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
; Do not declare Global variables in a function <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Global $settings_window_handle, $ok_button, $cancel_button
;; Set up settings dialog
InitSettingsDialog();
;; Start program in system tray
SetupSystemTrayEntry()
Func SetupSystemTrayEntry()
Opt("TrayMenuMode", 1)
$settingsitem = TrayCreateItem("Settings")
TrayCreateItem("")
$exititem = TrayCreateItem("Exit")
TraySetState()
While 1
Switch TrayGetMsg()
Case $settingsitem
ShowSettingsDialog() ;; Bring up settings dialog
Case $exititem
Exit ;; Exit program
EndSwitch
WEnd
EndFunc ;==>SetupSystemTrayEntry
Func InitSettingsDialog()
; Create
$settings_window_handle = GUICreate("Settings", 400, 150, #DesktopWidth / 2 - 200, #DesktopHeight / 2 - 75)
$ok_button = GUICtrlCreateButton("OK", 100, 100, 80, 25, $BS_DEFPUSHBUTTON)
$cancel_button = GUICtrlCreateButton("Cancel", 200, 100, 80, 25)
GUISetState(#SW_HIDE, $settings_window_handle)
EndFunc ;==>SettingsDialog
Func ShowSettingsDialog()
GUISetState(#SW_SHOW, $settings_window_handle)
While 1
Switch GUIGetMsg()
Case $ok_button
MsgBox(0, "test", "test")
ExitLoop
Case $cancel_button
ExitLoop
EndSwitch
WEnd
GUISetState(#SW_HIDE, $settings_window_handle)
EndFunc
I'm new to Erlang and I am writing a basic server. I am trying to figure out how to correctly kick a client from the server using the information that I have about the client (which is Pid, Client_socket, and Client_name.
Any suggestions would be great and much appreciated. Thanks for reading :)
Here's my code so far:
-module(cell_clnt).
-export([cell_client/0]).
cell_client()->
%%% Add any needed parameters for your cell process here
Port = 21,
Pending_connections = 5,
Cell = fun()-> cell_process() end,
spawn(fun()-> timer:sleep(10), keyboard_loop(Cell) end),
receive
stop->
ok
end.
keyboard_loop(Cell)->
case io:get_line(">> ") of
"quit\n"->
io:fwrite("Exiting...~n"),
if is_pid(Cell)-> Cell!stop; true->ok end;
"start\n" when is_function(Cell)->
keyboard_loop(spawn(Cell));
Input when is_pid(Cell)->
Cell!{input,Input},
keyboard_loop(Cell);
_Input->
io:fwrite("No cell process active yet!~n"),
keyboard_loop(Cell)
end.
%%% Edit this to implement your cell process %%%
cell_process()->
io:fwrite("In cell~n"),
{ok,Listening_socket} = gen_tcp:listen(21,
[binary,
{backlog,5},
{active,false},
{packet,line}]),
loop(Listening_socket,[]).
loop(Listening_socket, Clients)->
io:format("Clients: ~p", [Clients]),
case gen_tcp:accept(Listening_socket) of
{ok,Client_socket} ->
gen_tcp:send(Client_socket, "Hello, what is your name?"),
{_,Name} = gen_tcp:recv(Client_socket,0),
gen_tcp:send(Client_socket, "Hello, "),
gen_tcp:send(Client_socket, Name),
Pid = spawn(fun()-> client_loop(Client_socket) end),
loop(Listening_socket,[{Pid,Client_socket,Name}|Clients])
end.
client_loop(Client_socket)->
case gen_tcp:recv(Client_socket,0) of
{ok,Message}-> gen_tcp:send(Client_socket,Message),
client_loop(Client_socket);
{error,Why}-> io:fwrite("Error: ~s~n",[Why]),
gen_tcp:close(Client_socket)
end.
Use when you need close a TCP socket and kill process:
gen_tcp:close(Socket)
exit(Pid, kill).
You can close a socket by killing the pid, like this:
erlang:exit(Pid, kill)
I have written a sample KMDF driver. I dont know if I did every thing right but have seen KMDF driver printing Debug message in DebugView utility - when I added this driver as new hardware. It also showed up as "Sample Device" under device manager.
Now I want to write a sample client that could call this Driver - so I can establish a connection between driver and client. I read that we need to use 'CreateFile' and 'DEviceIOControl' etc. But I am not able to get a start on it.
Can you please guide me around creating sample client to access the sample KMDF driver ?
My INF file for the driver looks like this :-
***My INF FILE****
; myshelldriver.INF
; Windows installation file for installing the myshelldriver driver
; Copyright (c) Microsoft Corporation All rights Reserved
;
; Installation Notes:
;
; Using Devcon: Type "devcon install myshelldriver.inf myshelldriver" to install
;
[Version]
Signature="$WINDOWS NT$"
Class=Sample
ClassGuid={78A1C341-4539-11d3-B88D-00C04FAD5171}
Provider=%MSFT%
DriverVer=09/24/2012,1.0
CatalogFile=myshell.cat
[DestinationDirs]
DefaultDestDir = 12
[ClassInstall32]
Addreg=SampleClassReg
[SampleClassReg]
HKR,,,0,%ClassName%
HKR,,Icon,,-5
[DiskCopyfiles]
wdfmyshelldriver.sys
[SourceDisksNames]
1=%InstDisk%,
[SourceDisksFiles]
Wdfmyshelldriver.sys=1
[Manufacturer]
%MSFT% = DiskDevice,NTAMD64
; For Win2K
[DiskDevice]
%DiskDevDesc% = DiskInstall, wdfmyshelldriver
; For XP and later
[DiskDevice.NTAMD64]
%DiskDevDesc% = DiskInstall, wdfmyshelldriver
[DiskInstall.NT]
CopyFiles = DiskCopyfiles
;;specify that this is the installation
;;for nt based systems.
[DriverInstall.ntx86]
DriverVer=09/24/2012,1.0
CopyFiles=DriverCopyFiles
[DiskInstall.NT.Services]
AddService = wdfmyshelldriver, %SPSVCINST_ASSOCSERVICE%, DiskServiceInst
[DiskServiceInst]
ServiceType = %SERVICE_KERNEL_DRIVER%
StartType = %SERVICE_DEMAND_START%
ErrorControl = %SERVICE_ERROR_NORMAL%
DisplayName = %DiskServiceDesc%
ServiceBinary = %12%\Wdfmyshelldriver.sys
AddReg = DiskAddReg
[DiskAddReg]
HKR, "Parameters", "BreakOnEntry", %REG_DWORD%, 0x00000000
HKR, "Parameters", "DiskSize", %REG_DWORD%, 0x00100000
HKR, "Parameters", "DriveLetter", %REG_SZ%, "R:"
HKR, "Parameters", "RootDirEntries", %REG_DWORD%, 0x00000200
HKR, "Parameters", "SectorsPerCluster", %REG_DWORD%, 0x00000002
[Strings]
MSFT = "Microsoft"
ClassName = "My Shell Device"
DiskDevDesc = "WDF My Shell Driver"
DiskServiceDesc = "myshelldriver Driver"
InstDisk = "myshelldriver Install Disk"
;*******************************************
;Handy macro substitutions (non-localizable)
SPSVCINST_ASSOCSERVICE = 0x00000002
SERVICE_KERNEL_DRIVER = 1
SERVICE_DEMAND_START = 3
SERVICE_ERROR_NORMAL = 1
REG_DWORD = 0x00010001
REG_SZ = 0x00000000
**** END OF INF FILE***
There are many relevant samples in the WDK. For example, take a look at KMDF Echo sample.
First you will need to name your object.
Second you will need to do at least one of the following:
Create a Symbolic link in the \GLOBAL??\
Register a Device Interface.
Option 1 will let you do the simple
CreateFile("\\\\.\\<device_name>, ...);
Option 2 and you will need to use the Setup DI Api routines to find your device to open it.