 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
tank
Joined: 21 Dec 2007 Posts: 676
|
Posted: Thu May 29, 2008 3:32 am Post subject: |
|
|
or you can execute the loop as ahk
| Code: |
mycode=
(
dim some_vb_var
some_vb_var=true
)
some_vb_var=false
loop
{
ifnotequal,some_vb_var,true
break
WS_Exec(mycode)
WS_Eval(ahkoutput,"some_vb_var,")
}
|
you get the idea
could also be
| Code: |
settimer,mysub,60000 ; 60 seconds
mycode=
(
dim some_vb_var
some_vb_var=true
)
some_vb_var=false
return
mysub:
ifnotequal,some_vb_var,true
exitapp
WS_Exec(mycode)
WS_Eval(ahkoutput,"some_vb_var,")
return
|
WELL YOU GET THE GIST _________________ Read this
Com
Automate IE7 with Tabs |
|
| Back to top |
|
 |
Rad777
Joined: 05 Jul 2007 Posts: 9
|
Posted: Thu May 29, 2008 3:21 pm Post subject: |
|
|
| erictheturtle wrote: | With a quick glance I see the problem of using the WScript object. The WScript object is unfortunately only available to scripts (vbs or js) that are run by the wscript.exe or cscript.exe programs.
Try changeing your | Code: | | WScript.CreateObject(...) | to justand see what happens. |
THAT WAS IT! Woot! Thank you! |
|
| Back to top |
|
 |
