Jump to content

Help with macros @ScriptDir


Recommended Posts

Hi everyone.I need did my script is portable.I use @ScriptDir and  trying use one command  Example: RunWait(@ComSpec & '/ c copy /y ' & @ScriptDir & ' "\LOGUS\Logus.HMS.Desktop.lnk" "\\' & $rHostName & '\C$"') but it doesn't work for me.Please need for help.Thanks for your experience.Sorry for my English,I'm Russian...

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>
#include <String.au3>
#include <Crypt.au3>
#include <WinAPISysWin.au3>
#RequireAdmin
#NoTrayIcon

Opt("GUIOnEventMode", 1)

Global $Assets = @ScriptDir & "\Assets\"

Global $cUI_BK = 0x02101B
Global $cContent_BK = 0x091926
Global $cText = 0xDEDEDE
Global $cTextA = 0x56CBDD
Global $cCardBk = 0x0C1C29

Global $lastMenu = Default
Global $isOnTop = False
Global $ui_w = 800
Global $ui_h = 520
Global $topPanel_h = CalcPercent(12, $ui_h)
Global $bottomPanel_h = CalcPercent(8, $ui_h)
Global $bottomPanel_y = $ui_h - $bottomPanel_h
Global $leftPanel_w = CalcPercent(25, $ui_w)
Global $contentPanel_x = $leftPanel_w
Global $contentPanel_y = $topPanel_h
Global $contentPanel_w = $ui_w - $leftPanel_w
Global $contentPanel_h = $ui_h - ($topPanel_h + $bottomPanel_h)


Global $UI = GUICreate("Experience UI", $ui_w, $ui_h) ; $WS_POPUP, $WS_EX_CONTROLPARENT
WinSetTrans($UI, "", 0);
GUISetState(@SW_SHOW, $UI)
For $i = 0 To 243 Step 2
    WinSetTrans($UI, "", $i);Прозрачность 0-255

Next

GUISetOnEvent(-3, "Terminate", $UI)
GUISetBkColor($cUI_BK, $UI)

Global $topPanel = GUICtrlCreateLabel("", 0, 0, $ui_w, $topPanel_h) ; height = 12% from UI | (ps. $GUI_WS_EX_PARENTDRAG)
GUICtrlSetState($topPanel, 128) ; $GUI_DISABLE
GUICtrlSetBkColor($topPanel, $cUI_BK)

Global $bottomPanel = GUICtrlCreateLabel("", 0, $bottomPanel_y, $ui_w, $bottomPanel_h)
GUICtrlSetState($bottomPanel, 128) ; $GUI_DISABLE
GUICtrlSetBkColor($bottomPanel, $cUI_BK)

Global $leftPanel = GUICtrlCreateLabel("", 0, $topPanel_h, $leftPanel_w, $ui_h - ($topPanel_h + $bottomPanel_h))
GUICtrlSetState($leftPanel, 128) ; $GUI_DISABLE
GUICtrlSetBkColor($leftPanel, $cUI_BK)

Global $contentPanel = GUICtrlCreateLabel("", $contentPanel_x, $contentPanel_y, $contentPanel_w, $contentPanel_h)
GUICtrlSetState($contentPanel, 128) ; $GUI_DISABLE
GUICtrlSetBkColor($contentPanel, $cContent_BK)

$y = $bottomPanel_y + (($bottomPanel_h / 2) - (28 / 2))
GUICtrlCreateLabel("© 2020 by DiJo.", 10, $y, $leftPanel_w - 38, 28, 0x0200)
GUICtrlSetFont(-1, 8, Default, Default, "Segoe UI", 5) ; 5 = Clear Type
GUICtrlSetColor(-1, $cText)

Global $y = $topPanel_h
GUICtrlCreateLabel(" FNKC Pack", 52, $y, $leftPanel_w - 52, 32, 0x0200)
GUICtrlSetFont(-1, 12, 600, Default, "Segoe UI", 5) ; 5 = Clear Type
GUICtrlSetColor(-1, $cText)

