Jump to content

help needed using variables


raj_crc
 Share

Recommended Posts

Hi, i need to create a script to launch an executable on a server, the executable is unique to each workstation that launches it - ie. each technican workstation has a different executable to launch on the server.

When i specifiy the exectutable as its exact name e.g. raj it works.

i.e.

Run("psexec \\server -u server\Administrator -p password -i c:\windows\raj.exe")

However that would mean a dozen buttons in the gui, one for each technicans workstation.

The executables on the server have been named after the workstation i.e. if i goto dos - command prompt and type hostname the hostname is the same as the executable on the server.

The idea being i could use the variable %hostname%.exe as a variable to launch the relevant server executable from the workstation. However this fails.

Run("psexec \\server -u server\Administrator -p password -i c:\windows\%hostname%.exe")

i can get the script working when i do not use variable and dirrectly specify my machines executable as shown in the below executable - ( the words server and password are put in to avoid leaking my server/pass, but are constants and set in the script )

How can i use variables to execute the program on the server depending on the hostname of the machine ?

---------------------------------------WORKING NO VARIABLES-----------------------------

; ----------------------------------------------------------------------------

;

; AutoIt Version: 3.1.0

; Author: raj <edited>

;

; Script Function:

; AutoIt script.

;

; ----------------------------------------------------------------------------

; Script Start - Add your code below here

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode

$mainwindow = GUICreate("CRC", 260, 140)

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

GUICtrlCreateLabel("Maxivista software interface- Raj Sept 2006", 20, 10)

$okbutton = GUICtrlCreateButton("Clear Fassmon mirror", 30, 50, 190)

GUICtrlSetOnEvent($okbutton, "OKButton")

$nobutton =GUICtrlCreateButton("Mirror Fassmon", 30, 90, 190)

GUICtrlSetOnEvent($nobutton, "noButton")

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

GUISwitch($mainwindow)

GUISetState(@SW_SHOW)

While 1

Sleep(1000) ; Idle around

WEnd

Func OKButton()

Run("psexec \\server -u server\Administrator -p password -i c:\windows\clear.bat", "", @SW_HIDE)

EndFunc

Func noButton()

Run("psexec \\server -u server\Administrator -p password -i c:\windows\raj.exe")

EndFunc

Func CLOSEClicked()

;@GUI_WINHANDLE will be either $mainwindow or $dummywindow

If @GUI_WINHANDLE = $mainwindow Then

Exit

EndIf

EndFunc

-------------------------------WORKING NO VARIABLES------------------------------------

Link to comment
Share on other sites

What I would do is to use the AutoIT function to get the localhostname which is:

EnvGet("ComputerName")

Run("psexec \\server -u server\Administrator -p password -i c:\windows\" & EnvGet("ComputerName") & ".exe")

That should solve your problem.

Edited by Broots
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...