Sign in to follow this  
Followers 0
coucou

Advice for 2 functions

18 posts in this topic

#1 ·  Posted (edited)

Hi

I try to write a silent Activation of Diskeeper and I encountered some unusual (for me) functions to

1) Macro Reference

This works

Run('C:\WINDOWS\system32\mmc.exe "C:\Program Files\Diskeeper Corporation\Diskeeper\Diskeeper.msc"')

This NOT

$Launch = @SystemDir & "\system32\mmc.exe"
$Prog = @ProgramFilesDir  & "\Diskeeper Corporation\Diskeeper\Diskeeper.msc"
Run('$Launch "$Prog"')
I've tested many combinations and got AutoIt error messgaes "MMC can not open the file $Prog" or "Unable to executr the external program"

2) deleted

I'll appreciate any help

Regards

coucou

Edited by coucou

Share this post


Link to post
Share on other sites



$Launch = @SystemDir & "\system32\mmc.exe"
$Prog = @ProgramFilesDir  & "\Diskeeper Corporation\Diskeeper\Diskeeper.msc"
Run('"' & $Launch & '" "' & $Prog & '"')


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

$Launch = @SystemDir & "\system32\mmc.exe"
$Prog = @ProgramFilesDir  & "\Diskeeper Corporation\Diskeeper\Diskeeper.msc"
Run('"' & $Launch & '" "' & $Prog & '"')
TNX SmOke_N for yr help.

Sorry to _inform you that it doesn't works. muttley

Still I get "Unable to execute the external program" (see here bellow attached image)

BTW, is there any "Macro Reference" documentation? couldn't find it.

Regards

coucou

post-5679-1215181103_thumb.jpg

Edited by coucou

Share this post


Link to post
Share on other sites

TNX SmOke_N for yr help.

Sorry to _inform you that it doesn't works. muttley

Still I get "Unable to execute the external program" (see here bellow attached image)

BTW, is there any "Macro Reference" documentation? couldn't find it.

Regards

coucou

post-5679-1215181103_thumb.jpg

Try to run the msc through the ShellExecute() function.

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

TNX SmOke_N for yr help.

Sorry to _inform you that it doesn't works. muttley

Still I get "Unable to execute the external program" (see here bellow attached image)

BTW, is there any "Macro Reference" documentation? couldn't find it.

Regards

coucou

post-5679-1215181103_thumb.jpg

Maybe

$Launch = @SystemDir & "\system32\mmc.exe"

should be

$Launch = @SystemDir & "\mmc.exe"

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Nice catch martin. That's exactly what the problem is.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

BTW, is there any "Macro Reference" documentation? couldn't find it.

Regards

coucou

Macros

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Maybe

$Launch = @SystemDir & "\system32\mmc.exe"

should be

$Launch = @SystemDir & "\mmc.exe"
eek, I never even looked at the paths muttley

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

TNX guys, but nothing move forward.

$Launch = @SystemDir & "\mmc.exe"
this what i tested first. It gave exactly the same message error as
$Launch = @SystemDir & "\system32\mmc.exe"

Regarding "Macro Reference" documentation, I knew this, it's only a list and description of. What i'm looking for is how to use and examples as well as Function Reference.

Regards

coucou

Share this post


Link to post
Share on other sites

TNX guys, but nothing move forward.

$Launch = @SystemDir & "\mmc.exe"
this what i tested first. It gave exactly the same message error as
$Launch = @SystemDir & "\system32\mmc.exe"

Regarding "Macro Reference" documentation, I knew this, it's only a list and description of. What i'm looking for is how to use and examples as well as Function Reference.

Regards

coucou

The error you showed in post 3 doesn't correspond to having set $Launch = @SystemDir & \mmc.exe so perhaps you could post the code you are using and having problems with.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Using the example in post #1 this should work.

$Launch = @SystemDir & "\mmc.exe "
$Prog = FileGetShortName(@ProgramFilesDir  & "\Diskeeper Corporation\Diskeeper\Diskeeper.msc")
RunWait($Launch & $Prog)

But the better solution is simply

$Prog = @ProgramFilesDir  & "\Diskeeper Corporation\Diskeeper\Diskeeper.msc"
ShellExecuteWait($Prog)

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Many TNX GEOSoft, tested both command working muttley

BTW, I'm looking for a second help on "Control Start/Stop Services". By using the [search] on this forum, I saw you had contributed quite lot for "services"

