Jump to content
vyperhand

Execute VBS in a variable location?

Recommended Posts

vyperhand

I'm struggling to launch a VBS file via autoit using RunWait.  Due to the nature of the deployment tool I am using for said script, I only know that the .vbs files will be in the same directory as my AutoIt-generated .exe, but not what that path will be.  The path will look something like this:

c:\programdata\vendor\lots\of\folders\randomnumber

This is generated during deployment and I have no way of predicting the path - therefore, I am not sure how to call back to "same directory" in order to successfully launch the .vbs.

This line is as close as I have gotten - this fires off the cmd window, but it closes immediately with out information, and the .vbs is not launched.

RunWait (@ComSpec & " /c" & 'cscript.exe WORKPLEASE.vbs ALL /Q /NoCancel')

I thought /c might be the problem, but leaving out the /c element causes me not to even see the momentary CMD window flash by.  Any help will be greatly appreciated, and thanks in advance.

Share this post


Link to post
Share on other sites
water

Add a space after " /c"

RunWait (@ComSpec & " /c " & 'cscript.exe WORKPLEASE.vbs ALL /Q /NoCancel')

 


My UDFs and Tutorials:

Spoiler

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

 

Share this post


Link to post
Share on other sites
vyperhand

Thanks Water.

Tried that, no change.  Still just a flash of a command window and the .vbs does not execute.

Share this post


Link to post
Share on other sites
water

Then lets try to keep the window open:

RunWait (@ComSpec & " /k " & 'cscript.exe WORKPLEASE.vbs ALL /Q /NoCancel')

/c stands for "close the window", /k for "keep the window open".

  • Like 1

My UDFs and Tutorials:

Spoiler

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

 

Share this post


Link to post
Share on other sites
Subz

You can just use @ScriptDir for example to point to the same folder as the script:

RunWait (@ComSpec & ' /c cscript.exe "' & @ScriptDir & '\&WORKPLEASE.vbs" ALL /Q /NoCancel')

 

  • Like 1

Share this post


Link to post
Share on other sites
vyperhand

Thanks Water and Subz.

Combining those two got the scripts to fire and leave the screen up for troubleshooting - but then for no explicable reason, the VBS gives a permissions error on trying to remove some registry keys.  This is extremely confusing, as the script works both when called manually from a command line or from a batch.  Just for grins, I even moved the batch into the auto-deployment folder where the .exe landed, and the batch works great... but calling it via the EXE I made with AutoIt doesn't.

I'll dig deeper into that, appreciate the help that at least got me this far.

Share this post


Link to post
Share on other sites
Subz

Try and add #RequireAdmin at the top of your script, assuming the keys are HKLM keys or post your VB script and we can try and convert it to AutoIt

Edited by Subz

Share this post


Link to post
Share on other sites
vyperhand

Let me try #RequireAdmin - the .vbs I'm trying to run isn't one I made myself, unfortunately.  It's one of MS's pre-published Office Removal .VBS monstrosities.  3926 lines, more than a minor effort to convert to AutoIt.  Happy to provide the file if you're feeling froggy, but it seems effort-prohibitive to me.

**Edit - # RequireAdmin didn't change the outcome.  Just for grins, used psexec to kick the .exe off under the system account, same issue.

Edited by vyperhand
Updated information.

Share this post


Link to post
Share on other sites
Subz

Not sure if this would help, but here is what I used when upgrading our Office 2003/2007 clients to Office 2013

#RequireAdmin
Opt("ExpandVarStrings", 1)
;~ Uninstall Office 2003
If RegRead('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{90110409-6000-11D3-8CFE-0150048383C9}', 'DisplayName') Then
    RunWait('@ComSpec@ /c cscript "@ScriptDir@\OffScrub03.vbs" PIA,PROPLUS /S /OSE /BYPASS 1 /NOCANCEL /Quiet', '', @SW_HIDE)
EndIf
;~ Uninstall Office 2007
If RegRead('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{90120000-0011-0000-0000-0000000FF1CE}', 'DisplayName') Then
    RunWait('@ComSpec@ /c cscript "@ScriptDir@\OffScrub07.vbs" EXPDFXPS,PIA,PROPLUS /S /OSE /BYPASS 1 /NOCANCEL /Quiet', '', @SW_HIDE)
EndIf

 

Share this post


Link to post
Share on other sites
vyperhand

Yep, that looks familiar all right.

 

#RequireAdmin
RunWait (@ComSpec & " /c " & 'cscript.exe offscrub07.vbs ALL /Q /NoCancel')
Run (@ComSpec & " /c " & "shutdown /r /t 30 /d P:4:1")

