Jump to content

general scripting question


Recommended Posts

Hello team, I have a simple script I am trying to write. Basically I have 2 buttons. I have 1 that copies a vbscript file to a temp directory and the other to run the script once its copied. I am not having any luck getting even just the file to copy over. I was wondering if someone can look at the script give me some pointers. I did a lot of reading in the help file and found that filecopy might work for this. In the windows command prompt I know cscript will run my vbscript file so I am trying to declare that to run under button2. Can anyone help me write this? TYIA

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#Include <String.au3>


#Region ### START GUI section ###
$Form1 = GUICreate("File Fixer", 414, 389, 2165, 271)
GUISetBkColor(0x008080)

;this button should copy the vbs to the temp folder

$Button1 = GUICtrlCreateButton("Copy to c:\Temp", 8, 72, 89, 25)




$Label3 = GUICtrlCreateLabel("first name:", 8, 128, 58, 17)
GUICtrlSetColor(-1, 0xFFFFFF)

;creating variable fname to hold hte first name

$fname = GUICtrlCreateInput("", 80, 120, 81, 21)

;creating variable lname to hold hte last name

$lname = GUICtrlCreateLabel("last name:", 8, 168, 60, 17)
GUICtrlSetColor(-1, 0xFFFFFF)
$OU = GUICtrlCreateInput("", 80, 160, 81, 21)

;should run the script once pressed
$Button2 = GUICtrlCreateButton("Run Script", 80, 208, 121, 25)
GUISetState(@SW_SHOW)
#EndRegion ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $fname
    EndSwitch
 WEnd

so from here I should be able to click button1 have it copy the a.vbs file to the temp using filecopy

I am thinking then using button2 to take the input from fname and lname then run cscript via the cmd option and input that into the script

Any help is greatly appreciated

Edited by Melba23
Added code tags and moved thread
Link to comment
Share on other sites

You need to do a lot more research in help file,

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <String.au3>


#Region ### START GUI section ###
$Form1 = GUICreate("File Fixer", 300, 400, Default, Default)
;~ GUISetBkColor(0x008080)

;this button should copy the vbs to the temp folder

$Button1 = GUICtrlCreateButton("Copy to c:\Temp", 8, 72, 89, 25)




$Label3 = GUICtrlCreateLabel("first name:", 8, 128, 58, 17)
GUICtrlSetColor(-1, 0xFFFFFF)

;creating variable fname to hold hte first name

$fname = GUICtrlCreateInput("", 80, 120, 81, 21)

;creating variable lname to hold hte last name

$lname = GUICtrlCreateLabel("last name:", 8, 168, 60, 17)
GUICtrlSetColor(-1, 0xFFFFFF)
$OU = GUICtrlCreateInput("", 80, 160, 81, 21)

;should run the script once pressed
$Button2 = GUICtrlCreateButton("Run Script", 80, 208, 121, 25)
GUISetState(@SW_SHOW)
#EndRegion ### START GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            MsgBox($MB_OK, "Copy", GUICtrlRead($fname))
        Case $Button2
            MsgBox($MB_OK, "Run", GUICtrlRead($OU))
    EndSwitch
WEnd

 

ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Link to comment
Share on other sites

Maybe:

#NoTrayIcon
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

