Ajuda com objeto WScript.Shell

Projeto [x]Harbour - Compilador de código aberto compatível com o Clipper.

Moderador: Moderadores

Avatar do usuário
asimoes
Colaborador
Colaborador
Mensagens: 4919
Registrado em: 26 Abr 2007 16:48
Localização: RIO DE JANEIRO-RJ

Ajuda com objeto WScript.Shell

Mensagem por asimoes »

Pessoal,

Preciso de uma ajuda com WScript.Shell no método run

Acontece o seguinte:

A variavel cComando tem o seguinte valor:

D:\Harbour\h-Servidor LETO - HWGUI\FORK\letodbdaemon.exe stop

O erro ocorre por causa dos espaços nas pastas

Tem alguma dica para contornar o erro?

oShell:Run(cComando, nStyle, lEspera)
Anexos
Erro no método run
Erro no método run
Screen Shot 11-16-15 at 10.09 AM.PNG (6.99 KiB) Exibido 459 vezes
►Harbour 3.x | Minigui xx-x | HwGui◄
Pense nas possibilidades abstraia as dificuldades.
Não corrigir nossas falhas é o mesmo que cometer novos erros.
A imaginação é mais importante que o conhecimento. (Albert Einstein)
Avatar do usuário
asimoes
Colaborador
Colaborador
Mensagens: 4919
Registrado em: 26 Abr 2007 16:48
Localização: RIO DE JANEIRO-RJ

Ajuda com objeto WScript.Shell

Mensagem por asimoes »

Prezados,

Resolvi o problema

cExeLeto:=hb_DirBase()+"letodbdaemon.exe"

Para diretórios com espaços a variável deve estar entre '"' (aspas simples+aspas duplas+aspas simples) o parâmetro "stop" não.

A chamada é assim Execute( cExeLeto, " stop" )

A função Execute ficou assim:

Código: Selecionar todos

STATIC FUNCTION Execute( cArq, cParam1, lEspera )
Local oShell, lOk:=.T., nStyle, oErro, cComando

   hb_Default(@cArq,"")
   hb_Default(@cParam1,"")
   hb_Default(@lEspera,.F.)
   
  
   If Empty(cArq)
      hwg_MsgStop("O Arquivo deve ser informado","ERRO")
      Return .F.
   End
   
   Try
      oShell:=win_OleCreateObject( "WScript.Shell" )
   Catch
      Try
         oShell:=win_OleCreateObject( "WScript.Shell" )
      Catch
         lOk:=.F.
      End
   End
   If lOk
      Try
         /*
         intWindowStyle
         Description
         0  Hides the window and activates another window.
         1  Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when displaying the window for the first time.
         2  Activates the window and displays it as a minimized window.
         3  Activates the window and displays it as a maximized window.
         4  Displays a window in its most recent size and position. The active window remains active.
         5  Activates the window and displays it in its current size and position.
         6  Minimizes the specified window and activates the next top-level window in the Z order.
         7  Displays the window as a minimized window. The active window remains active.
         8  Displays the window in its current state. The active window remains active.
         9  Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window.
         10 Sets the show-state based on the state of the program that started the application. 
         */
         nStyle:=0
         cComando:='"'+cArq+'"'+cParam1
         oShell:Run(cComando, nStyle, lEspera)
      Catch oErro
         cErro:="Erro na execução"+hb_Eol()+cComando+hb_eol()
         IF !oErro = Nil
            cErro+=LTrim( Str( oErro:subCode ) )+" "+oErro:Description+" "
            DO CASE
            CASE ! Empty( oErro:filename )
               cErro+= ": " + oErro:filename
            CASE ! Empty( oErro:operation )
               cErro+= ": " + oErro:operation
            ENDCASE
            IF ! Empty( oErro:osCode )
               cDOSError := "(DOS Error " + LTrim( Str( oErro:osCode ) ) + ")"
            ENDIF
            IF ! Empty( oErro:osCode )
               cErro += " " + cDOSError
            ENDIF
         ENDIF
         hwg_MsgStop(cErro, "ERRO")
         lOk:=.F.
      End
      oShell:=Nil
   End
Return lOk
►Harbour 3.x | Minigui xx-x | HwGui◄
Pense nas possibilidades abstraia as dificuldades.
Não corrigir nossas falhas é o mesmo que cometer novos erros.
A imaginação é mais importante que o conhecimento. (Albert Einstein)
Responder