But for some reason, the first step of the VBS fails with a perms error regarding the registry when called from AutoIt.  Still digging into what might be causing that.  So the VBS fails, the sandbox system reboots, and I'm back to the drawing board.  I'll dig into this more tomorrow for sure.

 

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

  • Similar Content

    • KhalidAnsari
      By KhalidAnsari
      Hi,
      I need to automate Java application using AutoIt, I have refer forum for the same, as per forum I am using Java Access Bridge to finding control name. But could not set value to control. Below is my sample code 
      Send("#r")
      sleep(1500)
      Send("D:\javaapplication\javaapplication\Hello.jar{Enter}")
      WinActivate("Penjumlahan")
      sleep(1500)
      ControlSetText("Penjumlahan", "", "Name:  A :", "demo")
      Java Application and Java Ferret screen

    • QaisBsharat
      By QaisBsharat
      Hello, 
      May i know how can i automation qt application?
      Using controlclick not mouse and positions
       
      Thanks
    • nooneclose
      By nooneclose
      Good afternoon, I am in need of some help. I am sure this is a stupid question requiring only one or two lines of code. However, I would greatly appreciate the help I cannot figure this out. I also tried searching for the answer on the internet but no one except me apparently seems to be having a hard time figuring this out and or is asking about it. 
      I simply want to change the "status" of an email from unread to read once I have processed it. My code is over 500 lines and I would like not to clutter this post with it. Assume I have all my includes and connections properly defined and stuff. 
      Here is the bit of code where I am trying to change the email that was used from unread to read:
      Func ChangeEmailStatus() ;******************************************************************************* ; changes the status of an email from unread to Read ;******************************************************************************* Local $iRows = UBound($aItems, $UBOUND_ROWS) MsgBox("", "Number of Unread emails (Before Change)", $iRows) _OL_ItemModify($oOutlook,$aItems[$i][0], Default, "Read=True") MsgBox("", "Array Display 1", $aItems[1][0]) MsgBox("", "Array Display 2", $aItems[2][0]) Local $iRows = UBound($aItems, $UBOUND_ROWS) MsgBox("", "Number of Unread emails (After Change)", $iRows) EndFunc  
    • SharpDressedMan
      By SharpDressedMan
      Hello,
      Is there any way to check for validity of a pointer to a DllStruct ?
      In the above code, a DllStruct is created from an invalid pointer. How to prevent from doing this ?
      local $tStruct = DllStructCreate("int i") DllStructSetData($tStruct, "i", 123) local $pStruct = DllStructGetPtr($tStruct) $tStruct = 0 ; destroy DllStruct ==> $pStruct becomes invalid ; how to check here for validity of $pStruct and prevent from doing the following ? $tStruct = DllStructCreate("int i", $pStruct) ; create DllStruct from invalid pointer... MsgBox(0, @ScriptName, @error) ; displays '0' : invalid pointer is not detected by DllStructCreate() MsgBox(0, @ScriptName, IsDllStruct($tStruct)) ; displays '1' : tStruct is assumed as a valid DllStruct object, which is not Thanks for help
    • nooneclose
      By nooneclose
      I need to send a string of text to this popup and click on the ok button to save it.
      Here is the code I have so far:
      ;Start IE Sleep(7000) $oIE = _IECreate("http://www.google.com") Sleep(500) _IELoadWait($oIE) $hIE = _IEPropertyGet($oIE, "hwnd") ; Get Handle of the IE window Sleep(500) WinSetState($hIE, "", @SW_MAXIMIZE) ;Wait for a browser page load to complete Sleep(3000) _IENavigate($oIE, "https://properURL.com") Sleep(8000) _IELoadWait($oIE) ;Attach to a browser control embedded in another window $oIE = _IEAttach("https://"properURL.com", url") ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $oIE = ' & $oIE & @CRLF & '>Error code: ' & @error & ' Extended code: 0x' & Hex(@extended) & @CRLF) ;### Debug Console Sleep(2000) ;Get the title of the webpage ;Local $wTitle = _IEPropertyGet($oIE, "title") ;MsgBox($MB_SYSTEMMODAL, "Webpage title:", $wTitle) ;Clicks the new button Sleep(3000) _IEAction($nWorkOrderB, "focus") _IEAction($nWorkOrderB, "click") Sleep(5000) ;Store the Element names where the important data will be sent ;Store the long description button Local $wLongDButton = _IEGetObjById($oIE, "m65d795a4-img") ;Store the long Description field id Local $wComments = _IEGetObjById($oIE, "ma6499a9c-rte_iframe") ;Store the ok button id that is in the long description Local $wCommOk = _IEGetObjById($oIE, "m74031266-pb") ;******************************************************************************* ; Send the stored data to the proper field ;******************************************************************************* ;Click the long description button Sleep(300) _IEAction($wLongDButton, "focus") _IEAction($wLongDButton, "click") Sleep(300) ;Sends the Comments Sleep(500) _IEAction($wComments, "focus") _IEAction($wComments, "click") Sleep(500) _IEFormElementSetValue($wComments, "hello darkness my old friend") ;Click the ok button Sleep(500) _IEAction($wCommOk, "focus") _IEAction($wCommOk, "click") Sleep(500)  
      Here is the popup:

×