#Region ### START GUI section ###
Global $hGUI = GUICreate("Welcoem to Autoit :)", 587, 139, -1, -1)
GUISetBkColor(0x008080)
GUICtrlCreateLabel("", 8, 0, 6, 33)
GUICtrlSetBkColor(-1, 0x00FFFF)
Global $iAppName = GUICtrlCreateLabel("PROGRAM NAME DO SOMETHINK", 16, 0, 555, 25, $SS_CENTERIMAGE, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlCreateLabel("Frist Name:", 24, 40, 57, 17)
GUICtrlSetColor(-1, 0xFFFFFF)
Global $iFristName = GUICtrlCreateInput("", 96, 40, 305, 21)
GUICtrlCreateLabel("Last Name:", 24, 72, 66, 17)
GUICtrlSetColor(-1, 0xFFFFFF)
Global $iLastName = GUICtrlCreateInput("", 96, 72, 305, 21)
GUICtrlCreateLabel("Full Name:", 24, 104, 54, 17)
GUICtrlSetColor(-1, 0xFFFFFF)
Global $cFullName = GUICtrlCreateLabel("", 96, 104, 308, 17)
GUICtrlSetColor(-1, 0xFFFFFF)
Global $bCopy = GUICtrlCreateButton("Copy to TEMP", 424, 32, 147, 25)
Global $bRunScript = GUICtrlCreateButton("Run Script", 424, 64, 147, 65)
GUISetState(@SW_SHOW)
#EndRegion ### START GUI section ###

Global $zFristName, $zLastName, $zFullName

While 1
    Switch GUIGetMsg()
        Case $iFristName, $iLastName
            _ReadGuiData()
            GUICtrlSetData($cFullName, $zFullName)
;~          GUICtrlSetData($cFullName,_ReadGuiData())

        Case $bRunScript
            ; Do some think
            MsgBox(32, "RunScript", "You enter: " & _ReadGuiData() & @CRLF & @CRLF & "Frist Name: " & $zFristName & @CRLF & "Last Name: " & $zLastName)

        Case $bCopy
            ; Do some think
            MsgBox(32, "Copy", "You enter: " & _ReadGuiData() & @CRLF & @CRLF & "Frist Name: " & $zFristName & @CRLF & "Last Name: " & $zLastName)

        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func _ReadGuiData()
    $zFristName = GUICtrlRead($iFristName)
    $zLastName = GUICtrlRead($iLastName)
    $zFullName = $zFristName & " " & $zLastName
    Return $zFullName
EndFunc   ;==>_ReadGuiData

 

Regards,
 

Link to comment
Share on other sites

@indnracn2

Why not try using "FileExists()". With it you can control the program.

Example:

Global $zFristName, $zLastName, $zFullName
$Input = GUICtrlRead($fname)& " " & GUICtrlRead($OU)

Case $Button2
    If FileExists($Input) Then
        MsgBox(32, "RunScript", "You enter: " & GUICtrlRead($fname) & " " & GUICtrlRead($OU) & @CRLF & @CRLF & "Frist Name: " & GUICtrlRead($fname) & @CRLF & "Last Name: " & GUICtrlRead($OU))
        Run(@ScriptDir & "\" & $Input & ".exe")                        
    Else
        MsgBox(64,"Error runing script!","Unable to run program.")
    EndIf

 

Edited by KickStarter15

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Link to comment
Share on other sites

So here is where I am now. AFter reading that help file and more research I can get it all to work except the run(comspec part) can anyone look at my code now? The copy is working fine but the vbs script only process the firstname part only not the last name part to commit.

TYIA

 

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#Include <String.au3>


#Region ### START GUI section ###
$Form1 = GUICreate("File Fixer", 414, 389, 2165, 271)
GUISetBkColor(0x008080)

;this button should copy the vbs to the temp folder

$Button1 = GUICtrlCreateButton("Copy to c:\Temp", 8, 72, 89, 25)

$Label1 = GUICtrlCreateLabel("first name:", 8, 128, 58, 17)
GUICtrlSetColor(-1, 0xFFFFFF)

;creating variable fname to hold hte first name

$fname = GUICtrlCreateInput("", 80, 120, 81, 21)

;creating variable lname to hold hte last name

$Label2 = GUICtrlCreateLabel("last name:", 8, 168, 60, 17)
GUICtrlSetColor(-1, 0xFFFFFF)
$lname = GUICtrlCreateInput("", 80, 160, 81, 21)

;should run the script once pressed
$Button2 = GUICtrlCreateButton("Run Script", 80, 208, 121, 25)
GUISetState(@SW_SHOW)
#EndRegion ###

While 1
   $msg = GUIGetMsg()
   Select
      Case $msg = $GUI_EVENT_CLOSE
         Exit

         Case $msg = $Button1
         Run(@ComSpec & ' /c ' & 'copy test.VBS c:\temp')

         Case $msg = $Button2
         Run(@ComSpec & ' /k ' & 'cscript c:\temp\test.vbs /First Name:' & GUICtrlRead($fname) & ' /Last Name:' & GUICtrlRead($lname) & ' /commit:true')

   EndSelect
WEnd
Link to comment
Share on other sites

You could check if the command line being executed is correct something like:

#include <GUIConstantsEx.au3>

Global $sVBSScript = "C:\Temp\Test.vbs"

#Region ### START GUI section ###
$Form1 = GUICreate("File Fixer", 414, 389, 2165, 271)
GUISetBkColor(0x008080)

GUICtrlCreateLabel("first name:", 8, 128, 58, 17)
GUICtrlSetColor(-1, 0xFFFFFF)

;creating variable fname to hold hte first name

$fname = GUICtrlCreateInput("", 80, 120, 81, 21)

;creating variable lname to hold hte last name

GUICtrlCreateLabel("last name:", 8, 168, 60, 17)
GUICtrlSetColor(-1, 0xFFFFFF)
$lname = GUICtrlCreateInput("", 80, 160, 81, 21)

;should run the script once pressed
$Button2 = GUICtrlCreateButton("Run Script", 80, 208, 121, 25)
GUISetState(@SW_SHOW)
#EndRegion ###

While 1
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button2
            MsgBox(0,"Run " & $sVBSScript, @ComSpec & ' /k cscript "' & $sVBSScript & '" /First Name:' & GUICtrlRead($fname) & ' /Last Name:' & GUICtrlRead($lname) & ' /commit:true')
            If FileExists($sVBSScript) = 0 Then RunWait(@ComSpec & ' /c ' & 'copy test.VBS c:\temp', "", @SW_HIDE)
            If FileExists($sVBSScript) Then
                Run(@ComSpec & ' /k cscript "' & $sVBSScript & '" /First Name:' & GUICtrlRead($fname) & ' /Last Name:' & GUICtrlRead($lname) & ' /commit:true')
            EndIf
   EndSwitch
WEnd

 

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...