COMate - control COM objects via automation - OBSOLETE!

Developed or developing a new product in PureBasic? Tell the world about it.
User avatar
Kiffi
Addict
Addict
Posts: 1484
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Post by Kiffi »

@SFSxOI: try to insert a COMate_GetLastErrorDescription() after the invoke statement.

Code: Select all

  [...]
  WshShell\Invoke("Run 'netsh int tcp set global ecncapability=enabled'")
  Debug COMate_GetLastErrorDescription()
  [...]
does it returns an 'OK' or an 'Error'?

Greetings ... Kiffi
Hygge
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

Yep, your right srod, was just gonna post back with the same thing, works perfectly now

Code: Select all

Define WshShell.COMateObject 

WshShell = COMate_CreateObject("WScript.Shell") 

If WshShell 
  
  WshShell\Invoke("Run('netsh int tcp set Global ecncapability=enabled')")
  
  WshShell\Release() 
  
Else 
  
  Debug "!WshShell" 
  
EndIf

Thanks srod and Kiffi :)

Now i can start converting all of my old .vbs scripts for netsh :)
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Yes COMate's command parser requires the brackets after the method name. I could easily alter this if required?
I may look like a mule, but I'm not a complete ass.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

Its no big deal srod, I just got to remember to put the brackets :) but thanks for the offer.

I think that even though i have problems remembering the brackets, the thing i have problems with the most are the escape codes in relation to strings, I seem to always forget the ' or something and spend much time before I realize how dumb i was to overlook something like that. :)

Heres some script conversions for Netsh in Vista and Server 2008 that are used to tune the TCP stack in each. Changes take effect immediately and no reboot needed.

Code: Select all

XIncludeFile "COMate.pbi"
XIncludeFile "VariantHelper_Include.pb"


; NETSH scripts for Windows Vista and Server 2008
; Changes take effect immediately - no reboot needed
; PureBasic 4.30 and COMate by srod
; By SFSxOI - December 2008


; ECN Capability - Ecn_EnableDisable(ecn_enbdis.s)
; where - ecn_enbdis.s is one of the following
; enable : some routers have issues with this enabled, not suggested and need to test first
; disable : this is the default state and recommended setting
; default : restores the system default

Procedure Ecn_EnableDisable(ecn_enbdis.s)
Define WshShell.COMateObject 

WshShell = COMate_CreateObject("WScript.Shell") 

If WshShell 
  
  If ecn_enbdis = "enable"
  WshShell\Invoke("Run('netsh int tcp set Global ecncapability=enable')")
  EndIf
  
  If ecn_enbdis = "disable"
  WshShell\Invoke("Run('netsh int tcp set Global ecncapability=disable')")
  EndIf
  
  If ecn_enbdis = "default"
  WshShell\Invoke("Run('netsh int tcp set Global ecncapability=default')")
  EndIf
  
  WshShell\Release() 
  
EndIf

EndProcedure


; TCP Auto-Tuning - TCP_Auto_Tune(auto_tune.s)
; where - auto_tune.s is one of the following
;normal : Default value, allows the receive window To grow To accommodate most conditions
;highlyrestricted : allows the receive window To grow beyond default value very conservatively
;restricted : somewhat restricted growth of the tcp receive window beyond its Default value
;disabled : uses a fixed value For the tcp receive window. Limits it To 64KB (limited at 65535).
;experimental : allows the receive window to grow to accommodate extreme scenarios
;NOTE: experimental setting not recommended, it can degrade performance in common scenarios, only intended For research purposes. It enables RWIN values of over 16 MB
; If you experience problems with your NAT router or SPI firewall, try the "restricted", "highlyrestricted", or even "disabled" state.
; recomended normal unless you are having problems


Procedure TCP_Auto_Tune(auto_tune.s) 
Define WshShell.COMateObject 

WshShell = COMate_CreateObject("WScript.Shell") 

If WshShell

  If auto_tune = "normal" 
  WshShell\Invoke("Run('netsh int tcp set global autotuninglevel=normal')")
  EndIf
  
  If auto_tune = "highlyrestricted"
  WshShell\Invoke("Run('netsh int tcp set global autotuninglevel=highlyrestricted')")
  EndIf
  
  If auto_tune = "restricted"
  WshShell\Invoke("Run('netsh int tcp set global autotuninglevel=restricted')")
  EndIf
  
  If auto_tune = "disabled"
  WshShell\Invoke("Run('netsh int tcp set global autotuninglevel=disabled')")
  EndIf
  
  If auto_tune = "experimental"
  WshShell\Invoke("Run('netsh int tcp set global autotuninglevel=experimental')")
  EndIf
  
  WshShell\Release() 
  
EndIf

EndProcedure


