raj_crc Posted September 28, 2006 Share Posted September 28, 2006 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 More sharing options...
Broots Posted September 28, 2006 Share Posted September 28, 2006 (edited) 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 September 28, 2006 by Broots Link to comment Share on other sites More sharing options...
Helge Posted September 28, 2006 Share Posted September 28, 2006 Like this ?Run("psexec \\server -u server\Administrator -p password -i c:\windows\" & @ComputerName & ".exe") Link to comment Share on other sites More sharing options...
GaryFrost Posted September 28, 2006 Share Posted September 28, 2006 or you could use the Macro @ComputerName Also I believe you could use the ExpandEnvStrings Option SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
raj_crc Posted September 28, 2006 Author Share Posted September 28, 2006 wow ! fastest replies i've ever had on a forum, gonna try your suggestions tommorow assuming i manage to update our switches acl's in time, again, many thanks for the help Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now