Jump to content
Sign in to follow this  
Skirge01

Pass clicked filename to RunAs?

Recommended Posts

Skirge01

I'm attempting to use RunAs to launch a program via one of its "templates", which have their own extension and are associated as such in Windows.  So, without AutoIt, I can click the template and it automatically opens using the program.  Obviously, I can't figure out how to make it do this via AutoIt or I wouldn't be posting.  :-)

I can go to a CMD prompt and the following will open the referenced QWT file using QW.exe:

c:BusitechQW50>qw.exe L:Measrept20122012-AsepticAseptic Bottle Quality Tra
cking_V2.QWT

I have associated QWT files with my AutoIt executable when attempting to make it work via AutoIt.

The code I'm trying is very basic and here are the various RunAs statements I've tried:

; Fill in the username and password appropriate for your system.

Local $sUserName = "[username]"

Local $sPassword = "[password]"

Local $sDomain = "[company domain]"

Local $sPath = "C:\Busitech\QW50\"



; Run a command prompt as the other user.
RunAs($sUserName, $sDomain, $sPassword, 4, $sPath & "QW.exe " & "%1")
RunAs($sUserName, $sDomain, $sPassword, 4, $sPath & "QW.exe " & $CmdLine[1])
RunAs("[username]", "[domain]", "[password], 4, "C:\Busitech\QW50\QW.exe" & " L:\Measrept\2012\2012-Aseptic\Aseptic Bottle Quality Tracking_V2.QWT")
Run("C:\Busitech\QW50\QW.exe" & " L:\Measrept\2012\2012-Aseptic\Aseptic Bottle Quality Tracking_V2.QWT")

The first 3 attempts simply open QW.exe without the template.  The credentials I'm using at the moment are for my own user account, so it definitely has the correct AD permissions on the L: drive.  I also tried all the various logon flags, just for kicks.  The last entry above was simply a test to see if it could launch it correctly and it did work.  However, I need to use different credentials and QW.exe needs to open whichever QWT file is actually clicked.

At this point, I'm pretty sure the issue is that I'm not passing the template's filename through to the AutoIt program, but none of my searches have provided me with the proper method to do so.  This seems like it should be very easy to figure out, but I'm lost.

Any help would be greatly appreciated.

Share this post


Link to post
Share on other sites
JLogan3o13

You said you believe you're not passing the filename correctly, have you done any error checking? Try a MsgBox or ConsoleWrite to see what the value of $sPath & "QW.exe" is, for example.


√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
Skirge01

Thanks for replying.  I'm not sure exactly how to troubleshoot this, though.  I'm using SciTE and the log window at the bottom doesn't give any errors.  I tried the ConsoleWrite command and wrote all the variables out and they're exactly as defined.  When I do a "Go" on the script, it executes it and opens up the QW.exe program (not the template, as defined in the 3rd RunAs I listed above).  The only thing which shows in the log window is the command line with the .au3 it's running, followed by an exit code 0 and the time it took to complete.

Sorry if I'm misunderstanding what you're asking me to do.

Share this post


Link to post
Share on other sites
JLogan3o13

I'm suggesting something like this, above your RunAs lines, so you make sure you're passing the RunAs command with the info you're intending to:

MsgBox(0, "RunAs1 Test", "Username: " & $sUserName & @CRLF & "Domain: " & $sDomain & @CRLF & "Password: " & $sPassword & @CRLF & "Path: " & $sPath & "QW.exe " & "%1"
MsgBox(0, "RunAs2 Test", "Username: " & $sUserName & @CRLF & "Domain: " & $sDomain & @CRLF & "Password: " & $sPassword & @CRLF & "Path: " & $sPath & "QW.exe " & $CmdLine[1])

√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
BrewManNH

RunAs($username, $domain, $password, 4, "C:\Busitech\QW50\QW.exe 'L:\Measrept\2012\2012-Aseptic\Aseptic Bottle Quality Tracking_V2.QWT'")
; or this if using Windows to start the script when you double click on a .QWT file
RunAs($username, $domain, $password, 4, "C:\Busitech\QW50\QW.exe" & $CmdLine[1])
Your third RunAs command is missing the quote after the "[password]" section, BTW.


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  

×