IN2ITive
Joined: 15 Apr 2008 Posts: 47
|
Posted: Thu May 29, 2008 3:45 pm Post subject: |
|
|
OK, think i get what you are saying (still very ripe behind the ahk ears)...
So, I have these variables to persist through the script:
| Code: | objTcp =
objConstants =
strComputer =
objWMIService =
contents = |
Then I have this code, which seems to execute properly (I get the message box with the "." ) I then get the Test1 messagebox and Test2 messagebox as expected.
| Code: | WS_Initialize("VBScript")
initcode=
(
Set objTcp = CreateObject("ActiveXperts.Tcp")
Set objConstants = CreateObject("ActiveXperts.ASConstants")
objTcp.Protocol = objConstants.asSOCKET_PROTOCOL_RAW
objTcp.Connect "servername", 6008
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
MsgBox(strComputer)
)
ok := WS_Exec(initcode)
If (!ok)
Msgbox Error:`n%ErrorLevel%
Msgbox, Test1
Settimer, AddToGUI, 5000
Msgbox, Test2
Return |
Here is the mycode section and AddToGUI:
| Code: |
mycode=
(
Msgbox("Here")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM __InstanceOperationEvent WITHIN 1 WHERE " _
& "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
& "TargetInstance.GroupComponent= " _
& "'Win32_Directory.Name=""c:\\\\TestListener""'")
Set objEventObject = colMonitoredEvents.NextEvent()
Select Case objEventObject.Path_.Class
Case "__InstanceCreationEvent"
Set objFSO = CreateObject("Scripting.FileSystemObject")
strReturned = objEventObject.TargetInstance.PartComponent
CurrentItem = Split(strReturned, "CIM_DataFile.Name=")(1)
CurrentItem = Replace(CurrentItem, """", "")
CurrentItem = Replace(CurrentItem, "\\", "\")
Set filetxt = objFSO.OpenTextFile(CStr(CurrentItem), 1, False)
contents = filetxt.ReadAll
filetxt.Close
contents = Chr(11) & contents & Chr(28) & Chr(13)
For i = 1 To Len(contents)
objTcp.SendByte Asc(mid(contents, i, 1))
Next
End Select
)
AddToGUI:
Msgbox, I am here
WS_Exec(mycode)
WS_Eval(strComputer, "strComputer")
ws_Eval(contents, "contents")
MsgBox, %strComputer%
MsgBox, %contents%
Return |
The problem I have is that it never seems to execute the mycode section (I never see the messagebox "Here"). I don't get errors (code continues to loop).
I thought what I would be able to do is use the timer , execute the code, and then update GUI with information...but obviously I am missing something (again )
The initcode section sets some objects and if they are persisted then the mycode section should work.
Thanks. |
|
| Back to top |
|
 |
erictheturtle
Joined: 27 Jun 2007 Posts: 58 Location: California
|
Posted: Thu May 29, 2008 5:42 pm Post subject: |
|
|
That looks really good IN2ITive. I think with a little fix it might finally work.
Try this code out | Code: |
WS_Initialize("VBScript")
initcode=
(
Set objTcp = CreateObject("ActiveXperts.Tcp")
Set objConstants = CreateObject("ActiveXperts.ASConstants")
objTcp.Protocol = objConstants.asSOCKET_PROTOCOL_RAW
objTcp.Connect "servername", 6008
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
MsgBox(strComputer)
)
ok := WS_Exec(initcode)
If (!ok)
Msgbox Error:`n%ErrorLevel%
mycode=
(
Msgbox("Here")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM __InstanceOperationEvent WITHIN 1 WHERE " _
& "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
& "TargetInstance.GroupComponent= " _
& "'Win32_Directory.Name=""c:\\\\TestListener""'")
Set objEventObject = colMonitoredEvents.NextEvent()
Select Case objEventObject.Path_.Class
Case "__InstanceCreationEvent"
Set objFSO = CreateObject("Scripting.FileSystemObject")
strReturned = objEventObject.TargetInstance.PartComponent
CurrentItem = Split(strReturned, "CIM_DataFile.Name=")(1)
CurrentItem = Replace(CurrentItem, """", "")
CurrentItem = Replace(CurrentItem, "\\", "\")
Set filetxt = objFSO.OpenTextFile(CStr(CurrentItem), 1, False)
contents = filetxt.ReadAll
filetxt.Close
contents = Chr(11) & contents & Chr(28) & Chr(13)
For i = 1 To Len(contents)
objTcp.SendByte Asc(mid(contents, i, 1))
Next
End Select
)
Msgbox, Test1
Settimer, AddToGUI, 5000
Msgbox, Test2
Return
AddToGUI:
Msgbox, I am here
ok := WS_Exec(mycode)
If (!ok)
Msgbox Error:`n%ErrorLevel%
WS_Eval(strComputer, "strComputer")
WS_Eval(contents, "contents")
MsgBox, %strComputer%
MsgBox, %contents%
Return |
I think the only problem was you need to assign the 'mycode' variable during the startup. I also added an error check to report what might be going wrong when 'mycode' is executed. _________________ -m35 |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 676
|
Posted: Thu May 29, 2008 10:34 pm Post subject: |
|
|
yes what he said you return before mycode was set then call the lable completely bypassing mycode from getting initialized _________________ Read this
Com
Automate IE7 with Tabs |
|
| Back to top |
|
 |
IN2ITive
Joined: 15 Apr 2008 Posts: 47
|
Posted: Fri May 30, 2008 2:12 am Post subject: |
|
|
As you can see, still a newbie! Thanks for the code Eric and thanks for the explanation Tank. It is working!
...except for one issue...
Because we removed the loop (the "Do While TRUE" loop), if there is 5 new files detected it actually only sends one.
If we place the loop back in the code then we will run back into the problem where the rest of the code never gets executed.
Either way, it is not a big issue in my scenario since it will almost always be one file placed in the folder, and then some automation verification done on whatever the contents of the file sent to the server was. The code should work in my scenario. But is there anyway that you can think of to solve the problem where 5 files are placed in the listening directory at the same time.
Anyways...Eric and Tank...enjoy a cold virtual beer on me  |
|
| Back to top |
|
 |
Guest
|
Posted: Fri May 30, 2008 4:31 am Post subject: |
|
|
| can you not set some returnable value in your loop so that it can be evaluated with an if statement? |
|
| Back to top |
|
 |
erictheturtle
Joined: 27 Jun 2007 Posts: 58 Location: California
|
Posted: Thu Jul 03, 2008 6:13 pm Post subject: |
|
|
ws4ahk v0.21
- Numerous documentation improvements.
- Fixed error handling in WS_Initialize().
- WS_ReleaseObject(): added check to catch 0 or "" argument.
- Removed extraneous codef(), WS_ErrMsg(), and ScriptStr() functions.
- Renamed internal global variables to be more unique.
- Added MIT License as a formality.
I've removed the codef() function because I doubt anyone is using it. Of course if you are, it can easily be manually inclused in your scripts. The WS_ErrMsg() was just silly and shouldn't have been in there in the first place. The ScriptStr() was just a helper function that would call VBStr() or JStr() depending on the current language. Again, I doubt anyone needs it to keep track of the current language, and it is a task better left to each script writer to do.
Also a memory leak has been seen in the extreme case of thousands of WS_Initialize() and WS_Uninitialize() calls. I have posted a test script demonstrating it. I can't figure out why it's happening. If you see anything, please let me know.
Thanks. _________________ -m35 |
|
| Back to top |
|
 |
rani
Joined: 18 Mar 2008 Posts: 57
|
Posted: Fri Aug 15, 2008 6:21 am Post subject: run ahk from Javascript |
|
|
1.AHK from JS
how I can run ahk scripts, including gui instacne ,by ahk
from javascript code or from standard html web page ?
and not to save any code on clients ?
means:
run or 'browse' code from server
2. AHK as activex
is it possible to compile AHK as activex (dll activex or ocx)
so it can be run from <EMBED> tags in html ?
or there is other technique to do that ?
3. AHK exe from webpage
I can run direct the AHK exe from webpage ?
any sample code will be appreciated |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 676
|
Posted: Fri Aug 15, 2008 3:38 pm Post subject: |
|
|
the exe or .ahk would need to be downloaded to the client i would think or else any action would happen directly on the server.
If you can live with that i can answer most of what you said
but im not gonna bother to write up an answer unless you can live with that constraint otherwise lets see what eric thinks _________________ Read this
Com
Automate IE7 with Tabs |
|
| Back to top |
|
 |
HugoV
Joined: 27 May 2007 Posts: 495
|
Posted: Fri Aug 15, 2008 4:25 pm Post subject: Re: run ahk from Javascript |
|
|
| ell wrote: | 3. AHK exe from webpage
I can run direct the AHK exe from webpage? |
fyi:
AutoHotkey as CGI handler for LightTPD web server on Windows:
http://www.autohotkey.com/forum/topic27607.html _________________ When parsing a CSV file use Loop, parse, Inputvar, CSV! |
|
| Back to top |
|
 |
rani
Joined: 18 Mar 2008 Posts: 57
|
Posted: Sat Aug 16, 2008 4:35 pm Post subject: ahk from js |
|
|
Hi tank,
can it be silent download to client on 1st usage ?
or the user has to prompt by himself 1st time or whenever the ahk changed in server ?
if yes, what you suggest, if the answer is straight forward ? |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 676
|
Posted: Sat Aug 16, 2008 7:59 pm Post subject: |
|
|
ok first the site would need to be added as a trusted domain to avoid prompts
then yes it would all be silent
wheat i do is we have a use wscript within the html to write a download.ahk file and then execute a shell run with the wscript. i will have to modify ours to avoid giving anything proprietary away but this itself most vb scripters should be able to figure out on there own. the download.ahk file just executes a series of urldownloadtofile calls to download any ahk files from the server you can execute those files the same method as executing the download.ahk. this requires ahk to be installed on the client of course. Now if an exe is required there would be a prompt involved to download the download.exe but not when executing them. that method would not require ahk to be installed of course.
early monday morning ill post an example very simplified if you want. we do this in a corp environment and it works fairly well _________________ Read this
Com
Automate IE7 with Tabs |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 676
|
Posted: Mon Aug 18, 2008 6:30 am Post subject: |
|
|
| Code: | <script language='vbscript'>
Set oShell = CreateObject( "WScript.Shell" )
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("c:\path\file.ahk", 8, True)
objFile.WriteLine("urldownloadtofile,http:\\somedomain\file.ahk")
objFile.Close
oShell.Run "c:\path\file.ahk", 6, True
</script> | should be fairly self exclamitory I can only hope this will be put to honest intentions _________________ Read this
Com
Automate IE7 with Tabs |
|
| Back to top |
|
 |
rani
Joined: 18 Mar 2008 Posts: 57
|
Posted: Mon Aug 18, 2008 9:18 am Post subject: |
|
|
Hi tank ,
it looks simple,
I'll try it on mys site
can I use it with Javascript script eithe ?
or just with VB script ? |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|