; Compound TCP - Con_TCP(level_ctcp.s)
; where - level_ctcp.s is one of the following
; ctcp : recommended setting (default for Server 2008)
; none : no congestion control at all (default for Windows Vista)
; Default : restores the system default
; Recommended setting: ctcp
; It is better To use this newer generation CTCP congestion control algorithm For most broadband connections,
; NOTE: By default Vista has CTCP turned off (none), and Server 2008 has CTCP turned on (ctcp).
; NOTE : Turning this option on can significantly increase throughput (not bandwidth).

Procedure Con_TCP(level_ctcp.s) 
Define WshShell.COMateObject 

WshShell = COMate_CreateObject("WScript.Shell") 

If WshShell 
  
  If level_ctcp = "ctcp"
  WshShell\Invoke("Run('netsh int tcp set Global congestionprovider=ctcp')")
  EndIf
  
  If level_ctcp = "none"
  WshShell\Invoke("Run('netsh int tcp set Global congestionprovider=none')")
  EndIf
  
  If level_ctcp = "default"
  WshShell\Invoke("Run('netsh int tcp set Global congestionprovider=default')")
  EndIf
  
  WshShell\Release() 
  
EndIf

EndProcedure


; RSS - Receive-side Scaling - Rss_Scale(scale_rss.s)
; where - scale_rss.s is one of the following
; enabled : Default - enables receive side scaling
; disabled : disables receive side scaling
; default : returns to system default
; Recommended: enabled (If you have 2 Or more processor cores And a NIC that can handle RSS)

Procedure Rss_Scale(scale_rss.s) 
Define WshShell.COMateObject 

WshShell = COMate_CreateObject("WScript.Shell") 

If WshShell 
  
  If scale_rss = "enabled"
  WshShell\Invoke("Run('netsh int tcp set global rss=enabled')")
  EndIf
  
  If scale_rss = "disabled"
  WshShell\Invoke("Run('netsh int tcp set global rss=disabled')")
  EndIf
  
  If scale_rss = "default"
  WshShell\Invoke("Run('netsh int tcp set global rss=default')")
  EndIf
  
  WshShell\Release() 
  
EndIf

EndProcedure


; TCP Chimney Offload - TCP_Chimney_Offload(tcp_offload.s)
; where - tcp_offload.s is one of the following
; enabled : enables TCP Chimney Offload (Default)
; disabled : disables TCP Chimney Offload
; default : returns to default system default
; Recommended: enabled

Procedure TCP_Chimney_Offload(tcp_offload.s) 
Define WshShell.COMateObject 

WshShell = COMate_CreateObject("WScript.Shell")

If WshShell 
  
  If tcp_offload = "enabled"
  WshShell\Invoke("Run('netsh int tcp set global chimney=enabled')")
  EndIf
  
  If tcp_offload = "disabled"
  WshShell\Invoke("Run('netsh int tcp set global chimney=disabled')")
  EndIf
  
  If tcp_offload = "default"
  WshShell\Invoke("Run('netsh int tcp set global chimney=default')")
  EndIf
  
  WshShell\Release() 
  
EndIf

EndProcedure

; Time Stamp 1323 - TimeStamp_1323(time_stamp.s)
; where - time_stamp.s is one of the following
; enabled : Time Stamp 1323 enabled (recommended for most)
; disabled : Time Stamp 1323 disabled (default)

Procedure TimeStamp_1323(time_stamp.s) 
Define WshShell.COMateObject 

WshShell = COMate_CreateObject("WScript.Shell")

If WshShell 
  
  If time_stamp = "enabled"
  WshShell\Invoke("Run('netsh int tcp set global timestamps=enabled')")
  EndIf
  
  If time_stamp = "disabled"
  WshShell\Invoke("Run('netsh int tcp set global timestamps=disabled')")
  EndIf
    
  WshShell\Release() 
  
EndIf

EndProcedure

SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

how do you get a dotted IP address into a command when the dotted IP address can't be a string?

Like this:

Code: Select all

netsh interface ip set address "Local Area Connection" static 192.168.0.10 255.255.255.0 192.168.0.1 1
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Why not a string? Looking at the help for netsh; it certainly seems to require a string.
I may look like a mule, but I'm not a complete ass.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

Thats what I thought at first also, that it was a string in COMate. But if you use the netsh in an admin command prompt you specifically designate strings with the netsh command with the quote marks " ", and the only part that is specifically designated a string in the command is the "Local Area Connection" part. In the command prompt the IP addreses aren't strings.

I tried using them as strings in the COMate command, and although it ran without error it didn't do what it was supposed to do.

Maybe i'm doing it wrong or something with COMate...back to the drawing board I guess.

The help says this:

Code: Select all