$y += 50
Global $vDashboard = GUICtrlCreateLabel("Mode 1", 38, $y, $leftPanel_w - 38, 32, 0x0200)
GUICtrlSetOnEvent(-1, "DashboardEvent")
GUICtrlSetFont(-1, 11, 600, Default, "Segoe UI", 5) ; 5 = Clear Type
GUICtrlSetColor(-1, $cTextA)
GUICtrlSetCursor(-1, 0)
$lastMenu = $vDashboard
$y += 32
Global $vWallet = GUICtrlCreateLabel("Mode 2", 38, $y, $leftPanel_w - 38, 32, 0x0200)
GUICtrlSetOnEvent(-1, "WalletEvent")
GUICtrlSetFont(-1, 11, 600, Default, "Segoe UI", 5) ; 5 = Clear Type
GUICtrlSetColor(-1, $cText)
GUICtrlSetCursor(-1, 0)
$y += 32
Global $vMessages = GUICtrlCreateLabel("Mode 3", 38, $y, $leftPanel_w - 38, 32, 0x0200)
GUICtrlSetOnEvent(-1, "MessagesEvent")
GUICtrlSetFont(-1, 11, 600, Default, "Segoe UI", 5) ; 5 = Clear Type
GUICtrlSetColor(-1, $cText)
GUICtrlSetCursor(-1, 0)

$y = ($topPanel_h + 50)
Global $vIndicator = GUICtrlCreateLabel("", 0, $y, 4, 32)
GUICtrlSetBkColor(-1, $cTextA)

$x = $contentPanel_x + 10
$y = $contentPanel_y + 15
Global $iHostName = GUICtrlCreateInput("", $x + 200, $y + 10, 180, 21)
Global $Button1 = GUICtrlCreateButton("Ping", $x, $y + 80, 267, 43)
GUICtrlSetFont(-1, 8, 800, 0, "Tahoma") ;задаем стиль элементу выше
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x0E0C2E)
GUICtrlSetOnEvent(-1, "_Didshit1")
Global $Button2 = GUICtrlCreateButton("Logus", $x + 310, $y + 80, 267, 43)
GUICtrlSetFont(-1, 8, 800, 0, "Tahoma") ;задаем стиль элементу выше
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x0E0C2E)
GUICtrlSetOnEvent(-1, "_Didshit2")
Global $Button3 = GUICtrlCreateButton("Start", $x, $y + 140, 267, 43) ;создаем кнопку подключения
GUICtrlSetFont(-1, 8, 800, 0, "Tahoma") ;задаем стиль элементу выше
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x0E0C2E)

Global $Checkbox1 = GUICtrlCreateCheckbox("", $x + 273, $y + 95, 12, 12)
Global $Checkbox2 = GUICtrlCreateCheckbox("", $x + 293, $y + 95, 12, 12)

GUISetState() ; Show GUI
Global $rHostName
While True
    Sleep(10)
WEnd

Func DashboardEvent()
    If $lastMenu <> $vDashboard Then
        Local $CGP = ControlGetPos($UI, '', $vDashboard)
        GUICtrlSetPos($vIndicator, 0, $CGP[1])
        GUICtrlSetColor($vDashboard, $cTextA)
        GUICtrlSetColor($lastMenu, $cText)
        $lastMenu = $vDashboard
        GUICtrlSetState($Button1, $GUI_SHOW)
        GUICtrlSetState($Button2, $GUI_SHOW)
        GUICtrlSetState($Checkbox1, $GUI_SHOW)
        GUICtrlSetState($Checkbox2, $GUI_SHOW)
        ConsoleWrite(1)
    EndIf
EndFunc ;==>DashboardEvent

Func WalletEvent()
    If $lastMenu <> $vWallet Then
        Local $CGP = ControlGetPos($UI, '', $vWallet)
        GUICtrlSetPos($vIndicator, 0, $CGP[1])
        GUICtrlSetColor($vWallet, $cTextA)
        GUICtrlSetColor($lastMenu, $cText)
        $lastMenu = $vWallet
        GUICtrlSetState($Button1, $GUI_HIDE)
        GUICtrlSetState($Button2, $GUI_HIDE)
        GUICtrlSetState($Checkbox1, $GUI_HIDE)
        GUICtrlSetState($Checkbox2, $GUI_HIDE)
        ConsoleWrite(1)
    EndIf
