Sign in to follow this  
Followers 0
pcjunki

help with variables

6 posts in this topic

i'm need a little help with my script, i think i have some spacing or maybe to many quotes, but just cant figure it out.

i'm having problems with the Func Remote_cmd

the one line that is commented out, works, and the line below, which i want to use, is not working.

here is my code

#include <GUIConstants.au3>
#include < GuiButton.au3>
#Include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Remote Printer Manage", 446, 288, 194, 130)
$Label1 = GUICtrlCreateLabel("Computer Name", 16, 16, 80, 17)
$Input1 = GUICtrlCreateInput("", 16, 40, 145, 21)
$Label2 = GUICtrlCreateLabel("UserName", 16, 104, 54, 17)
$Input2 = GUICtrlCreateInput("", 16, 128, 121, 21)
$Label3 = GUICtrlCreateLabel("Pwd", 16, 184, 25, 17)
$Input3 = GUICtrlCreateInput("", 16, 208, 121, 21)
$combo = GUICtrlCreateCombo("", 200, 40, 193, 25)
GUICtrlSetData(-1,"List_Default_Printer|List_All_Printers|Remote_cmd")
$Button1 = GUICtrlCreateButton("execute", 328, 184, 81, 49)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit




Case $Button1
$app = GUICtrlRead($combo)
$pc = GUICtrlRead($Input1)
$user = GUICtrlRead($input2)
$pwd = GUICtrlRead($input3)
Call($app, $pc, $user, $pwd)
Func Remote_cmd($pc)
;~ ShellExecute ("c:\pstools\psexec.exe" , "\\" & $pc &" -u domain\admin -p password123 cmd" ) <----------- this works
ShellExecute ("c:\pstools\psexec.exe" , "\\" & $pc &" -u "& $user &" -p "& $pwd &" cmd" ) <----------- this doesn't works but i want it to work
EndFunc


EndSwitch
WEnd

Share this post


Link to post
Share on other sites



Firstly, you can't have a function inside of a loop or a Switch/select statement.

Second, I'm not sure what you're doing with the Call statement.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

i am working off a script that i have that works, but the username and password is hard coded into the script.

i want to have inputs in the gui where i can put in the username and pwd

here is a working code

#include <GUIConstants.au3>
#include <GuiButton.au3>
#Include <WindowsConstants.au3>
#include <IE.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("pc tools", 380, 308, 240, 140 )
GUISetBkColor(0xA6CAF0)
$Tab1 = GUICtrlCreateTab(8, 8, 360, 265)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$TabSheet1 = GUICtrlCreateTabItem("Remote Push")
$Label1 = GUICtrlCreateLabel("Computer Name", 16, 40, 80, 17)
$Input1 = GUICtrlCreateInput("", 16, 56, 137, 21)
$combo = GUICtrlCreateCombo("", 160, 56, 193, 25)
GUICtrlSetData(-1, "Remote_cmd")
$Button25 = GUICtrlCreateButton("Execute", 280, 80, 73, 57, 0)
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button25
$app = GUICtrlRead($combo)
$pc = GUICtrlRead($Input1)
Call($app, $pc)

;~ remote push tab
Func Remote_cmd($pc)
ShellExecute ("c:\pstools\psexec.exe" , "\\" & $pc &" -u domain\admin -p pwd cmd" )
EndFunc

EndSwitch
WEnd

Share this post


Link to post
Share on other sites

Your function is still inside the While loop AND inside the Switch statement, you have to move it before that script will even run at all.

Second, you're not calling the function anywhere in your script, your Call statement is badly written.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

so i need to move the function before the while?

i'm working off a posting i created earlier this year, this is where i got the code to work when i first created it

Share this post


Link to post
Share on other sites

You should probably move the function outside of the While loop, whether you put it before it or after it, it won't matter.

Second, you should probably read the help file on how to use Call, or better yet, not use it at all.

Third, your old script and this one don't work the same way, so you can't just reuse the code without modifying it first. The old script "Call"ed a function by the name of the program you were installing, here you're not doing that you're using a combo box with only one entry in it, which makes no sense, and then using that to start the function. The ShellExecute appears to be set up correctly for using the variables, you just have the function in the wrong place.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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