Usage: set address [name=]<string>
             [[source=]dhcp|static]
             [[address=]<IPv4 address>[/<integer>] [[mask=]<IPv4 mask>]
             [[gateway=]<IPv4 address>|none [gwmetric=]<integer>]
             [[type=]unicast|anycast]
             [[subinterface=]<string>]
             [[store=]active|persistent]
where only the name (connection name) is a string, and the addresses are integers. So if it expects an integer for the IP addresses how do you get the integer into the COMate command line? AS type-modifier of some sort? AS INTEGER (if there is one) ?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Well if you wish to pass an integer variable just use Str() etc. There is no need to use " as integer" although you can do if you wish.

E.g. (passing an integer variable as a BOOLEAN) :

Code: Select all

regExObject\SetProperty("IgnoreCase = " + Str(bIgnoreCase) + " AS BOOLEAN")
I may look like a mule, but I'm not a complete ass.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

doesn't matter what i do, its not working. Oh well.....I know its sending the command to netsh, its just not doing what its supposed to as as if it were typed directly into the command prompt.

Anyway, heres the lasted thing i've tried, and i've tried all sorts of variations and mixes, etc...and i'm back to trying to do it with strings again. Am I using the escape sequences correctly ?

Code: Select all

Procedure Stac_IP(connection_name.s, desired_IP.s, sub_net_mask.s, gw_router.s) 
Define WshShell.COMateObject

WshShell = COMate_CreateObject("WScript.Shell")

If WshShell 
  
  WshShell\Invoke("Run('netsh interface ip set address $0027" + connection_name + "$0027 static $0027" + desired_IP + "$0027 $0027" + sub_net_mask + "$0027 $0027" + gw_router + "$0027')")
  
  WshShell\Release() 
  
EndIf

EndProcedure
and i'm also trying it the older way which still works instead of the abbreviated version by using this line:

Code: Select all

WshShell\Invoke("Run('netsh interface ip set address name= $0027" + connection_name + "$0027 source= $0027" + static_change$ + "$0027 addr= $0027" + desired_IP + "$0027 mask= $0027" + sub_net_mask + "$0027 gateway= $0027" + gw_router + "$0027')")
KIKI
Enthusiast
Enthusiast
Posts: 145
Joined: Thu Dec 28, 2006 11:49 am
Location: FRANCE

Post by KIKI »

I have the folowing error message return by comate
Unknown error. (Code : Hex FFFFFFFF80020003). Please report this error code to the author at 'enquiries@nxsoftware.com'
Here is the context

Code: Select all

RegisterActiveX(GetCurrentDirectory()+"AutoItX3.dll") 
automation = COMate_CreateObject("AutoItX3.Control")

anf this is these intstruction wich cause a crash 

Automation\SetPropertyRef("ControlSetText('Importation complète...','Regarder &dans','Edit1',"+"'" +strChemin +"')")
  
Description of ControlSetText 
ControlSetText "title", "text", "controlID", "new text"

Parameters

title The title of the window to access. 
text The text of the window to access. 
controlID The control to interact with. See Controls. 
new text The new text to be set into the control. 
Return Value

Success: Returns 1. 
Failure: Returns 0 if window/control is not found.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

That is a 'Member not found' error. Try using Invoke instead of SetPropertyRef and also double check the classname of the control; is it really "Edit1" ? You can also try setting the first two parameters to null strings etc.
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Bug fix - 29th Dec. 2008.

COMate version 1.1.9.

First, only the version of COMate for PB 4.3 has had this bug fix. COMate for PB 4.2 remains at version 1.1.7

A quite major shortcoming on COMate's part meant that it would effectively ignore some ActiveX control's events (e.g. ShockwaveFlash). I blame this on a severe lack of documentation on MS's part! :wink:

This has been fixed.

See the nxSoftware site for the download.
I may look like a mule, but I'm not a complete ass.
KIKI
Enthusiast
Enthusiast
Posts: 145
Joined: Thu Dec 28, 2006 11:49 am
Location: FRANCE

Post by KIKI »

Hi srod,
Hapy new year.
Here is my problem from my program HTML mailer (CDO and comate programm) see my post.
Someone wonder me how to see if the mail was send correctly.
But the send function doesn(t retrun anaything except thazn in visual basic error vraibla have a code returning error.
How can i do to intercept that's message to see if yhe mail was send correctly ? Have you an idea.
Thanks in advance
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Hi,

happy new year to you KIKI.

Unfortunately I know very very little about CDO, so am unable to shed any light on this I'm afraid.
I may look like a mule, but I'm not a complete ass.
X
Enthusiast
Enthusiast
Posts: 311
Joined: Tue Apr 04, 2006 6:27 am

Post by X »

srod wrote: Right, I'm off to study 'Event sinks' now... Let's hope I have more luck than I generally do with kitchen sinks! :wink:
Hello! Just checking back in to see if this has come around yet :) VBScripts allows scripts to call application functions directly, and the other way around (allow applications to call script functions directly), and yet, allows events to bubble up from events.

I was wondering how this project was coming along.
Post Reply