May you be kind to help on THIS

Regards

coucou

Share this post


Link to post
Share on other sites

Many TNX GEOSoft, tested both command working muttley

BTW, I'm looking for a second help on "Control Start/Stop Services". By using the [search] on this forum, I saw you had contributed quite lot for "services"

May you be kind to help on THIS

Regards

coucou

Did you download and look at the UDF? It has _Service_Stop(), _Service_Start() and _Service_GetState(). It does require that WMI be enabled on the system.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Sorry to bothering you again GEOSoft

Yes I did.

Here the part i'm concerned.

;===============================================================================
;
; Description:    Starts a service
; Syntax:          _StartService($sServiceName)
; Parameter(s):  $sServiceName - Name of service to start
; Requirement(s):   None
; Return Value(s):  On Success - Sets   @error = 0
;                  On Failure - Sets:
;                             @error = 1056: Already running
;                             @error = 1060: Service does not exist
; Author(s):        SumTingWong
; Documented by:    noone
;
;===============================================================================
Func _StartService($sServiceName)
  Local $arRet
  Local $hSC
  Local $hService
  Local $lError = -1

  $arRet = DllCall("advapi32.dll", "long", "OpenSCManager", _
                   "str", "", _
                   "str", "ServicesActive", _
                   "long", $SC_MANAGER_CONNECT)
  If $arRet[0] = 0 Then
     $arRet = DllCall("kernel32.dll", "long", "GetLastError")
     $lError = $arRet[0]
  Else
     $hSC = $arRet[0]
     $arRet = DllCall("advapi32.dll", "long", "OpenService", _
                      "long", $hSC, _
                      "str", $sServiceName, _
                      "long", $SERVICE_START)
     If $arRet[0] = 0 Then
        $arRet = DllCall("kernel32.dll", "long", "GetLastError")
        $lError = $arRet[0]
     Else
        $hService = $arRet[0]
        $arRet = DllCall("advapi32.dll", "int", "StartService", _
                         "long", $hService, _
                         "long", 0, _
                         "str", "")
        If $arRet[0] = 0 Then
           $arRet = DllCall("kernel32.dll", "long", "GetLastError")
           $lError = $arRet[0]
        EndIf
        DllCall("advapi32.dll", "int", "CloseServiceHandle", "long", $hService)     
     EndIf
     DllCall("advapi32.dll", "int", "CloseServiceHandle", "long", $hSC)
  EndIf
  If $lError <> -1 Then SetError($lError)
EndFunc


;===============================================================================
;
; Description:    Stops a service
; Syntax:          _StopService($sServiceName)
; Parameter(s):  $sServiceName - Name of service to stop
; Requirement(s):   None
; Return Value(s):  On Success - Sets:  
;                             @error = 0
;                  On Failure - Sets:
;                             @error = 1062: Already stopped
;                             @error = 1060: Service does not exist
; Author(s):        SumTingWong
; Documented by:    noone
;
;===============================================================================
Func _StopService($sServiceName)
  Local $arRet
  Local $hSC
  Local $hService
  Local $lError = -1

  $arRet = DllCall("advapi32.dll", "long", "OpenSCManager", _
                   "str", "", _
                   "str", "ServicesActive", _
                   "long", $SC_MANAGER_CONNECT)
  If $arRet[0] = 0 Then
     $arRet = DllCall("kernel32.dll", "long", "GetLastError")
     $lError = $arRet[0]
  Else
     $hSC = $arRet[0]
     $arRet = DllCall("advapi32.dll", "long", "OpenService", _
                      "long", $hSC, _
                      "str", $sServiceName, _
                      "long", $SERVICE_STOP)
     If $arRet[0] = 0 Then
       $arRet = DllCall("kernel32.dll", "long", "GetLastError")
       $lError = $arRet[0]
     Else
        $hService = $arRet[0]
        $arRet = DllCall("advapi32.dll", "int", "ControlService", _
                         "long", $hService, _
                         "long", $SERVICE_CONTROL_STOP, _
                         "str", "")
        If $arRet[0] = 0 Then
           $arRet = DllCall("kernel32.dll", "long", "GetLastError")
           $lError = $arRet[0]
        EndIf
        DllCall("advapi32.dll", "int", "CloseServiceHandle", "long", $hService)     
     EndIf
     DllCall("advapi32.dll", "int", "CloseServiceHandle", "long", $hSC)
  EndIf
  If $lError <> -1 Then SetError($lError)
