Launching an application with a PS script

Hi everybody,
          I'm an absolute beginner with PowerShell, so please be patient :-)
I'm going to write my first script for PowerShell. The script core concerns an external software I need to launch. This is a typical code for a batch file:
cd case_path
echo "macro" | "app_path"app.exe case.ext 2>&1 >> log
It results in:
- go to the folder containing the 'case' to launch (just a file containing settings)
- run the case with application.exe, execute the 'internal macro' and generate a log file
I'm able to run the application with
Invoke-Item app_path\app.exe
but I can't run the specific case (and the internal macro too). Could you help me, the batch script as a starting point?

OK, I'm here again, just for feedback and sharing (are there other newbies out there?)
I made some tests with both methods (thanks Fred and jrv!).
method cmd /c
$FS_path = $env:fsinstall + '\bin\win32\'
$case_path = '.\f1'
$cmdString = 'cd ' + $case_path + ' && echo "res" | "' + $FS_path + '"xfsflow doubleSkegCase.fme 2>&1 >> log.txt'
method Start-Process
$FS_path = $env:fsinstall + '\bin\win32\xfsflow'
$args = '-c "res" doubleSkegCase.fme'
$FS_case = '.\f1'
$sim=@{
FilePath = $FS_path
ArgumentList = $args
WorkingDirectory = $FS_case
RedirectStandardOutput = "$FS_case\log.txt"
Start-Process @sim -noNewWindow -wait
just two more questions:
1. is it possible to get rid of the standard error output? I'd like to have no error messages in the terminal or as a file
2. I'd like to make the macro "res" in the ArgumentList
as a variable, but I'm not able to. I guess the problem concerns escape characters or similar, could you help me?

Similar Messages

  • How to launch an application with elevated administrator account privilege from windows service even if the account has not yet logon

    Here is the case:
    OS environment: Windows 7
    There are two user accounts in my system, standard user "S" and administrator account "A", and there is a windows service running with "Local System" privilege.
    Now i logged-in with account "S", and i want to launch an application with elevated administrator account "A" from that service program, so here is the code snippet:
    int LaunchAppWithElevatedPrivilege (
    LPTSTR lpszUsername, // client to log on
    LPTSTR lpszDomain, // domain of client's account
    LPTSTR lpszPassword, // client's password
    LPTSTR lpCommandLine // command line to execute e.g. L"C:\\windows\\regedit.exe"
    DWORD dwExitCode = 0;
    HANDLE hToken = NULL;
    HANDLE hFullToken = NULL;
    HANDLE hPrimaryFullToken = NULL;
    HANDLE lsa = NULL;
    BOOL bResult = FALSE;
    LUID luid;
    MSV1_0_INTERACTIVE_PROFILE* profile = NULL;
    DWORD err;
    PTOKEN_GROUPS LocalGroups = NULL;
    DWORD dwLength = 0;
    DWORD dwSessionId = 0;
    LPVOID pEnv = NULL;
    DWORD dwCreationFlags = 0;
    PROCESS_INFORMATION pi = {0};
    STARTUPINFO si = {0};
    __try
    if (!LogonUser( lpszUsername,
    lpszDomain,
    lpszPassword,
    LOGON32_LOGON_INTERACTIVE,
    LOGON32_PROVIDER_DEFAULT,
    &hToken))
    LOG_FAILED(L"GetTokenInformation failed!");
    __leave;
    if( !GetTokenInformation(hToken, (TOKEN_INFORMATION_CLASS)19, (VOID*)&hFullToken,
    sizeof(HANDLE), &dwLength))
    LOG_FAILED(L"GetTokenInformation failed!");
    __leave;
    if(!DuplicateTokenEx(hFullToken, MAXIMUM_ALLOWED, NULL,
    SecurityIdentification, TokenPrimary, &hPrimaryFullToken))
    LOG_FAILED(L"DuplicateTokenEx failed!");
    __leave;
    DWORD dwSessionId = 0;
    WTS_SESSION_INFO* sessionInfo = NULL;
    DWORD ndSessionInfoCount;
    bResult = WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE, 0, 1, &sessionInfo, &ndSessionInfoCount);
    if (!bResult)
    dwSessionId = WTSGetActiveConsoleSessionId();
    else
    for(unsigned int i=0; i<ndSessionInfoCount; i++)
    if( sessionInfo[i].State == WTSActive )
    dwSessionId = sessionInfo[i].SessionId;
    if(0 == dwSessionId)
    LOG_FAILED(L"Get active session id failed!");
    __leave;
    if(!SetTokenInformation(hPrimaryFullToken, TokenSessionId, &dwSessionId, sizeof(DWORD)))
    LOG_FAILED(L"SetTokenInformation failed!");
    __leave;
    if(CreateEnvironmentBlock(&pEnv, hPrimaryFullToken, FALSE))
    dwCreationFlags |= CREATE_UNICODE_ENVIRONMENT;
    else
    pEnv=NULL;
    if (! ImpersonateLoggedOnUser(hPrimaryFullToken) )
    LOG_FAILED(L"ImpersonateLoggedOnUser failed!");
    __leave;
    si.cb= sizeof(STARTUPINFO);
    si.lpDesktop = L"winsta0\\default";
    bResult = CreateProcessAsUser(
    hPrimaryFullToken, // client's access token
    NULL, // file to execute
    lpCommandLine, // command line
    NULL, // pointer to process SECURITY_ATTRIBUTES
    NULL, // pointer to thread SECURITY_ATTRIBUTES
    FALSE, // handles are not inheritable
    dwCreationFlags, // creation flags
    pEnv, // pointer to new environment block
    NULL, // name of current directory
    &si, // pointer to STARTUPINFO structure
    &pi // receives information about new process
    RevertToSelf();
    if (bResult && pi.hProcess != INVALID_HANDLE_VALUE)
    WaitForSingleObject(pi.hProcess, INFINITE);
    GetExitCodeProcess(pi.hProcess, &dwExitCode);
    else
    LOG_FAILED(L"CreateProcessAsUser failed!");
    __finally
    if (pi.hProcess != INVALID_HANDLE_VALUE)
    CloseHandle(pi.hProcess);
    if (pi.hThread != INVALID_HANDLE_VALUE)
    CloseHandle(pi.hThread);
    if(LocalGroups)
    LocalFree(LocalGroups);
    if(pEnv)
    DestroyEnvironmentBlock(pEnv);
    if(hToken)
    CloseHandle(hToken);
    if(hFullToken)
    CloseHandle(hFullToken);
    if(hPrimaryFullToken)
    CloseHandle(hPrimaryFullToken);
    return dwExitCode;
    I passed in username and password of account "A" to method "LaunchAppWithElevatedPrivilege", and also the application i want to launch, e.g. "C:\windows\regedit.exe", but when i run the service program, i found it do launch
    "regedit.exe" with elevated account "A", but the content of regedit.exe is pure back. screenshot as below:
    Can anyone help me on this?

    You code is not dealing with the DACL access to Winsta0\Default.  Only the LocalSystem account will have full access and the interactively logged on user which is why regedit is not displaying properly.  You'll need to grant access to your user. 
    You also need to deal with UAC since that code is going to give you a non-elevated token via LogonUser().  You need to get the full token via a call to GetTokenInformation() + TokenLinkedToken.
    thanks
    Frank K [MSFT]
    Follow us on Twitter, www.twitter.com/WindowsSDK.

  • Launching an application with midlet?

    Hi,
    I'm total beginner with j2me and need help. I know it is possible to launch an application with midlet with platformRequest, but how is it done?
    Could anyone give me a simple example?
    Thx.

    Hi,
    If you are using a WTK2.0 version you can simulate this command.
    add below line to system.config file in wtk20/lib dir
    com.sun.midp.midlet.platformRequestCommand: "C:\Program Files\Internet Explorer\IEXPLORE.EXE"
    invoke the command by
    midlet.platformRequest("http://java.sun.com");
    cheers
    phani

  • Failed to launch JavaFX application with native bundle exe

    Hi,
    I have created a JavaFX application, and created its native bundle using Ant. When I am trying to launch application using Jar from bundle created with double click, it successfully launching my application. But when I am trying double click on MyApplication.exe (say), it throwing JavaFX Launcher Error *"Exception while running Application"*.
    I have searched about this issue, I found about jre, so I did replace jre from *"C:\Program Files\Java\jdk1.7.0_10\jre"* to my application bundle folder -- *\bundles\MyApplication\runtime\jre*, then I tried to launch exe with double click, it successfully launched.
    I have compared both jre, there are many missing jar, exe, dll and some properties files I found.
    I have these environment settings -
    JAVA_HOME -- C:\Program Files\Java\jdk1.7.0_10
    JREFX_HOME -- C:\Program Files\Oracle\JavaFX 2.2 Runtime
    Path contains an entry of C:\Program Files\Java\jdk1.7.0_10\bin JAVA_HOME and JREFX_HOME are used as in my build.xml to take ant-javafx.jar and jfxrt.jar --
    ${env.JAVA_HOME}/lib/ant-javafx.jar
    ${env.JREFX_HOME}/lib/jfxrt.jarMy steps to create bundle are -
    <target name="CreatingExe" depends="SignedJar">
                 <fx:deploy width="800" height="600" nativeBundles="all" outdir="${OutputPath}" outfile="${app.name}">
                          <fx:info title="${app.title}"/>
                          <fx:application name="${app.title}" mainClass="${main.class}"/>
                          <fx:resources>
                               <fx:fileset dir="${OutputPath}" includes="*.jar"/>
                         <fx:fileset dir="${WorkingFolder}/temp"/>
                   </fx:resources>
               </fx:deploy>
    </target>What more needed in build.xml so that application launch correctly with exe ?
    Thanks

    You code is not dealing with the DACL access to Winsta0\Default.  Only the LocalSystem account will have full access and the interactively logged on user which is why regedit is not displaying properly.  You'll need to grant access to your user. 
    You also need to deal with UAC since that code is going to give you a non-elevated token via LogonUser().  You need to get the full token via a call to GetTokenInformation() + TokenLinkedToken.
    thanks
    Frank K [MSFT]
    Follow us on Twitter, www.twitter.com/WindowsSDK.

  • Auto-launching other applications with iTunes

    i recently download itunesMenu, a little app that displays currently playing song in the menubar. at the minute i've got it in my startup apps, but my startup is getting a little sluggish so i'm trying to reduce what i have in there. also even if its at the bottom of the startup list, it opens before other apps that i have in my menubar, which is annoying because as it scrolls it moves the other icons.
    i was wondering if anyone knows of a way whereby i can get itunesMenu to automatically launch everytime i launch itunes?
    thanks in advance

    What worked for me:
    Connect iPhone
    Open iTunes
    Click to select iPhone on left side
    Uncheck Open iTunes when this iPhone is connected
    Click Apply in the lower right corner
    Click Sync in the lower right corner
    Click to check Open iTunes when this iPhone is connected
    This should open a pop-up window asking to install iTunes Helper. Be sure to click to install iTunes Helper
    Click Apply in the lower right corner
    Click Sync in the lower right corner
    Unplug iPhone
    Click iTunes | Exit
    Connect iPhone via USB connector and iTunes should launch

  • Which is better approach to manage sharepoint online - PowerShell Script with CSOM or Console Application with CSOM?

    Which is better approach to manage sharepoint online - PowerShell Script with CSOM or Console Application with CSOM?
    change in sharepoint scripts not require compilation but anything else?

    Yes, PowerShell is great, since you can quick change your code without compilation.
    SP admin can write ps scripts without specific tools like Visual Studio.
    With powershell you can use cmdlets,
    which could remove a lot of code, for example restarting a service.
    [custom.development]

  • Launch application with hotkey

    is there a way to launch any selected application with a hotkey from finder? any help is greatly appreciated.
    Mark N

    kevinkendall wrote:
    hehehe
    hey Project
    I don't know if yer joshin' er not!....
    hehe kinda funny, that answer.
    But according to your profile info, you should be joshin'! <g>
    But if, by some stretch, you're not, lookie: http://en.wikipedia.org/wiki/Hotkey
    kk
    what's really funny is that ProjectArchangel's answer was marked as solved by the original poster. I guess he found it satisfactory or perhaps liked the humor...

  • How to launch a Java WebStart application with older JREs when Java 7u25 is on the client?

    How can I launch older versions of my Java WebStart application, that are built and run with Java 7u21 or earlier, even if Java 7u25 is installed locally on the client? Application launch and behaviour must be reliable and consistent.
    Background:
    As of 7u25 (and later), Java Webstart applications launch with a different class loader than pre-7u25.
    My Java Webstart application has supported versions that were built with older versions of the JDK (e.g. Java 5, 6, 7u21 or earlier). These applications run with their required JRE version, enforced through JNLP. Once Java 7u25 is installed locally, these older applications fail to launch, due to classloader differences.
    The question is: what is required to run older Java WebStart applications even if 7u25 (or later) Java Webstart is installed locally on the client?

    I confirm your findings when using shortcuts to try specific versions of JavaWS with 7u25 or later installed:
    JRE 5u14 launched and the classloader was as pre 7u25
    JRE 6u43 would not launch
    JRE 7u21 launched but the classloader was not as pre 7u25
    You can launch the shortcut with the JavaWS -verbose option to display a messagebox with valuable information.
    I am keeping a close watch on this thread.

  • Why do applications (Illustrator, Pages, Mail) launch so slowly with spinning ball (about a minute to 90 seconds) when Mac is connected to our LAN, but when I disconnected Mac from the LAN, those applications launch instantly and function normally?

    I hope I'm submitting this properly, I apologize if this irritates anyone because of improper etiquette. Why do applications (Illustrator, Pages, Mail) launch so slowly with spinning ball (about a minute to 90 seconds) when Mac is connected to our LAN, but when I disconnected Mac from the LAN, those applications launch instantly and function normally? This is a condition which seemed to start just recently and abruptly. These applications reside on, and are launched from the startup drive, not from a network drive. Also, we have a NAS drive on the LAN that we connect to that also takes a minute or two to mount, when it used to (before this problem) mount on the desktop in a matter of about 5 seconds. We have three identical Mac Pros on the LAN, and they all have this problem when launching and using the above mentioned applications. When I physically unplug the network cable from the Mac, all applications launch instantly and function normally. I know very little about networks, so I can't begin to test or change any setting pertaining to our network - if that is where the problem lies. The only recent change to our network situation is that we lost or our internet and phone service due to massive flooding here in Minot, North Dakota (our ISP tells us the communication lines are under water and shorting out). But shouldn't our LAN still function even though we have lost our connection to the outside world? Thanks so much, in advance, for helping me solve this problem. Sheldon.

    Hi there.
    A slow LAN can have many things so its going slow.
    1) is your lan 1gbit speed? (full duplex)
    2) are the macs also 1Gbit speed? (full duplex)
    3) does your nas has a firewall? (so you can see what the mac asking there)
    4) on the macs is the firewall on? (does the programms can pass the fw?)
    5) how big is the nas and how many files/dirctorys are on the nas? (big folders speeds down )
    many questions, but sometimes there is a solution.
    regards tim

  • Launching applications with CF

    Hello - My company is considering a Web page as an
    application launcher. Essentially it would be a page that displays
    images of the program icons, and when the user clicks an icon, the
    executable runs (C:\Program Files\Microsoft
    Office\Office10\WINWORD.EXE). Is there any ColdFusion code that
    will run an executable from a user's hard drive or network
    share?

    Is there any ColdFusion code that will run an executable from
    a user's
    hard drive or network share?
    <cfexecute...> will launch many applications, from the
    point of view of
    the the CF-Server and the user it runs under. I suspect what
    you really
    want is not going to work well. A ColdFusion server has
    almost no
    ability to interact with a client system. If it did it would
    be a huge
    security risk and people would be abusing it all over the
    place.

  • EMET 5.1 With Default Installation Causes Slow Launching of Applications

    What would I have to change to improve the speed when launching applications with EMET 5.1 running?

    What would I have to change to improve the speed when launching applications with EMET 5.1 running?

  • Strange problem when re-launching an application

    I have this program which can self-update to the latest version. What it does is downloads the new version of itself, deletes the old version, renames the new version, sets its permissions and executes it.
    Up until this next point, everything worked fine.
    The method it executes it is using the Unix style exec() functions.
    Until recently, my app was run "Unix Style", as in some kind of login script ran it. There were a lot of issues the cropped up, so I changed it to a proper application package. You know, with the .app directory structure with the real executable inside the MacOS directory.
    Now what happens is that the initial app launches and seems to run normally, but when an update comes down, it goes through its update process and launches the replacement with the exec() functions.
    Then something strange happens. My app will run for a few more seconds, and then just stop. It will disappear from the task viewer. It does not crash, it just goes away without any explanation.
    I have put a lot of logging statements in, and there is no reason for it to stop where it does. I do not even think it stops at the same place. In once caase it stopped between to logging statements. IE: Log statement #1 was in my log file, but no log statement #2 when there was nothing in the world that could have caused the program to exit between them.
    Does anyone know why this happens?
    I have a suspicion, that maybe the fact that I am using the Unix exec command to launch the app, it is causing some trouble and I need to use the apple method.
    What is the API command to launch another executable in a manner that it would be launched by the login window aka a user double clicking on the app icon?

    First of all, have you set a proper bundle identifier for your app? It'll be the CFBundleIdentifier entry in the bundle's Info.plist file.
    The equivalent to double-clicking on an app in the Finder is probably LSOpenFSRef() which is part of Launch Services:
    OSStatus LSOpenFSRef (
    const FSRef *inRef,
    FSRef *outLaunchedRef
    You can change a posix style path to an FSRef (opaque File system reference) using FSPathMakeRef():
    OSStatus FSPathMakeRef (
    const UInt8 * path,
    FSRef * ref,
    Boolean * isDirectory
    That function is part of the CoreServices framework:
    /Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/CoreServices.framework / .. /Frameworks/CarbonCore.framework/ .. /Headers/Files.h"
    Hope this helps....
    Dual 2.7GHz PowerPC G5 w/ 2.5 GB RAM; 17" MacBook Pro w/ 2 GB RAM -   Mac OS X (10.4.8)  

  • Applescript application with UI dialogs auto relaunch !

    I have a strange behavior with Applescript Application with UI dialogs (for exemple, just display dialog "toto" ). These scripts run, quit and then always relaunch with no end, a king of "keepalive" option.
    The problem doesn't appear when I run the script from the Applescript Editor, neither with scripts without UI dialogs. I've tried my application script on another Mac, and it was okay, just on normal run and quit.
    I can't find the source of my problem on the particular mac, both Macs are up to date (10.8.2). I've cleaned up some startup damemons, relaunch the dyld database. I tried to find a clue with the ps command, but I just can see that my application is relaunched by launchd, without more information.
    Has anyone experienced the same problem, or have an idea to find the source of this, thanks.

    You're a little light on details there, which is going to make answering your question tricky.
    Are you saying, though, that launchd is starting your script? repeatedly?
    If so it would help to know what your script is doing. Launchd expects to launch executables and doesn't expect them to quit. If it quits (or dies) within 10 seconds then launchd assumes the process failed and relaunches it. That sounds to me like what you're saying (/var/log/system.log will confirm that).
    If that's the case, the problem is that your script is too quick. Slow it down by ensuring it takes at least 10 seconds before it quits (a simple delay added to the end of the run handler should take care of that), then launchd won't try to restart it.
    You can also edit the launchd configuration to not be so sensitive to short-lived tasks, but that's probably more work.

  • Open Application with files arguments

    I want to create a Finder Service thats launch 7zX Application passing the selected files and folder as parameters. 7zX application works dropping files/folder on his icon, can I simulate that action with appleScript?
    7z compress algorithm can be called from terminal, but I what to use the 7zX graphical interface.

    Camelot wrote:
    You should be able to do it via something like;
    tell application "Finder" to open file "path:to:your.file" using application "7zX.app"
    Thanks to Reply.
    I tried that Script:
    set fileName to "/Users/mario/Desktop/aew.PNG" as POSIX file
    tell application "Finder" to open file fileName using application "7zX"
    but doesn't work.
    7zX send a pop up with message
    This software only works through drag & drop.
    and AppleScript Editor with Error
    error "Finder got an error: Can’t make application \"7zX\" into type application file." number -1700 from application "7zX" to application file
    To test that idea I changed 7zX to Preview but AppleScript Editor send me the same Error.
    (Sorry about my english)
    Message was edited by: MarioBajr

  • Launching external applications from web start

    Hi!
    I am currently working on a management system and I need to launch other management systems from my Java Web Start application. The other systems are either based on web applications (URLs), telnet - needs to set up a telnet session, or running shell scripts or batch files.
    URLs are ok. I am using Desktop.browse in Java 1.6 or I can use BasicService.showDocument in javax.jnlp API.
    My application may run on both windows and linux (ie its launched from the browser). It interacts with a java app on a linux server over RMI.
    How can I lauch a telnet session from my client app?
    Do I have to include apache commons.net and create a telnet module in my app or can i lauch c:\windows\system32\telnet.exe in windows (if my app is lauched on win) and /usr/kerberos/bin/telnet (if my app is lauched in Linux)?
    How can I launch an external .exe application in window and how can I launch any shell script or program in Linux?
    (same as how do i lauch telnet)
    As long as the user is prompted I can see no risk of denying these kind of things so I hope and think that this should be possible!
    PS. I have managed to do it by using Runtime.exec() when running as a non JWS application, but I cannot do it when running as JWS:
    java.security.AccessControlException: access denied (java.io.FilePermission <<ALL FILES>> execute)I dont want to sign the application either. The reason for choosing webstart was to not have to renew certificates at our customers.
    Please help.
    Thanks for taking interest and reading this.. and I hope that someone has some helpful answers for me :)
    Edited by: Tomas_Andersen on Feb 5, 2008 6:34 AM

    Do you know how to launch Java applications (not applets) from web pages ? Thank you.
    you can setoff a java servlet from a webpage.Is that what you are talking about ??? activeateing a server side app ????

Maybe you are looking for