EndFunc ;==>WalletEvent

Func MessagesEvent()
    If $lastMenu <> $vMessages Then
        Local $CGP = ControlGetPos($UI, '', $vMessages)
        GUICtrlSetPos($vIndicator, 0, $CGP[1])
        GUICtrlSetColor($vMessages, $cTextA)
        GUICtrlSetColor($lastMenu, $cText)
        $lastMenu = $vMessages
        GUICtrlSetState($Button1, $GUI_HIDE)
        GUICtrlSetState($Button2, $GUI_HIDE)
        GUICtrlSetState($Checkbox1, $GUI_HIDE)
        GUICtrlSetState($Checkbox2, $GUI_HIDE)
        ConsoleWrite(1)
    EndIf
EndFunc ;==>MessagesEvent

Func _Didshit1()
    $rHostName = GUICtrlRead($iHostName)
    Run(@ComSpec & ' /c C:\Windows\System32\Ping.exe ' & $rHostName & ' -t')
EndFunc ;==>_Didshit1

Func _Didshit2()
    $rHostName = GUICtrlRead($iHostName)
    RunWait(@ComSpec & ' /c PsPasswd \\' & $rHostName & ' Администратор Mik35')
    RunWait(@ComSpec & ' /c copy /y "C:\Progra~2\DiJo\LOGUS\Logus.bat" "\\' & $rHostName & '\C$"')
    RunWait(@ComSpec & ' /c copy /y "C:\Progra~2\DiJo\LOGUS\Logus.HMS.Desktop.lnk" "\\' & $rHostName & '\C$"')
    RunWait(@ComSpec & ' /c psexec \\' & $rHostName & ' -u Администратор -p Mik35 cmd.exe /c "C:\Logus.bat"')
EndFunc ;==>_Didshit2

Func Terminate()
    GUIDelete($UI)
    Exit
EndFunc ;==>Terminate

Func Minimize()
    GUISetState(@SW_MINIMIZE, $UI)
EndFunc ;==>Minimize

Func Topmost()
    If $isOnTop = False Then
        WinSetOnTop($UI, Default, 1)
        $isOnTop = True
    Else
        WinSetOnTop($UI, Default, 0)
        $isOnTop = False
    EndIf
EndFunc ;==>Topmost

Func CalcPercent($vPercent, $vInt) ; Calculate percent % :)
    Return $vPercent * $vInt / 100
EndFunc ;==>CalcPercent


 

Link to comment
Share on other sites

  • Replies 53
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

Hello :) 

;Replace
RunWait(@ComSpec & '/ c copy /y ' & @ScriptDir & ' "\LOGUS\Logus.HMS.Desktop.lnk" "\\' & $rHostName & '\C$"')
;" " less you got quotes, easier it will be. Leave only space for blank charactere as well, because they are important here.
;With :
RunWait(@ComSpec & ' /c copy /y '&@ScriptDir&'\Logus.HMS.Desktop.lnk \\'&$rHostName&'\C$')

Maybe ?

Add error checking as well. 

If @error Then MsgBox ( 64 , "ERROR" , "Error:"&@error @ CRLF & "Error Running the commmand Run Wait Line X")

The error return of non executed run at all is Not Zero.

You got a more friendly approach in the help file : 

; Run Notepad and wait for the Notepad process to close.
Local $iReturn = RunWait("notepad.exe")

; Display the return code of the Notepad process.
MsgBox($MB_SYSTEMMODAL, "", "The return code from Notepad was: " & $iReturn)

When you're saying it's not working. You mean nothing is executed at all ?

Or it's executed and the psexec is failing. 

 

Anyway

@ComSpec & '/ c copy /y ' & .... Cannot work.