EndFunc

;===============================================================================
but it looks to complicate (for me) to insert it in my here bellow small script.

;Stop Diskeeper Service  
RunWait("net stop Diskeeper", "C:\windows\system32")

;Here to insert the service control
;If Diskeeper (it's the name of the service) is stop Then
;Copy Diskeeper FR Language
   $Lang = RegRead("HKEY_CURRENT_USER\Control Panel\International", "sLanguage")
     If $Lang = "FRA" Then
        RunWait("DK781_FR.exe")
     EndIf
;EndIf

;Start Diskeeper Service  
RunWait("net start Diskeeper", "C:\windows\system32")
;Here to insert the service control
;If Diskeeper is start Then
    Exit
;EndIf

Regards

coucou

Edited by coucou

Share this post


Link to post
Share on other sites

That's not from myUDF so good luck with that.

Mine is here

http://dundats.mvps.org/AutoIt/udf_code.aspx?udf=services

There is a download button at the bottom of the page.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

As far i understood, I have to play with

;===============================================================================
; Name:   _Service_Start()
; Description:   Start a Windows Service
; Syntax:   _Service_Start($sServiceName[, $Computer])
; Parameter(s):   $sServiceName - The name of the service to start
;                $Computer - The network name of the computer (optional).
;                            The local computer is default
; Requirement(s):   WMI capable operating system and administrator rights on the computer
; Return Value(s):   Success - Starts the service
;                   Failure Sets @Error = -1 if service not found or service is already running
; Author(s):        George (GEOSoft) Gedye
; Modification(s):   Added  "where name like" to the query string to prevent an array loop in AutoIt
;                   
; Note(s):   
; Example(s):   
;===============================================================================

Func _Service_Start($sServiceName, $Computer = "localhost")
  _sServErrorHandlerRegister()
  Local $Service = ObjGet("winmgmts:\\" & $Computer & "\root\cimv2")
  Local $sQuery = "Select * from Win32_Service Where State = 'Stopped' And " & _
      "name like '"& $sServiceName & "'"
  Local $sItems = $Service.ExecQuery($sQuery)
  _sServErrorHandlerDeRegister()
  For $objService in $sItems
    $objService.StartService($objService.Name)
    Return
  Next
  Return SetError(-1)
EndFunc  ;<==> _Service_Start()

and

;===============================================================================
; Name:   _Service_Stop()
; Description:   Stop a Windows Service
; Syntax:   _Service_Stop($sServiceName[, $Computer])
; Parameter(s):   $sServiceName - The name of the service to stop
;                $Computer - The network name of the computer (optional).
;                            The local computer is default
; Requirement(s):   WMI capable operating system and administrator rights on the computer
; Return Value(s):   Success - Stops the service
;                   Failure Sets @Error = -1 if service not found or service state is already stopped
;                           Sets @Error = -2 if service can not be stopped
; Author(s)   George (GEOSoft) Gedye
; Modification(s):   Added  "where name like" to the query string to prevent an array loop in AutoIt
;                   engine - added ProcessWaitClose.
;                            
; Note(s):   I recommend that you call _Service_StopOK() prior to using this function
; Example(s):   
;===============================================================================

Func _Service_Stop($sServiceName, $Computer = "localhost")
  Local $sQuery = "Select * from Win32_Service Where State = 'Running' And " & _
      "name like '"& $sServiceName &"'"
  _sServErrorHandlerRegister()
  Local $Service = ObjGet("winmgmts:\\" & $Computer & "\root\cimv2")
  Local $sItems = $Service.ExecQuery($sQuery)
  _sServErrorHandlerDeRegister()
  For $objService In $sItems
    If Not $objService.AcceptStop Then Return SetError(-2)
    $objService.StopService($objService.Name)
    ProcessWaitClose($objService.ProcessID)
    Return
  Next
  Return SetError(-1)
EndFunc ;<==> _Service_Stop()

1) Do i have to define $sServiceName as $sDiskeeper?

2) As i'm not using a server nor network, do i forget about $Computer.

3) Is there anything else to check before i run my here above script?

Regards

coucou

Share this post


Link to post
Share on other sites

As far i understood, I have to play with

