+ Reply to Thread
Results 1 to 4 of 4

pass multiple items to a command line

  1. #1
    Registered User
    Join Date
    03-26-2013
    Location
    Maryland
    MS-Off Ver
    Excel 2010
    Posts
    2

    Question pass multiple items to a command line

    Hello all,

    This is my first post in this forum. I'm relatively new to VBA and coding in general. I found a great Command Line function over at VBA Express
    I made a few changes, because I have no need for the Input Box (I'm working on an automation project and would like to limit the amount of user interaction.)
    This is what I did to change the Test Subroutine:

    Please Login or Register  to view this content.
    When this code runs, the command prompt stays up, requesting a password. Ideally, what I would like to do is keep the username, domain, and passwords as variables in a spreadsheet, and pass these through to cmd as part of this function.

    Is there any way to continue to interact with the command window using the Command Line function?
    I feel like I may be barking up the wrong tree.
    Full disclosure: running the calculator is not my end goal here. Initially I plan to use this function for RegAsm.exe to register an application as a COM object. That being said, it would be incredibly useful to be able to use the command prompt and continue to interact with it via excel VBA script (even outside of trying to get around the Windows UAC stuff.)
    So...
    Is there a way to change the CommandLine function to get what I want? Should I do something completely different? Or is it just not possible to do what I want to do in the first place?

    Thanks in advance!
    Last edited by marcwords; 03-26-2013 at 04:40 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: pass multiple items to a command line

    My best suggestion is.... if you must create strings and commands within VBA that must then be run in command shell, use VBA to create a .bat file that holds all the commands and then use your shell method to execute the bat file, then delete the bat.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    03-26-2013
    Location
    Maryland
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: pass multiple items to a command line

    As a matter of fact, I have the batch files written that accomplish the COM object registration.
    However, my end-goal is to have a fully automated process. In order to run those .bat files, I have to right-click and run as admin due to the W7user account controls.
    I don't really care if regasm.exe is run through the batch files after being called from a VBA script in excel, or if it is done through the VBA script itself. But W7 absolutely cares that the user running regasm.exe is an administrator.
    I guess that the gordian knot solution would be to run excel as admin, but passing more than one string to the cmd window seems like a feat that could easily be accomplished via VBA.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: pass multiple items to a command line

    Some Googling uncovered this suggestion:

    1) Make a batch file in any editor with a specific name
    2) Create a shortcut to it
    3) Right-click on the shortcut and select Properties->Shortcut tab -> Advanced
    4) Click Run as administrator.

    Execute it from the shortcut and the bat file will be run as Administrator. Now use your VBA to edit the original bat file as needed, then use the shell to execute it, but execute from the shortcut.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1