You need an additional space. 

This is correct : (you can copy past above.)

@ComSpec & ' /c copy .....

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

You have both incorrect spacing and quotes, try debugging with something like:

Local $rHostName = "HostName"
Local $sCommand = 'Copy /y "' & @ScriptDir & '\LOGUS\Logus.HMS.Desktop.lnk" "\\' & $rHostName & '\C$"'

;~ Debug the command
RunWait(@ComSpec & ' /k Echo ' & $sCommand & '&&' & $sCommand & '&& Pause')

;~ Hidden Command
;~ RunWait(@ComSpec & ' /c ' & $sCommand, "", @SW_HIDE)

 

Link to comment
Share on other sites

ops miss nvm x)

 

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

  • Developers

Please done quote a whole post translated as that only makes it harder to follow the issue.

Have you corrected the spacing in the script statement as indicated?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

6 minutes ago, Jos said:

Пожалуйста, процитируйте весь переведенный пост, так как это только усложняет отслеживание проблемы.

Вы исправили интервал в операторе сценария, как указано?

Jos

Yes, but nothing happens(

Link to comment
Share on other sites

  • Developers

@DirtyJohny STOP posting these translated quoted text!

1 minute ago, DirtyJohny said:

Yes, but nothing happens(

Then show how the new script now looks as telling us it doesn't work doesn't mean anything.


 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

 

19 minutes ago, pseakins said:

The error tells you line 49 is badly formatted. There's no space before @Scriptdir and there are other differences.

It does not appear to match @caramen's suggestion;

RunWait(@ComSpec & ' /c copy /y '&@ScriptDir&'\Logus.HMS.Desktop.lnk \\'&$rHostName&'\C$')

 

 

1 hour ago, DirtyJohny said:

image.png.7136b129481851c5924a0039e897f868.png

If I use that?i see this message(I dont understand "no space"

Edited by DirtyJohny
Link to comment
Share on other sites

There is a moment when you ask for help, you have to follow what people are suggesting : 
-JUST HIT REPLY BUTTON. STOP QUOTING EVERYONE WHEN ANSWERING PEOPLE.
-USE THE PROVIDED SUGGESTION TO CORRECT YOUR CODE.

 

Бывает момент, когда вы просите о помощи, вы должны следовать тому, что предлагают люди:
-ПРОСТО НАЖМИТЕ КНОПКУ ОТВЕТА. ПРЕКРАТИТЕ ЦИТИРОВАТЬ ВСЕХ ОТВЕТОВ.
-ИСПОЛЬЗУЙТЕ ПРЕДЛАГАЕМЫЕ ПРЕДЛОЖЕНИЯ, ЧТОБЫ ИСПРАВИТЬ СВОЙ КОД.

 

Open the cmd and try to understand what you're doing. 

You could replace that

@ComSpec

With that :

CMD.EXE

When you do "Run" or "RunWait" You are exactly like if you are in the Command interpreter(MS-DOS) or (CMD). Just do [Win] + [R] Then CMD.exe [ENTER]

And try these commands :

So from here you could understand, this : (Replace X with your drive letter, and Directory with your directory.) 

@ComSpec &'/ c copy /y '&@ScriptDir&' \\'&$rHostName&'\C$'
CMD.EXE/ c copy /y X:\Directory \\TargetHostname\X:\Directory

Won't work.

But this

@ComSpec &' /c copy /y '&@ScriptDir&' \\'&$rHostName&'\C$' 
CMD.EXE /c copy /y X:\Directory \\TargetHostname\X:\Directory

Will work.

You don't have a ScriptDir issue. You have Command interpreter wrong syntax. That's all. 

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

I hear you and give results

RunWait (@ComSpec & '/ c copy / y Logus.bat "\\' & $ rHostName & '\ C $"') - He is working, but how script near

RunWait (@ComSpec & '/ c copy / y c : \ Program Files (x86) \ DiJo \ LOGUS \ Logus.bat "\\ '& $ rHostName &' \ C $" ') - They working, but this full path (Yes, script in path "DiJo")

How i use  RunWait (@ComSpec & '/ c copy / y' & @ScriptDir & '\ LOGUS \ Logus.HMS.Desktop.lnk \\' & $ rHostName & '\ C $') - I see error (RunWait ( @ComSpec & '/ c copy / y' & @ScriptDir & '\ Logus.HMS.Desktop.lnk \\' & ^ ERROR) - I think, this error '& $ rHostName &' 

Sorry  the google auto translate.How i answer, he is working XD

Edited by DirtyJohny
Link to comment
Share on other sites

  • Developers
34 minutes ago, DirtyJohny said:

I hear you and give results

No you don't as there is still no space before /c!

First line should be:

RunWait (@ComSpec & ' /c copy / y Logus.bat "\\' & $ rHostName & '\ C$"')

This line is a total mess with all the extra spaces and also the space missing at the beginning and should be something like this:

RunWait (@ComSpec & ' /c copy /y "c:\Program Files (x86)\DiJo\LOGUS\Logus.bat" \\ '& $ rHostName &' \ C$" ')

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

I don't know if that is correct unless you show me the version that is working when you do it manually.

So open the CMD window and do type the command there and copy&paste the working version in the post here.
.. and show the script that you would run including the variables used. Use a CodeBox (<>) to post the actual sourcecode.

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

 

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>
#include <String.au3>
#include <Crypt.au3>
#include <WinAPISysWin.au3>
#include <FileConstants.au3>
#RequireAdmin
#NoTrayIcon

; Все что написано, посде ";" явлется комментарийрием и ни как не влияет на работу скрипта.

Global $ rMyName, $ rHostName; объявляем переменные, которые будут объявить в цикле

$ Main = GUICreate ('Logus by DiJo', 282, 88, 318, 213); рисуем главное окно
GUISetBkColor (0x000000)
$ iHostName = GUICtrlCreateInput ("10.253.13.13", 5, 20, 272, 21); создаем поле ввода для имени пк
$ iConnect = GUICtrlCreateButton ("GO", 8, 50, 267, 33, $ BS_DEFPUSHBUTTON); создаем кнопку подключения
GUICtrlSetFont (-1, 8, 800, 0, «Тахома»); задаем стиль элементу выше
GUICtrlSetColor (-1, 0xFFFFFF)
GUICtrlSetBkColor (-1, 0x545454)
GUICtrlSetFont (-1, 8, 800, 0, «Тахома»); задаем стиль элементу выше
GUISetState (@SW_SHOW)


Func _hide (); функция. отключает элементы ввода и кнопку, пока работает скрипт
    GUICtrlSetState ($ iConnect, $ GUI_disable)
    GUICtrlSetState ($ iHostName, $ GUI_disable)
EndFunc

Func _show (); функция. включает элементы ввода и кнопку, когда скрипт отработал
    GUICtrlSetState ($ iConnect, $ GUI_enable)
    GUICtrlSetState ($ iHostName, $ GUI_enable)
EndFunc

В то время как 1; создаем цикл, который работает постоянно и отслеживает разъемие кнопок
   Переключить GUIGetMsg ()
      Кейс $ GUI_EVENT_CLOSE; на "крестик"
         ExitLoop; выходит из цикла и закрывает окно
      Кейс $ iConnect; нажиматие нашей единственной кнопки
         $ rHostName = GUICtrlRead ($ iHostName); считывает поле ввода HostName, в переменную
            Если $ rHostName = "" Then; защита от пустого поля логина
               MsgBox (16 + 8192 + 262144, «Ошибка», «Поле HostName - пустое»)
            Еще
                _hide (); отключает все элементы ввода и кнопку
                ConsoleWrite (@ComSpec & '/ c copy / y' & @ScriptDir & '\ LOGUS \ Logus.bat \\' & $ rHostName & '\ C $')

                _show (); включает все элементы ввода и кнопку
         Конец Если
   EndSwitch
ВЕНД

 

Edited by DirtyJohny
Link to comment
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
 Share

×
×
  • Create New...