;===============================================================================
; Name:   _Service_Start()
; Description:   Start a Windows Service
; Syntax:   _Service_Start($sServiceName[, $Computer])
; Parameter(s):   $sServiceName - The name of the service to start
;                $Computer - The network name of the computer (optional).
;                            The local computer is default
; Requirement(s):   WMI capable operating system and administrator rights on the computer
; Return Value(s):   Success - Starts the service
;                   Failure Sets @Error = -1 if service not found or service is already running
; Author(s):        George (GEOSoft) Gedye
; Modification(s):   Added  "where name like" to the query string to prevent an array loop in AutoIt
;                   
; Note(s):   
; Example(s):   
;===============================================================================

Func _Service_Start($sServiceName, $Computer = "localhost")
  _sServErrorHandlerRegister()
  Local $Service = ObjGet("winmgmts:\\" & $Computer & "\root\cimv2")
  Local $sQuery = "Select * from Win32_Service Where State = 'Stopped' And " & _
      "name like '"& $sServiceName & "'"
  Local $sItems = $Service.ExecQuery($sQuery)
  _sServErrorHandlerDeRegister()
  For $objService in $sItems
    $objService.StartService($objService.Name)
    Return
  Next
  Return SetError(-1)
EndFunc ;<==> _Service_Start()

and

;===============================================================================
; Name:   _Service_Stop()
; Description:   Stop a Windows Service
; Syntax:   _Service_Stop($sServiceName[, $Computer])
; Parameter(s):   $sServiceName - The name of the service to stop
;                $Computer - The network name of the computer (optional).
;                            The local computer is default
; Requirement(s):   WMI capable operating system and administrator rights on the computer
; Return Value(s):   Success - Stops the service
;                   Failure Sets @Error = -1 if service not found or service state is already stopped
;                           Sets @Error = -2 if service can not be stopped
; Author(s)   George (GEOSoft) Gedye
; Modification(s):   Added  "where name like" to the query string to prevent an array loop in AutoIt
;                   engine - added ProcessWaitClose.
;                            
; Note(s):   I recommend that you call _Service_StopOK() prior to using this function
; Example(s):   
;===============================================================================

Func _Service_Stop($sServiceName, $Computer = "localhost")
  Local $sQuery = "Select * from Win32_Service Where State = 'Running' And " & _
      "name like '"& $sServiceName &"'"
  _sServErrorHandlerRegister()
  Local $Service = ObjGet("winmgmts:\\" & $Computer & "\root\cimv2")
  Local $sItems = $Service.ExecQuery($sQuery)
  _sServErrorHandlerDeRegister()
  For $objService In $sItems
    If Not $objService.AcceptStop Then Return SetError(-2)
    $objService.StopService($objService.Name)
    ProcessWaitClose($objService.ProcessID)
    Return
  Next
  Return SetError(-1)
EndFunc;<==> _Service_Stop()

1) Do i have to define $sServiceName as $sDiskeeper?

2) As i'm not using a server nor network, do i forget about $Computer.

3) Is there anything else to check before i run my here above script?

Regards

coucou

1 - If the service name is actually the same as $sDiskeeper then yes.

2 - forget it. It will use the default.

3 - while you are testing you may want to get the return values from some of the other functions. Just to make sure for instance that you have the correct service name.

Easiest way is to place the UDF in your AutoIt3\Include folder then #include<services.au3> until everything is working. Separate the functions you need later.

Tip. Check for dependents of your service. If another service depends on $sDiskeeper then you may also have to close that one first. You can just call the other functions on a temporary basis until everything is working and then remove the calls to the un-needed functions.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

1 - If the service name is actually the same as $sDiskeeper then yes.

2 - forget it. It will use the default.

3 - while you are testing you may want to get the return values from some of the other functions. Just to make sure for instance that you have the correct service name.

Easiest way is to place the UDF in your AutoIt3\Include folder then #include<services.au3> until everything is working. Separate the functions you need later.

Tip. Check for dependents of your service. If another service depends on $sDiskeeper then you may also have to close that one first. You can just call the other functions on a temporary basis until everything is working and then remove the calls to the un-needed functions.

1 - YES

2 - OK

3 - How to get the return values

place the UDF AutoIt3\Include folder <--- Do you mean yr services.au3 file ?

#include<services.au3> <--- Do i have to add this command in yr script

Check for dependents of your service <--- There is NO dependence

TNX for any furthere suggestion, I'll test tomorrow and give you a feedback.

Regards

coucou

Edited by coucou

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0